ILHelper.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using ILRuntime.CLR.Method;
  5. using ILRuntime.CLR.TypeSystem;
  6. using ILRuntime.Runtime.Enviorment;
  7. using ILRuntime.Runtime.Generated;
  8. using ILRuntime.Runtime.Intepreter;
  9. using UnityEngine;
  10. namespace ETModel
  11. {
  12. public static class ILHelper
  13. {
  14. public static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
  15. {
  16. // 注册重定向函数
  17. // 注册委托
  18. appdomain.DelegateManager.RegisterMethodDelegate<List<object>>();
  19. appdomain.DelegateManager.RegisterMethodDelegate<AChannel, System.Net.Sockets.SocketError>();
  20. appdomain.DelegateManager.RegisterMethodDelegate<byte[], int, int>();
  21. appdomain.DelegateManager.RegisterMethodDelegate<IResponse>();
  22. appdomain.DelegateManager.RegisterMethodDelegate<Session, object>();
  23. appdomain.DelegateManager.RegisterMethodDelegate<Session, Packet>();
  24. appdomain.DelegateManager.RegisterMethodDelegate<Session>();
  25. appdomain.DelegateManager.RegisterMethodDelegate<ILTypeInstance>();
  26. appdomain.DelegateManager.RegisterFunctionDelegate<Google.Protobuf.Adapt_IMessage.Adaptor>();
  27. appdomain.DelegateManager.RegisterMethodDelegate<Google.Protobuf.Adapt_IMessage.Adaptor>();
  28. CLRBindings.Initialize(appdomain);
  29. // 注册适配器
  30. Assembly assembly = typeof(Init).Assembly;
  31. foreach (Type type in assembly.GetTypes())
  32. {
  33. object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
  34. if (attrs.Length == 0)
  35. {
  36. continue;
  37. }
  38. object obj = Activator.CreateInstance(type);
  39. CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
  40. if (adaptor == null)
  41. {
  42. continue;
  43. }
  44. appdomain.RegisterCrossBindingAdaptor(adaptor);
  45. }
  46. LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
  47. }
  48. }
  49. }