ILRuntimeCLRBinding.cs 1.9 KB

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