- 使用www加载DLL热更文件与PDB日志文件(发布后不需要查看打印热更的日志,可以去掉PDB文件);
#if UNITY_ANDROID
WWW www = new WWW(Application.streamingAssetsPath + "/HotFix_Project.dll");
#else
WWW www = new WWW("file:///" + Application.streamingAssetsPath + "/HotFix_Project.dll");
#endif
while (!www.isDone)
yield return null;
if (!string.IsNullOrEmpty(www.error))
UnityEngine.Debug.LogError(www.error);
byte[] dll = www.bytes;
www.Dispose();
#if UNITY_ANDROID
www = new WWW(Application.streamingAssetsPath + "/HotFix_Project.pdb");
#else
www = new WWW("file:///" + Application.streamingAssetsPath + "/HotFix_Project.pdb");
#endif
while (!www.isDone)
yield return null;
if (!string.IsNullOrEmpty(www.error))
UnityEngine.Debug.LogError(www.error);
byte[] pdb = www.bytes;
fs = new MemoryStream(dll);
p = new MemoryStream(pdb);
- 实例化ILRuntime的AppDomain沙盒,并使用沙盒加载对应的热更文件与日志,同时将Unity应用主线程告诉沙盒;
appdomain = new ILRuntime.Runtime.Enviorment.AppDomain();
appdomain.LoadAssembly(fs, p, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());
appdomain.UnityMainThreadID = Thread.CurrentThread.ManagedThreadId;
- 使用沙盒调用热更方法
appdomain.Invoke("HotFix_Project.InstanceClass", "StaticFunTest2", null, 123);
更多方法调用方式请参考Demo工程中的Invocation.cs类。
|