static public void InitHotModule() { appdomain = new AppDomain(); try { DllStream = CopyStream(ResLoad.GetStream("Data/DyncDll.dll")); if (DllStream != null) { #if USE_PDB SymbolStream = CopyStream(ResLoad.GetStream("Data/DyncDll.pdb")); appdomain.LoadAssembly(DllStream, SymbolStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); #elif USE_MDB SymbolStream = CopyStream(ResLoad.GetStream("Data/DyncDll.mdb")); appdomain.LoadAssembly(DllStream, SymbolStream, new ILRuntime.Mono.Cecil.Mdb.MdbReaderProvider()); #else appdomain.LoadAssembly(DllStream); #endif } } catch (System.Exception ex) { wxb.L.LogException(ex); } RegDelegate(appdomain); IL.Help.Init(); }
public static void Init(IResLoad resLoad = null) { if (appdomain != null) { return; } #if UNITY_EDITOR DllInitByEditor.Release(); #endif if (resLoad == null) { #if UNITY_EDITOR ResLoad.Set(new EditorResLoad()); #endif } else { ResLoad.Set(resLoad); } InitHotModule(); refType = new RefType("hot.hotApp"); refType.TryInvokeMethod("Init"); AllTypes = new List <IType>(); foreach (var ator in appdomain.LoadedTypes) { AllTypes.Add(ator.Value); } AutoReplace(AllTypes); InitByProperty(typeof(AutoInitAndRelease), "Init", AllTypes); }
// 释放所有热更模块 public static void ReleaseAll() { if (appdomain == null) { return; } ResLoad.Set(null); refType.TryInvokeMethod("ReleaseAll"); //var types = new Dictionary<string, IType>(appdomain.LoadedTypes); InitByProperty(typeof(AutoInitAndRelease), "Release", AllTypes); foreach (var ator in Fields) { ator.SetValue(null, null); } Fields.Clear(); IL.Help.ReleaseAll(); AllTypes.Clear(); AllTypes = null; refType = null; appdomain = null; System.GC.Collect(); }
static public void InitHotModule(TextAsset dll) { appdomain = new AppDomain(); appdomain.RegisterCrossBindingAdaptor(new CoroutineAdapter()); #if UNITY_EDITOR System.Type clrType = System.Type.GetType("ILRuntime.Runtime.Generated.CLRBindings"); if (clrType != null) { clrType.GetMethod("Initialize").Invoke(null, new object[] { appdomain }); } #else ILRuntime.Runtime.Generated.CLRBindings.Initialize(appdomain); #endif ILRuntime.Runtime.Generated.UnityEngine_Debug_Binding.Register(appdomain); #if UNITY_EDITOR ResLoad.Set(new EditorResLoad()); #endif try { #if TEST_MODEL var dlldata = ResLoad.GetStream(Paths.HOT_DLL_PATH); DllStream = CopyStream(dlldata); #elif BUILD_MODEL DllStream = CopyStream(new MemoryStream(dll.bytes)); #endif if (DllStream != null) { #if USE_PDB var pdbdata = ResLoad.GetStream(Paths.HOT_PDB_PATH); SymbolStream = CopyStream(pdbdata); appdomain.LoadAssembly(DllStream, SymbolStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); //启动调试服务器 appdomain.DebugService.StartDebugService(56000); #elif USE_MDB SymbolStream = CopyStream(ResLoad.GetStream("Data/DyncDll.mdb")); appdomain.LoadAssembly(DllStream, SymbolStream, new ILRuntime.Mono.Cecil.Mdb.MdbReaderProvider()); #else appdomain.LoadAssembly(DllStream); #endif } } catch (System.Exception ex) { wxb.L.LogException(ex); } RegDelegate(appdomain); IL.Help.Init(); }
// 释放所有热更模块 public static void ReleaseAll() { if (appdomain == null) { return; } ResLoad.Set(null); refType.TryInvokeMethod("ReleaseAll"); //var types = new Dictionary<string, IType>(appdomain.LoadedTypes); InitByProperty(typeof(AutoInitAndRelease), "Release", AllTypes); foreach (var ator in Fields) { ator.SetValue(null, null); } Fields.Clear(); // 释放CLR绑定,类继承等全局变量 { #if UNITY_EDITOR CallStatic("ILRuntime.Runtime.Generated.CLRBindings", "Shutdown", appdomain); CallStatic("wxb.AllAdapter", "Shutdown", appdomain); #else ILRuntime.Runtime.Generated.CLRBindings.Shutdown(appdomain); AllAdapter.Release(); #endif } IL.Help.ReleaseAll(); AllTypes.Clear(); AllTypes = null; refType = null; appdomain = null; if (DllStream != null) { DllStream.Close(); DllStream = null; } #if USE_PDB || USE_MDB if (SymbolStream != null) { SymbolStream.Close(); SymbolStream = null; } #endif System.GC.Collect(); }
static public void InitHotModule() { appdomain = new AppDomain(); appdomain.RegisterCrossBindingAdaptor(new CoroutineAdapter()); #if UNITY_EDITOR System.Type clrType = System.Type.GetType("ILRuntime.Runtime.Generated.CLRBindings"); if (clrType != null) { clrType.GetMethod("Initialize").Invoke(null, new object[] { appdomain }); } #else ILRuntime.Runtime.Generated.CLRBindings.Initialize(appdomain); #endif ILRuntime.Runtime.Generated.UnityEngine_Debug_Binding.Register(appdomain); try { DllStream = CopyStream(ResLoad.GetStream("Data/DyncDll.dll")); if (DllStream != null) { #if USE_PDB SymbolStream = CopyStream(ResLoad.GetStream("Data/DyncDll.pdb")); appdomain.LoadAssembly(DllStream, SymbolStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); #elif USE_MDB SymbolStream = CopyStream(ResLoad.GetStream("Data/DyncDll.mdb")); appdomain.LoadAssembly(DllStream, SymbolStream, new ILRuntime.Mono.Cecil.Mdb.MdbReaderProvider()); #else appdomain.LoadAssembly(DllStream); #endif } } catch (System.Exception ex) { wxb.L.LogException(ex); } RegDelegate(appdomain); IL.Help.Init(); }
public static void Init(IResLoad resLoad = null) { if (appdomain != null) { return; } #if UNITY_EDITOR DllInitByEditor.Release(); #endif if (resLoad == null) { #if UNITY_EDITOR ResLoad.Set(new EditorResLoad()); #endif } else { ResLoad.Set(resLoad); } InitHotModule(); #if HOT_DEBUG if (UnityEngine.Application.isPlaying) { System.Type debugger_type; if (IL.Help.TryGetTypeByFullName("hot.Debugger", out debugger_type)) { var debugger = new RefType(true, debugger_type); object port = debugger.TryGetField("port"); if (port != null) { var ds = appdomain.DebugService; ds.StartDebugService((int)port); object vsWaitTimeoutTime = debugger.TryGetField("vsWaitTimeoutTime"); if (vsWaitTimeoutTime != null) { int wt = (int)vsWaitTimeoutTime; if (wt > 0) { L.Log("vsWait begin!"); int count = 0; while (!ds.IsDebuggerAttached) { System.Threading.Thread.Sleep(1000); ++count; if (count >= wt) { L.Log("vsWait timeout!"); break; } } L.Log("vsWait end!"); } } } } } #endif refType = new RefType("hot.hotApp"); refType.TryInvokeMethod("Init"); AllTypes = new List <IType>(); foreach (var ator in appdomain.LoadedTypes) { AllTypes.Add(ator.Value); } AutoReplace(AllTypes); InitByProperty(typeof(AutoInitAndRelease), "Init", AllTypes); }