ILRuntimeCLRBinding.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace ET
  4. {
  5. public static class ILRuntimeCLRBinding
  6. {
  7. [MenuItem("Tools/ILRuntime/通过自动分析热更DLL生成CLR绑定")]
  8. private static void GenerateCLRBindingByAnalysis()
  9. {
  10. //用新的分析热更dll调用引用来生成绑定代码
  11. ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain();
  12. using (System.IO.FileStream fs = new System.IO.FileStream(BuildAssemblieEditor.ScriptAssembliesDir + "Code.dll", System.IO.FileMode.Open,
  13. System.IO.FileAccess.Read))
  14. {
  15. domain.LoadAssembly(fs);
  16. ILHelper.RegisterAdaptor(domain);
  17. ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, "Assets/Mono/ILRuntime/Generate");
  18. }
  19. AssetDatabase.Refresh();
  20. Debug.Log("生成CLR绑定文件完成");
  21. }
  22. [MenuItem("Tools/ILRuntime/生成跨域继承适配器")]
  23. private static void GenerateCrossbindAdapter()
  24. {
  25. //由于跨域继承特殊性太多,自动生成无法实现完全无副作用生成,所以这里提供的代码自动生成主要是给大家生成个初始模版,简化大家的工作
  26. //大多数情况直接使用自动生成的模版即可,如果遇到问题可以手动去修改生成后的文件,因此这里需要大家自行处理是否覆盖的问题
  27. using (System.IO.StreamWriter sw = new System.IO.StreamWriter("Assets/Mono/ILRuntime/IDisposableAdapter.cs"))
  28. {
  29. sw.WriteLine(ILRuntime.Runtime.Enviorment.CrossBindingCodeGenerator.GenerateCrossBindingAdapterCode(
  30. typeof (System.IDisposable), "ET"));
  31. }
  32. AssetDatabase.Refresh();
  33. Debug.Log("生成适配器完成");
  34. }
  35. }
  36. }