ILRuntimeHelper.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using ILRuntime.Runtime.Intepreter;
  4. using ILRuntime.Runtime.Stack;
  5. using ILRuntime.CLR.Method;
  6. using ILRuntime.CLR.TypeSystem;
  7. using System.Reflection;
  8. using ILRuntime.CLR.Utils;
  9. using FairyGUI;
  10. using UnityEngine;
  11. namespace GFGGame
  12. {
  13. public class ILRuntimeHelper
  14. {
  15. public unsafe static void RegisterILRuntimeCLRRedirection(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
  16. {
  17. //重定向
  18. LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
  19. CLRMethod(appdomain);
  20. }
  21. private unsafe static void CLRMethod(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
  22. {
  23. BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
  24. MethodBase method;
  25. Type[] args;
  26. Type type = typeof(FairyGUI.UIObjectFactory);
  27. args = new Type[] { typeof(System.String), typeof(System.Type) };
  28. method = type.GetMethod("SetPackageItemExtension", flag, null, args, null);
  29. appdomain.RegisterCLRMethodRedirection(method, SetPackageItemExtension_0);
  30. }
  31. private unsafe static StackObject* SetPackageItemExtension_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
  32. {
  33. ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
  34. StackObject* ptr_of_this_method;
  35. StackObject* __ret = ILIntepreter.Minus(__esp, 2);
  36. ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
  37. System.Type @type = (System.Type)typeof(System.Type).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
  38. __intp.Free(ptr_of_this_method);
  39. ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
  40. System.String @url = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
  41. __intp.Free(ptr_of_this_method);
  42. FairyGUI.UIObjectFactory.SetPackageItemExtension(@url, () => {
  43. Debug.Log("il test " + @type.FullName);
  44. return __domain.Instantiate<GComponent>(@type.FullName);
  45. });
  46. // FairyGUI.UIObjectFactory.SetPackageItemExtension (@url, @type);
  47. return __ret;
  48. }
  49. }
  50. }