LuaFramework热更新过程(及可更新的loading界面实现)



IEnumerator OnExtractResource() {
string dataPath = Util.DataPath; //数据目录
string resPath = Util.AppContentPath(); //游戏包资源目录 if (Directory.Exists(dataPath)) Directory.Delete(dataPath, true);
Directory.CreateDirectory(dataPath); string infile = resPath + "files.txt";
string outfile = dataPath + "files.txt";
if (File.Exists(outfile)) File.Delete(outfile); string message = "正在解包文件:>files.txt";
Debug.Log(infile);
Debug.Log(outfile);
if (Application.platform == RuntimePlatform.Android) {
WWW www = new WWW(infile);
yield return www; if (www.isDone) {
File.WriteAllBytes(outfile, www.bytes);
}
yield return ;
} else File.Copy(infile, outfile, true);
yield return new WaitForEndOfFrame(); //释放所有文件到数据目录
string[] files = File.ReadAllLines(outfile);
foreach (var file in files) {
string[] fs = file.Split('|');
infile = resPath + fs[]; //
outfile = dataPath + fs[]; message = "正在解包文件:>" + fs[];
Debug.Log("正在解包文件:>" + infile);
facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message); string dir = Path.GetDirectoryName(outfile);
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); if (Application.platform == RuntimePlatform.Android) {
WWW www = new WWW(infile);
yield return www; if (www.isDone) {
File.WriteAllBytes(outfile, www.bytes);
}
yield return ;
} else {
if (File.Exists(outfile)) {
File.Delete(outfile);
}
File.Copy(infile, outfile, true);
}
yield return new WaitForEndOfFrame();
}
message = "解包完成!!!";
facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);
yield return new WaitForSeconds(0.1f); message = string.Empty;
//释放完成,开始启动更新资源
StartCoroutine(OnUpdateResource());
}
IEnumerator OnUpdateResource() {
if (!AppConst.UpdateMode) {
OnResourceInited();
yield break;
}
string dataPath = Util.DataPath; //数据目录
string url = AppConst.WebUrl;
string message = string.Empty;
string random = DateTime.Now.ToString("yyyymmddhhmmss");
string listUrl = url + "files.txt?v=" + random;
Debug.LogWarning("LoadUpdate---->>>" + listUrl); WWW www = new WWW(listUrl); yield return www;
if (www.error != null) {
OnUpdateFailed(string.Empty);
yield break;
}
if (!Directory.Exists(dataPath)) {
Directory.CreateDirectory(dataPath);
}
File.WriteAllBytes(dataPath + "files.txt", www.bytes);
string filesText = www.text;
string[] files = filesText.Split('\n'); for (int i = ; i < files.Length; i++) {
if (string.IsNullOrEmpty(files[i])) continue;
string[] keyValue = files[i].Split('|');
string f = keyValue[];
string localfile = (dataPath + f).Trim();
string path = Path.GetDirectoryName(localfile);
if (!Directory.Exists(path)) {
Directory.CreateDirectory(path);
}
string fileUrl = url + f + "?v=" + random;
bool canUpdate = !File.Exists(localfile);
if (!canUpdate) {
string remoteMd5 = keyValue[].Trim();
string localMd5 = Util.md5file(localfile);
canUpdate = !remoteMd5.Equals(localMd5);
if (canUpdate) File.Delete(localfile);
}
if (canUpdate) { //本地缺少文件
Debug.Log(fileUrl);
message = "downloading>>" + fileUrl;
facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);
/*
www = new WWW(fileUrl); yield return www;
if (www.error != null) {
OnUpdateFailed(path); //
yield break;
}
File.WriteAllBytes(localfile, www.bytes);
*/
//这里都是资源文件,用线程下载
BeginDownload(fileUrl, localfile);
while (!(IsDownOK(localfile))) { yield return new WaitForEndOfFrame(); }
}
}
yield return new WaitForEndOfFrame(); message = "更新完成!!";
facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message); OnResourceInited();
}
public void CreatePanel(string name, LuaFunction func = null) {
string assetName = name + "Panel";
string abName = name.ToLower() + AppConst.ExtName; ResManager.LoadPrefab(abName, assetName, delegate(UnityEngine.Object[] objs) {
if (objs.Length == ) return;
// Get the asset.
GameObject prefab = objs[] as GameObject; if (Parent.FindChild(name) != null || prefab == null) {
return;
}
GameObject go = Instantiate(prefab) as GameObject;
go.name = assetName;
go.layer = LayerMask.NameToLayer("Default");
go.transform.SetParent(Parent);
go.transform.localScale = Vector3.one;
go.transform.localPosition = Vector3.zero;
go.AddComponent<LuaBehaviour>(); if (func != null) func.Call(go);
Debug.LogWarning("CreatePanel::>> " + name + " " + prefab);
});
}
public void CreateLoadingPanelFromResource()
{
_MemoryPoolManager_ memMgr = AppFacade.Instance.GetManager<_MemoryPoolManager_>(ManagerName._Pool_); Debug.Log("--------------------Resources加载loading--------------------------------"); memMgr.AddPrefabPoolRS("LoadingPanel", , , true, null);
// memMgr.AddPrefabPoolAB ("loading", "LoadingPanel", 1, 1, true, null); Transform loadingPanel = _MemoryPoolManager_.Spawn("LoadingPanel", true);
loadingPanel.SetParent(GameObject.Find("2DERoot/Resolution").transform);
loadingPanel.localPosition = Vector3.zero;
loadingPanel.localScale = new Vector3(, , ); _slider = loadingPanel.FindChild("LoadingSlider").GetComponent<Slider>();
_text = loadingPanel.FindChild("LoadingSlider/Text").GetComponent<Text>();
_text.gameObject.SetActive(true);
_text.transform.localPosition = Vector3.zero;
_slider.value = ;
_text.text = "准备启动游戏";
_isStartupLoading = true; KeyFrameWork.MVC.SendEvent(FWConst.E_ShowLog, "Resources load finish");
public IEnumerator CreateLoadingPanelFromAssetBundle()
{
string url = Util.GetRelativePath() + "loading.unity3d";
Debug.Log("--------------------AssetBundle加载Loading--------------------------------" + url); WWW www = WWW.LoadFromCacheOrDownload(url, , ); yield return www; AssetBundle bundle = www.assetBundle;
GameObject asset = bundle.LoadAsset<GameObject>("LoadingPanel");
Transform loadingPanel = Instantiate<GameObject>(asset).GetComponent<Transform>(); //memMgr.AddPrefabPoolRS("LoadingPanel", 1, 1, true, null);
//Transform loadingPanel = _MemoryPoolManager_.Spawn ("LoadingPanel", true); loadingPanel.SetParent(GameObject.Find("2DERoot/Resolution").transform);
loadingPanel.localPosition = Vector3.zero;
loadingPanel.localScale = new Vector3(, , );
loadingPanel.name = "LoadingPanel(Clone)001"; _slider = loadingPanel.FindChild("LoadingSlider").GetComponent<Slider>();
_text = loadingPanel.FindChild("LoadingSlider/Text").GetComponent<Text>();
_text.gameObject.SetActive(true);
_slider.value = ; _isStartupLoading = true; //加载loading完成后再开始lua,保证lua能顺利接管loading
AppFacade.Instance.StartUp(); //启动游戏 KeyFrameWork.MVC.SendEvent(FWConst.E_ShowLog, "AssetBundle load finish"); }
LuaFramework热更新过程(及可更新的loading界面实现)的更多相关文章
- 青瓷引擎使用心得——修改引擎的loading界面
一. 修改引擎的Loading界面之使用进度条显示1. 双击打开引擎包中的lib/qc-loading-debug.js,如下图所示: 2. 只需要修改qici.init函数即可改变loading界面 ...
- Cocos Creator—定制H5游戏首页loading界面
Cocos Creator从1.0版本发布到现在也有一年多了,按理说一些常见的问题网上都有解决方案,例如"如何自定义首页加载进度条界面"这种普遍需求,应该所有人都会遇到的,因此也有 ...
- cocos2d-x 3.0 Loading界面实现
这个世界每一天都在验证我们的渺小,但我们却在努力创造,不断的在这生活的画卷中留下自己的脚印.或许等到我们老去的那一天,老得不能动仅仅能靠回顾的那一天.你躺在轮椅上,不断的回顾过去.相思的痛苦忘不了,相 ...
- SILVERLIGHT 应急卫生模拟演练项目之loading界面实现
第一次在博客园写文章 俺是菜鸟 有不足之处还请大佬们多多指教 第一次也不知道该写啥 俺就拿自己最近做的一个项目 来细说吧 俺们公司是做医疗卫生方面的 其中有一块涉及到应急卫生模拟演练方面 这块分到我 ...
- cocos2d-x游戏开发(十五)游戏加载动画loading界面
个人原创,欢迎转载:http://blog.csdn.net/dawn_moon/article/details/11478885 这个资源加载的loading界面demo是在玩客网做逆转三国的时候随 ...
- 10分钟,利用canvas画一个小的loading界面
首先利用定义下canvas得样式 <canvas width="1024" height="720" id="canvas" styl ...
- 手游产品经理初探(二)从营销角度看loading界面
近期開始写产品相关的专题,准备从细节入手去思考.总结一些不为人注意的细节地方. 今天给大家分享的是游戏里面都有的loading界面. 还是从几个在Facebook上排名靠前的Casino游戏的load ...
- cocos2d-x游戏开发(十五)游戏载入动画loading界面
这个资源载入的loading界面demo是在玩客网做逆转三国的时候随手写的,尽管我在那仅仅待了2个礼拜.可是也算參与了一个商业游戏项目了,学到不少东西.当时使用的cocos2d-x还是1.0版的,我用 ...
- JavaFX桌面应用-loading界面
上次使用JavaFX开发了一个视频转码工具,当用户点击"启动"按钮开始转码的时候,会禁用启动按钮,防止多次启动转码. 这种处理方式对用户来说可能并是很友好,其实可以在启动转码的时弹 ...
随机推荐
- js的for循环闭包问题
一个简单的例子,如果想循环输出数组中的每一个数值我们可以利用for循环来输出例如: <script type="text/javascript"> var arr=[& ...
- Linux下如果忘记了Mysql的root密码该怎么办?
下面十分简单的办法用来重置密码: 1.编辑MySQL配置文件my.cnf vi /etc/my.cnf #编辑文件,找到[mysqld],在下面添加一行skip-grant-tables [mysql ...
- 软件测试基础(软件测试分类和工具组)firebug、firepath的安装
白盒测试:需要了解内部结构和代码 黑盒测试:不关心内部结构和代码 灰盒测试:介于白盒黑盒之间 静态测试:测试时不执行被测试软件 动态测试:测试时执行被测试软件 单元测试:测试软件的单元模块 集成测试: ...
- servlet与Javabean之间的区别
在JSP中调用JAVA类和使用JavaBean有什么区别? 可以像使用一般的类一样使用JavaBean,Bean只是一种特殊的类.特殊在可以通过<jsp:useBean/>调用JavaBe ...
- 解决laydate时间日期插件定位溢出
laydate是一款比较好用的网页时间日期插件,不过用起来有一些细节问题需要我们手动去解决!例如:laydate兼容bootstrap 1. 默认情况 laydate弹出层默认对齐input左边框 2 ...
- Oracle数据库ora-01722 错误小记
今天遇到个关联查询的错误,特搜索了下记录下来. 因为做视图查询的表是以前建立的,所以有个字段类型应该只实用于当时.看SQL: select x.参数1 , y.参数2 from t_fac_info ...
- 使用File、Path和Directory进行常见的操作
我们偶尔会用到文件操作,其中File.Path和Directory这三个类是比较常见的,今天写了一个测试demo,也是顺便学习一下,记录一二. BTW,使用这几个类的时候需要引用using Syste ...
- iOS 转场动画探究(二)
这篇文章是接着第一篇写的,要是有同行刚看到的话建议从前面第一篇看,这是第一篇的地址:iOS 转场动画探究(一) 接着上一篇写的内容: 上一篇iOS 转场动画探究(一)我们说到了转场要素的第四点,把那个 ...
- SpringMVC转发和重定向区别!
在servlet中,转发和重定向是由request和response完成的.两者之间的区别请看我之前的文章.那么在springMVC中是如何完成的呢? /**转发**/ @RequestMapping ...
- cmake的安装和卸载
cmake介绍: CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程).他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性 ...