public static void RunTest(int a, string str) { delegateMethod?.Invoke(a); string returnFunction = delegateFunc?.Invoke(a); Debug.Log("ReturnA:" + returnFunction); delegateAction?.Invoke(str); }
private void OnHotFixLoaded() { //第一个简单方法调用 调用无参数静态方法 mAppDomain.Invoke("类名", "方法名", 对象引用, 参数列表); //mAppDomain.Invoke("Hotfix.TestClass", "StaticFunTest", null, null); //第二种调用 先单独获取类,之后一直使用这个类来调用 IType type = mAppDomain.LoadedTypes["Hotfix.TestClass"]; //根据方法名称和参数个数获取方法 IMethod method = type.GetMethod("StaticFunTest", 0); mAppDomain.Invoke(method, null, null); //------------------------------------------------------------------------------------- //根据获取函数来调用有参的函数 //第一种传参调用 //IMethod method2 = type.GetMethod("StaticFunTest2",1); //mAppDomain.Invoke(method2, null, 10); //第二种传参调用 IType intType = mAppDomain.GetType(typeof(int)); List <IType> paraList = new List <IType>(); paraList.Add(intType); IMethod method2 = type.GetMethod("StaticFunTest2", paraList, null); mAppDomain.Invoke(method2, null, 10); //---------------------------------------------------------------------------------------- //实例化热更工程里的类 //第一种实例化(可带参) object obj = mAppDomain.Instantiate("Hotfix.TestClass", new object[] { 15 }); //第二种实例化(不带参) //object obj = ((ILType)type).Instantiate(); //获取属性 //int id = (int)mAppDomain.Invoke("Hotfix.TestClass", "get_ID", obj, null);//获取属性前面需要加get_ //Debug.Log("ID" + id); object obj1 = ILRuntimeManager.Instance.AppDomainCtrl.Instantiate("Hotfix.LoadingPanelLogic"); //----------------------------------------------------------------------------------------- //第一种泛型方法调用 IType stringType = mAppDomain.GetType(typeof(string)); IType[] genericArguments = new IType[] { stringType }; //mAppDomain.InvokeGenericMethod("Hotfix.TestClass", "GenericMethod",genericArguments,null,"Jayden"); //第二种泛型方法调用 paraList.Clear(); paraList.Add(stringType); IMethod genericMethod = type.GetMethod("GenericMethod", paraList, genericArguments); mAppDomain.Invoke(genericMethod, null, "Jayden22222222"); //-------------------------------------------------------------------------------------- //委托调用 IType delegateType = mAppDomain.LoadedTypes["Hotfix.TestDelegate"]; //IMethod delegateInit = delegateType.GetMethod("Initialize",0); //mAppDomain.Invoke(delegateInit,null); //IMethod delegateRun = delegateType.GetMethod("RunTest", 2); //mAppDomain.Invoke(delegateRun, null,10,"Jayden"); //跨域委托调用 尽量使用系统自带的Action以及Function IMethod DelegateInit = delegateType.GetMethod("Initialize2", 0); mAppDomain.Invoke(DelegateInit, null); //IMethod DelegateRun = delegateType.GetMethod("RunTest2", 2); //mAppDomain.Invoke(DelegateRun, null,10,"Jayden"); // 也可以直接调用委托 委托在热更工程中注册 DelegateMethod?.Invoke(10); string returnFunction = DelegateFunc?.Invoke(10); Debug.Log("ReturnA:" + returnFunction); DelegateAction?.Invoke("Jayden"); //-------------------------------------------------------------------------------------- //跨域继承 第一种 //TestClassBase InheritanceObj = mAppDomain.Instantiate<TestClassBase>("Hotfix.TestInheritance"); //InheritanceObj.TestAbstract(556); //InheritanceObj.TestVirtual("JadenVirtual"); //跨域继承 第二种 TestClassBase InheritanceObj = (TestClassBase)mAppDomain.Invoke("Hotfix.TestInheritance", "NewObject", null); InheritanceObj.TestAbstract(100); InheritanceObj.TestVirtual("JadenVirtual"); //-------------------------------------------------------------------------------------- //CLR绑定测试 long curTime = System.DateTime.Now.Ticks; mAppDomain.Invoke("Hotfix.TestCLRBinding", "RunTest", null, null); Debug.Log("使用时间:" + (System.DateTime.Now.Ticks - curTime)); //---------------------------------------------------------------------------------------- //协成测试 mAppDomain.Invoke("Hotfix.TestCortoutine", "RunTest", null, null); //---------------------------------------------------------------------------------------- //Mono测试 // mAppDomain.Invoke("Hotfix.TestMono", "RunTest", null, GameRoot.Instance.gameObject); mAppDomain.Invoke("Hotfix.TestMono", "RunTest1", null, GameRoot.Instance.gameObject); }