ILHelper.cs 1.8 KB

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