ILHelper.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 unsafe 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. CLRBindings.Initialize(appDomain);
  27. // 注册适配器
  28. Assembly assembly = typeof(Init).Assembly;
  29. foreach (Type type in assembly.GetTypes())
  30. {
  31. object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
  32. if (attrs.Length == 0)
  33. {
  34. continue;
  35. }
  36. object obj = Activator.CreateInstance(type);
  37. CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
  38. if (adaptor == null)
  39. {
  40. continue;
  41. }
  42. appDomain.RegisterCrossBindingAdaptor(adaptor);
  43. }
  44. LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appDomain);
  45. }
  46. }
  47. }