ET框架---HotFix.HotFix学习笔记
2018-04-09 11:04
1651 查看
HotFix学习笔记
请大家关注我的微博:@NormanLin_BadPixel坏像素从现在开始,关于热更部分的代码,我们很可能得分两部分来讲,一种是在开发的情况下,另一种则是在发布后的情况下。将会大量用到Unity的宏定义。
#if ILRuntime private ILRuntime.Runtime.Enviorment.AppDomain appDomain; #else private Assembly assembly; #endif
比如这里,如果是在热更情况下,我们会用到ILRuntime的域,否则,我们需要用到相关的程序集。
我们看到,在Model的Init方法里,我们先调用了LoadHotfixAssembly
public void LoadHotfixAssembly() { Game.Scene.GetComponent<ResourcesComponent>().LoadBundle($"code.unity3d"); #if ILRuntime this.appDomain = new ILRuntime.Runtime.Enviorment.AppDomain(); GameObject code = Game.Scene.GetComponent<ResourcesComponent>().GetAsset<GameObject>("code.unity3d", "Code"); byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes; byte[] mdbBytes = code.Get<TextAsset>("Hotfix.pdb").bytes; using (MemoryStream fs = new MemoryStream(assBytes)) using (MemoryStream p = new MemoryStream(mdbBytes)) { this.appDomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider()); } this.start = new ILStaticMethod(this.appDomain, "Hotfix.Init", "Start", 0); #else GameObject code = Game.Scene.GetComponent<ResourcesComponent>().GetAsset<GameObject>("code.unity3d", "Code"); byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes; byte[] mdbBytes = code.Get<TextAsset>("Hotfix.mdb").bytes; this.assembly = Assembly.Load(assBytes, mdbBytes); Type hotfixInit = this.assembly.GetType("Hotfix.Init"); this.start = new MonoStaticMethod(hotfixInit, "Start"); #endif Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle($"code.unity3d"); }
我们看到,这里就是给热更的域添加内容的地方。通过我们之前学的资源管理组件跟AssetBundle的一些知识,我们获取到Code这个预制体,并从其身上获取到”Hotfix.dll”跟”Hotfix.pdb”,这些程序集相关的内容,然后把这些程序集信息加载入ILRuntime的域中。
之后,把HotFix的start方法重定向到热更域中的Hotfix.Init.Start方法。我们可以去看一下ILStaticMethod类,其实就是一个指向指定热更域中一个指定方法的类,并继承IStaticMethod,有Run方法。当我们去调用Run方法的时候,其实是去调用热更域中的方法。
如果不用热更,则是直接加载程序集。同样的指定start方法。关于MonoStaticMethod,大家也去看一下吧,全是C#反射的知识。
当我们加载完我们需要的东西后,记得卸载用完了的资源。
Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle($"code.unity3d");
当我们调用GotoHotfix的时候。
public void GotoHotfix() { #if ILRuntime ILHelper.InitILRuntime(this.appDomain); #endif this.start.Run(); }
看来我们需要先初始化一下ILRuntime。里面的代码多是我看不懂的。。。大家可以先去看看ILRuntime教程。
当我们开始看
this.start.Run();
我们就需要进入HotFix程序集里面了。
HotFix.Init
相关文章推荐
- ET框架---ClientComponent学习笔记
- ET框架---BundleDownloaderComponent学习笔记
- ET框架---ClientDispatcher学习笔记
- node.js 和 express 框架学习笔记(2)
- 【day 12】python编程:从入门到实践学习笔记-基于Django框架的Web开发-Django入门(三)
- MonoRail学习笔记二:框架代码下载
- Yii框架学习笔记(二)将html前端模板整合到框架中
- Java框架spring 学习笔记(二):Bean的作用域
- Java框架spring 学习笔记(三):Bean 的生命周期
- Android 学习笔记之AndBase框架学习(七) SlidingMenu滑动菜单的实现
- HTML学习笔记——框架
- sturts2框架的学习笔记,问题解决:
- 07/11/2014 J2EE 学习笔记 Design Pattern Observer,Singleton et Iterator
- Universal Image Loader 学习笔记-框架配置
- Struts 1 Validator框架学习笔记
- Web前端学习笔记:Bootstrap框架
- Js测试框架学习笔记(一)
- OC学习笔记之Foundation框架NSNumber、NSValue和NSDate(转)
- VS2010 C++ MFC框架学习笔记1 - 创建一个简单的加法计算器(1)
- CI框架学习笔记