ILHelper.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Reflection;
  3. using ILRuntime.Runtime.Enviorment;
  4. using UnityEngine;
  5. namespace Model
  6. {
  7. public static class ILHelper
  8. {
  9. public static unsafe void InitILRuntime()
  10. {
  11. // 注册重定向函数
  12. MethodInfo mi = typeof(Log).GetMethod("Debug", new Type[] { typeof(string) });
  13. Init.Instance.AppDomain.RegisterCLRMethodRedirection(mi, ILRedirection.LogDebug);
  14. MethodInfo mi2 = typeof(Log).GetMethod("Info", new Type[] { typeof(string) });
  15. Init.Instance.AppDomain.RegisterCLRMethodRedirection(mi2, ILRedirection.LogInfo);
  16. MethodInfo mi3 = typeof(Log).GetMethod("Error", new Type[] { typeof(string) });
  17. Init.Instance.AppDomain.RegisterCLRMethodRedirection(mi3, ILRedirection.LogError);
  18. // 注册委托
  19. Init.Instance.AppDomain.DelegateManager.RegisterMethodDelegate<AChannel, System.Net.Sockets.SocketError>();
  20. Init.Instance.AppDomain.DelegateManager.RegisterMethodDelegate<byte[], int, int>();
  21. Init.Instance.AppDomain.DelegateManager.RegisterMethodDelegate<AResponse>();
  22. // 注册适配器
  23. Assembly assembly = typeof(Init).Assembly;
  24. foreach (Type type in assembly.GetTypes())
  25. {
  26. object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
  27. if (attrs.Length == 0)
  28. {
  29. continue;
  30. }
  31. object obj = Activator.CreateInstance(type);
  32. CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
  33. if (adaptor == null)
  34. {
  35. continue;
  36. }
  37. Init.Instance.AppDomain.RegisterCrossBindingAdaptor(adaptor);
  38. }
  39. }
  40. public static void AvoidAot(GameObject gameObject)
  41. {
  42. Input input = gameObject.Get<Input>("11");
  43. }
  44. }
  45. }