Esempio n. 1
0
    public override void Excute()
    {
        base.Excute();
        //现在我们来注册适配器
        AppDomain.RegisterCrossBindingAdaptor(new TestClassBaseeAdapter());
        TestClassBase obj = AppDomain.Instantiate <TestClassBase>("GameModelTest.Inheritance");

        //现在来调用成员方法
        obj.TestAbstract(123);
        obj.TestVirtual("Hello");

        //现在换个方式创建实例
        obj = AppDomain.Invoke("GameModelTest.Inheritance", "NewObject", null, null) as TestClassBase;
        obj.TestAbstract(456);
        obj.TestVirtual("Hello2");
    }
Esempio n. 2
0
        static int _m_TestAbstract(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                TestClassBase gen_to_be_invoked = (TestClassBase)translator.FastGetCSObj(L, 1);



                {
                    int _gg = LuaAPI.xlua_tointeger(L, 2);

                    gen_to_be_invoked.TestAbstract(_gg);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Esempio n. 3
0
    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);
    }