ILRuntimeCLRBinding.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #if UNITY_EDITOR
  2. using UnityEditor;
  3. //using ILRuntime.Generated.CrossBinding;
  4. using System.Collections.Generic;
  5. [System.Reflection.Obfuscation(Exclude = true)]
  6. public class ILRuntimeCLRBinding
  7. {
  8. [MenuItem("ILRuntime/通过自动分析热更DLL生成CLR绑定")]
  9. 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("Assets/Res/Code/Game.HotUpdate.dll.bytes", System.IO.FileMode.Open, System.IO.FileAccess.Read))
  14. {
  15. domain.LoadAssembly(fs);
  16. //Crossbind Adapter is needed to generate the correct binding code
  17. InitILRuntime(domain);
  18. ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, "Assets/Game/Launcher/ILRuntime/Generated");
  19. }
  20. AssetDatabase.Refresh();
  21. }
  22. static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
  23. {
  24. //这里需要注册所有热更DLL中用到的跨域继承Adapter,否则无法正确抓取引用
  25. //appdomain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter());
  26. //appdomain.RegisterCrossBindingAdaptor(new CoroutineAdapter());
  27. //appdomain.RegisterCrossBindingAdaptor(new GComponentAdapter());
  28. //appdomain.RegisterCrossBindingAdaptor(new IEnumerator());
  29. //appdomain.RegisterCrossBindingAdaptor(new ScriptableObjectAdapter());
  30. //appdomain.RegisterCrossBindingAdaptor(new WindowAdapter());
  31. //appdomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
  32. }
  33. }
  34. #endif