static void GenerateCLRBindingByAnalysis() { //CLR绑定 从热更DLL中调用Unity主工程或者Unity的接口 //用新的分析热更dll调用引用来生成绑定代码 var domain = new ILRuntime.Runtime.Enviorment.AppDomain(); //string path = Application.dataPath + "/ILRuntime/DllData/"; foreach (var full_path in Directory.GetFiles(LC_RuntimeManager.DLL_PATH, "*_dlc.txt", SearchOption.TopDirectoryOnly)) { var relative_path = full_path.Substring(full_path.IndexOf("Assets")); using (var fs = new FileStream(relative_path, FileMode.Open, FileAccess.Read)) { domain.LoadAssembly(fs); } } //Crossbind Adaptor is needed to generate the correct binding code LC_AdaptorHelper.Init(domain); var generated_path = Application.dataPath + "/ILRuntime/Generated/"; var relative = generated_path.Substring(generated_path.IndexOf("Assets")); ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, relative); Debug.LogWarning("== ILRuntime/Generate CLR Binding Code by Analysis Complete!!! =="); }
public static void LoadAssembly(byte[] dll_data, byte[] pdb_data = null) { if (dll_data == null || dll_data.Length == 0) { Debug.LogError("== LoadAssembly parameter is null =="); return; } //首先实例化ILRuntime的AppDomain,AppDomain是一个应用程序域,每个AppDomain都是一个独立的沙盒 if (null == _appdomain) { _appdomain = new ILRuntime.Runtime.Enviorment.AppDomain(); //TODO For Debug //_appdomain.DebugService.StartDebugService(56000); LC_AdaptorHelper.Init(_appdomain); LC_Helper.Init(_appdomain); SetupCLRRedirection(); SetupCLRRedirection2(); CLRBindings.Initialize(_appdomain); #if UNITY_EDITOR // _appdomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId; //Debug.Log("m_pcAppDomain.UnityMainThreadID:" + _appdomain.UnityMainThreadID); #endif } using (var fs = new MemoryStream(dll_data)) { MemoryStream p = null; if (pdb_data != null) { p = new MemoryStream(pdb_data); } _appdomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider()); } }