Esempio n. 1
0
    public static void InitializeILRuntime(AppDomain appdomain)
    {
#if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE)
        //由于Unity的Profiler接口只允许在主线程使用,为了避免出异常,需要告诉ILRuntime主线程的线程ID才能正确将函数运行耗时报告给Profiler
        appdomain.UnityMainThreadID = Thread.CurrentThread.ManagedThreadId;
        appdomain.DebugService.StartDebugService(56000);
#endif

        RegisterCrossBindingAdaptorHelper.HelperRegister(appdomain);
        RegisterCLRMethodRedirectionHelper.HelperRegister(appdomain);
        RegisterMethodDelegateHelper.HelperRegister(appdomain);
        RegisterFunctionDelegateHelper.HelperRegister(appdomain);
        RegisterDelegateConvertorHelper.HelperRegister(appdomain);
        RegisterLitJsonHelper.HelperRegister(appdomain);
        RegisterValueTypeBinderHelper.HelperRegister(appdomain);

        //Protobuf适配
        ProtoBuf.PType.RegisterFunctionCreateInstance(PType_CreateInstance);
        ProtoBuf.PType.RegisterFunctionGetRealType(PType_GetRealType);

        //LitJson适配
        JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);

        //CLR绑定
        CLRBindings.Initialize(appdomain);
        Init.Inited = true;
    }
Esempio n. 2
0
    public static void InitializeILRuntime(AppDomain appdomain)
    {
#if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE)
        //由于Unity的Profiler接口只允许在主线程使用,为了避免出异常,需要告诉ILRuntime主线程的线程ID才能正确将函数运行耗时报告给Profiler
        appdomain.UnityMainThreadID = Thread.CurrentThread.ManagedThreadId;
        appdomain.DebugService.StartDebugService(56000);
#endif

        RegisterCrossBindingAdaptorHelper.HelperRegister(appdomain);
        RegisterCLRMethodRedirectionHelper.HelperRegister(appdomain);
        RegisterMethodDelegateHelper.HelperRegister(appdomain);
        RegisterFunctionDelegateHelper.HelperRegister(appdomain);
        RegisterDelegateConvertorHelper.HelperRegister(appdomain);
        RegisterLitJsonHelper.HelperRegister(appdomain);
        RegisterValueTypeBinderHelper.HelperRegister(appdomain);

        //Protobuf适配
        PType.RegisterILRuntimeCLRRedirection(appdomain);

        //LitJson适配
        JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);

        //CLR绑定(有再去绑定)
        Type t = Type.GetType("ILRuntime.Runtime.Generated.CLRBindings");
        if (t != null)
        {
            t.GetMethod("Initialize")?.Invoke(null, new object[]
            {
                appdomain
            });
        }
    }
Esempio n. 3
0
    public static unsafe void InitializeILRuntime(AppDomain appdomain)
    {
#if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE)
        //由于Unity的Profiler接口只允许在主线程使用,为了避免出异常,需要告诉ILRuntime主线程的线程ID才能正确将函数运行耗时报告给Profiler
        appdomain.UnityMainThreadID = Thread.CurrentThread.ManagedThreadId;
        appdomain.DebugService.StartDebugService(56000);
#endif

        RegisterCrossBindingAdaptorHelper.HelperRegister(appdomain);
        RegisterMethodDelegateHelper.HelperRegister(appdomain);
        RegisterFunctionDelegateHelper.HelperRegister(appdomain);
        RegisterDelegateConvertorHelper.HelperRegister(appdomain);
        RegisterLitJsonHelper.HelperRegister(appdomain);
        RegisterValueTypeBinderHelper.HelperRegister(appdomain);

        //添加MonoBehaviour核心方法
        var arr = typeof(GameObject).GetMethods();
        foreach (var i in arr)
        {
            if (i.Name == "AddComponent" && i.GetGenericArguments().Length == 1)
            {
                appdomain.RegisterCLRMethodRedirection(i, AddComponent);
            }
        }

        foreach (var i in arr)
        {
            if (i.Name == "GetComponent" && i.GetGenericArguments().Length == 1)
            {
                appdomain.RegisterCLRMethodRedirection(i, GetComponent);
            }
        }

        //Protobuf适配
        ProtoBuf.PType.RegisterFunctionCreateInstance(PType_CreateInstance);
        ProtoBuf.PType.RegisterFunctionGetRealType(PType_GetRealType);

        //LitJson适配
        JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);

        //CLR绑定
        CLRBindings.Initialize(appdomain);
    }