Ejemplo n.º 1
0
    private void Start()
    {
        Debug.Log("普通日志");
        Debug.LogError("普通错误");

        _msgId = PinnedLog.AddMsg("我是不会被清掉的日志");

        // 实例方法替换测试
        InstanceMethodTest InstanceTest = new InstanceMethodTest();

        InstanceTest.Test();

        // 属性替换测试
        PropertyHookTest propTest = new PropertyHookTest();

        propTest.Test();

        // 参数类型是私有类型的方法替换测试
        PrivateTypeArgMethodTest privateTypeArgMethodTest = new PrivateTypeArgMethodTest();

        privateTypeArgMethodTest.Test();

        // 构造函数替换测试
        CtorHookTest ctorHookTest = new CtorHookTest();

        ctorHookTest.Test();

        // 测试GameObject.SetActive
        btn.gameObject.SetActive(false);
        btn.gameObject.SetActive(true);
    }
Ejemplo n.º 2
0
    private void Start()
    {
        Debug.Log("普通日志");
        Debug.LogError("普通错误");

        _msgId = PinnedLog.AddMsg("我是不会被清掉的日志");

        // 测试实例方法替换
        InstanceMethodTest InstanceTest = new InstanceMethodTest();

        InstanceTest.Test();

        // 测试属性替换
        PropertyHookTest propTest = new PropertyHookTest();

        propTest.Test();

        // 参数类型是私有类型的方法替换测试
        PrivateTypeArgMethodTest privateTypeArgMethodTest = new PrivateTypeArgMethodTest();

        privateTypeArgMethodTest.Test();
    }
Ejemplo n.º 3
0
    public void OnBtnTestClick()
    {
        Debug.Log("Test Begin");

        // 实例方法替换测试
        {
            InstanceMethodTest.InstallPatch();
            InstanceMethodTest.callOriFunc = true;
            InstanceMethodTest InstanceTest = new InstanceMethodTest();
            InstanceTest.Test();
            int ret = InstanceTest.Test();

            int    count = 10 * 1000 * 1000;
            string str   = $"InstanceMethodTest {count} times, ret: {ret}\r\n";

            DateTime dt  = DateTime.Now;
            long     val = 0;
            {// patch and call original function
                for (int i = 0; i < count; i++)
                {
                    val += InstanceTest.Test();
                }
                str += $"patch:      {(int)new TimeSpan(DateTime.Now.Ticks - dt.Ticks).TotalMilliseconds} ms, ret:{val}\r\n";
            }

            {// patch but dont call original function
                dt  = DateTime.Now;
                val = 0;
                InstanceMethodTest.callOriFunc = false;
                for (int i = 0; i < count; i++)
                {
                    val += InstanceTest.Test();
                }
                str += $"patch, no ori call:{(int)new TimeSpan(DateTime.Now.Ticks - dt.Ticks).TotalMilliseconds} ms, ret:{val}\r\n";
            }

            {// no patch
                InstanceMethodTest.UninstallPatch();
                dt  = DateTime.Now;
                val = 0;
                for (int i = 0; i < count; i++)
                {
                    val += InstanceTest.Test();
                }
                str += $"no patch: {(int)new TimeSpan(DateTime.Now.Ticks - dt.Ticks).TotalMilliseconds} ms, ret:{val}";
            }

            txtTestVal.text = str;
        }

        // 属性替换测试
        PropertyHookTest propTest = new PropertyHookTest();

        propTest.Test();

        // 参数类型是私有类型的方法替换测试
        PrivateTypeArgMethodTest privateTypeArgMethodTest = new PrivateTypeArgMethodTest();

        privateTypeArgMethodTest.Test();

        // 构造函数替换测试
        CtorHookTest ctorHookTest = new CtorHookTest();

        ctorHookTest.Test();

        // 测试GameObject.SetActive
        GameObject_SetActive_HookTest.Test(btn.gameObject);

        Debug.Log("Test End");
    }