ILHelper.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Net;
  5. using System.Reflection;
  6. using ILRuntime.CLR.Method;
  7. using ILRuntime.CLR.TypeSystem;
  8. using ILRuntime.Runtime.Enviorment;
  9. using ILRuntime.Runtime.Generated;
  10. using ILRuntime.Runtime.Intepreter;
  11. using UnityEngine;
  12. namespace ET
  13. {
  14. public static class ILHelper
  15. {
  16. public static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
  17. {
  18. // 注册重定向函数
  19. // 注册委托
  20. appdomain.DelegateManager.RegisterMethodDelegate<List<object>>();
  21. appdomain.DelegateManager.RegisterMethodDelegate<object>();
  22. appdomain.DelegateManager.RegisterMethodDelegate<bool>();
  23. appdomain.DelegateManager.RegisterMethodDelegate<string>();
  24. appdomain.DelegateManager.RegisterMethodDelegate<float>();
  25. appdomain.DelegateManager.RegisterMethodDelegate<long, int>();
  26. appdomain.DelegateManager.RegisterMethodDelegate<long, MemoryStream>();
  27. appdomain.DelegateManager.RegisterMethodDelegate<long, IPEndPoint>();
  28. appdomain.DelegateManager.RegisterMethodDelegate<ILTypeInstance>();
  29. appdomain.DelegateManager.RegisterFunctionDelegate<UnityEngine.Events.UnityAction>();
  30. appdomain.DelegateManager.RegisterFunctionDelegate<System.Object, ET.ETTask>();
  31. appdomain.DelegateManager.RegisterFunctionDelegate<ILTypeInstance, bool>();
  32. appdomain.DelegateManager.RegisterFunctionDelegate<System.Collections.Generic.KeyValuePair<System.String, System.Int32>, System.String>();
  33. appdomain.DelegateManager.RegisterFunctionDelegate<System.Collections.Generic.KeyValuePair<System.Int32, System.Int32>, System.Boolean>();
  34. appdomain.DelegateManager.RegisterFunctionDelegate<System.Collections.Generic.KeyValuePair<System.String, System.Int32>, System.Int32>();
  35. appdomain.DelegateManager.RegisterFunctionDelegate<List<int>, int>();
  36. appdomain.DelegateManager.RegisterFunctionDelegate<List<int>, bool>();
  37. appdomain.DelegateManager.RegisterFunctionDelegate<int, bool>();//Linq
  38. appdomain.DelegateManager.RegisterFunctionDelegate<int, int, int>();//Linq
  39. appdomain.DelegateManager.RegisterFunctionDelegate<KeyValuePair<int, List<int>>, bool>();
  40. appdomain.DelegateManager.RegisterFunctionDelegate<KeyValuePair<int, int>, KeyValuePair<int, int>, int>();
  41. //注册Json的CLR
  42. LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
  43. //注册ProtoBuf的CLR
  44. ProtoBuf.PBType.RegisterILRuntimeCLRRedirection(appdomain);
  45. CLRBindings.Initialize(appdomain);
  46. // 注册适配器
  47. RegisterAdaptor(appdomain);
  48. }
  49. public static void RegisterAdaptor(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
  50. {
  51. //注册自己写的适配器
  52. appdomain.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor());
  53. appdomain.RegisterCrossBindingAdaptor(new ISupportInitializeAdapter());
  54. appdomain.RegisterCrossBindingAdaptor(new IDisposableAdapter());
  55. }
  56. }
  57. }