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