ILHelper.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction>((act) =>
  43. {
  44. return new UnityEngine.Events.UnityAction(() =>
  45. {
  46. ((Action)act)();
  47. });
  48. });
  49. appdomain.DelegateManager.RegisterDelegateConvertor<Comparison<KeyValuePair<int, int>>>((act) =>
  50. {
  51. return new Comparison<KeyValuePair<int, int>>((x, y) =>
  52. {
  53. return ((Func<KeyValuePair<int, int>, KeyValuePair<int, int>, int>)act)(x, y);
  54. });
  55. });
  56. // 注册适配器
  57. RegisterAdaptor(appdomain);
  58. //注册Json的CLR
  59. LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
  60. //注册ProtoBuf的CLR
  61. PType.RegisterILRuntimeCLRRedirection(appdomain);
  62. CLRBindings.Initialize(appdomain);
  63. }
  64. public static void RegisterAdaptor(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
  65. {
  66. //注册自己写的适配器
  67. appdomain.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor());
  68. }
  69. }
  70. }