/// <summary>
        /// 加载Hotfix程序集
        /// </summary>
        /// <param name="dllPath"></param>
        /// <param name="isRegisterBindings"></param>
        public static void LoadHotfix(string dllPath, bool isRegisterBindings = true)
        {
            //
            IsRunning = true;
            string pdbPath = dllPath + ".pdb";

            BDebug.Log("DLL加载路径:" + dllPath, "red");
            //
            AppDomain = new AppDomain();
            if (File.Exists(pdbPath))
            {
                //这里的流不能释放,头铁的老哥别试了
                fsDll = new FileStream(dllPath, FileMode.Open, FileAccess.Read);
                fsPdb = new FileStream(pdbPath, FileMode.Open, FileAccess.Read);
                AppDomain.LoadAssembly(fsDll, fsPdb, new PdbReaderProvider());
            }
            else
            {
                //这里的流不能释放,头铁的老哥别试了
                fsDll = new FileStream(dllPath, FileMode.Open, FileAccess.Read);
                AppDomain.LoadAssembly(fsDll);
            }


#if UNITY_EDITOR
            AppDomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId;
#endif

            //绑定的初始化
            //ada绑定
            AdapterRegister.RegisterCrossBindingAdaptor(AppDomain);
            //delegate绑定
            ILRuntimeDelegateHelper.Register(AppDomain);
            //值类型绑定
            AppDomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Vector4), new Vector4Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());


            //是否注册各种binding
            if (isRegisterBindings)
            {
                CLRBindings.Initialize(AppDomain);
                CLRManualBindings.Initialize(AppDomain);
                // ILRuntime.Runtime.Generated.PreCLRBuilding.Initialize(AppDomain);
            }

            JsonMapper.RegisterILRuntimeCLRRedirection(AppDomain);


            if (BDLauncher.Inst != null && Config.Inst.Data.IsDebuggerILRuntime)
            {
                AppDomain.DebugService.StartDebugService(56000);
                Debug.Log("热更调试器 准备待命~");
            }

            //
            AppDomain.Invoke("HotfixCheck", "Log", null, null);
        }
Exemple #2
0
 public static void RegisterAdaptor(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
 {
     //注册自己写的适配器
     appdomain.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor());
     appdomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());
     appdomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
     appdomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());
 }
        public static void LoadHotfix(string dllPath, bool isRegisterBindings = true)
        {
            //
            IsRunning = true;
            string pdbPath = dllPath.Replace(".dll", ".pdb");

            BDebug.Log("DLL加载路径:" + dllPath, "red");
            //
            AppDomain = new AppDomain();
            if (File.Exists(pdbPath))
            {
                //这里的流不能释放,头铁的老哥别试了
                fsDll = new FileStream(dllPath, FileMode.Open, FileAccess.Read);
                fsPdb = new FileStream(pdbPath, FileMode.Open, FileAccess.Read);
                AppDomain.LoadAssembly(fsDll, fsPdb, new PdbReaderProvider());
            }
            else
            {
                //这里的流不能释放,头铁的老哥别试了
                fsDll = new FileStream(dllPath, FileMode.Open, FileAccess.Read);
                AppDomain.LoadAssembly(fsDll);
            }


            //绑定的初始化
            //ada绑定
            AdapterRegister.RegisterCrossBindingAdaptor(AppDomain);
            //delegate绑定
            ILRuntimeDelegateHelper.Register(AppDomain);
            //值类型绑定
            AppDomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Vector4), new Vector4Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());



            //是否注册各种binding
            if (isRegisterBindings)
            {
                ILRuntime.Runtime.Generated.CLRBindings.Initialize(AppDomain);
                ILRuntime.Runtime.Generated.CLRManualBindings.Initialize(AppDomain);
                // ILRuntime.Runtime.Generated.PreCLRBuilding.Initialize(AppDomain);
            }

            JsonMapper.RegisterILRuntimeCLRRedirection(AppDomain);


            if (Application.isEditor)
            {
                AppDomain.DebugService.StartDebugService(56000);
                Debug.Log("热更调试器 准备待命~");
            }

            //
            AppDomain.Invoke("HotfixCheck", "Log", null, null);
        }
Exemple #4
0
        // manual register
        public static void Init(ILRuntime.Runtime.Enviorment.AppDomain app)
        {
            if (app == null)
            {
                // should log error
                return;
            }

            ILRuntime.Runtime.Enviorment.PrimitiveConverter <ILRuntimeTest.TestFramework.TestCLREnum> .ToInteger   = (a) => (int)a;
            ILRuntime.Runtime.Enviorment.PrimitiveConverter <ILRuntimeTest.TestFramework.TestCLREnum> .FromInteger = (a) => (ILRuntimeTest.TestFramework.TestCLREnum)a;

            // adaptor register

            app.RegisterCrossBindingAdaptor(new ClassInheritanceTestAdaptor());
            app.RegisterCrossBindingAdaptor(new InterfaceTestAdaptor());
            app.RegisterCrossBindingAdaptor(new TestClass2Adapter());
            app.RegisterCrossBindingAdaptor(new TestClass3Adaptor());
            app.RegisterCrossBindingAdaptor(new TestClass4Adaptor());
            app.RegisterCrossBindingAdaptor(new IDisposableAdapter());
            app.RegisterCrossBindingAdaptor(new ClassInheritanceTest2Adaptor());
            app.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor());

            // value type register

            app.RegisterValueTypeBinder(typeof(TestVector3), new TestVector3Binder());
            app.RegisterValueTypeBinder(typeof(TestVectorStruct), new TestVectorStructBinder());
            app.RegisterValueTypeBinder(typeof(TestVectorStruct2), new TestVectorStruct2Binder());
            app.RegisterValueTypeBinder(typeof(System.Collections.Generic.KeyValuePair <uint, ILRuntime.Runtime.Intepreter.ILTypeInstance>), new KeyValuePairUInt32ILTypeInstanceBinder());

            // delegate register

            app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Boolean>();

            app.DelegateManager.RegisterMethodDelegate <System.Int32>();

            app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Int32>();

            app.DelegateManager.RegisterMethodDelegate <System.Int32, System.String, System.String>();

            app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestFramework.BaseClassTest>();

            app.DelegateManager.RegisterFunctionDelegate <System.Int32>();
            app.DelegateManager.RegisterFunctionDelegate <System.Collections.Generic.KeyValuePair <System.Int32, System.Collections.Generic.List <System.Int32> >, System.Collections.Generic.IEnumerable <System.Int32> >();
            app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Single, System.Int16, System.Double>();
            app.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Boolean>();
            app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestFramework.TestCLREnum>();
            app.DelegateManager.RegisterFunctionDelegate <ILRuntimeTest.TestFramework.TestCLREnum>();
            app.DelegateManager.RegisterFunctionDelegate <System.Threading.Tasks.Task <System.Collections.Generic.List <System.String> > >();
            app.DelegateManager.RegisterFunctionDelegate <System.Byte, System.Boolean>();
            app.DelegateManager.RegisterFunctionDelegate <System.Byte, System.Byte>();
            app.DelegateManager.RegisterFunctionDelegate <System.Linq.IGrouping <System.Byte, System.Byte>, ILRuntime.Runtime.Intepreter.ILTypeInstance>();
            app.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int32>();
            app.DelegateManager.RegisterFunctionDelegate <ILRuntimeTest.TestFramework.TestVector3, System.Single>();
            app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestFramework.TestVector3>();
            // delegate convertor
            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.TestValueTypeDelegate>((act) =>
            {
                return(new ILRuntimeTest.TestFramework.TestValueTypeDelegate((vec) =>
                {
                    ((Action <ILRuntimeTest.TestFramework.TestVector3>)act)(vec);
                }));
            });
            app.DelegateManager.RegisterDelegateConvertor <System.Predicate <ILRuntime.Runtime.Intepreter.ILTypeInstance> >((act) =>
            {
                return(new System.Predicate <ILRuntime.Runtime.Intepreter.ILTypeInstance>((obj) =>
                {
                    return ((Func <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Boolean>)act)(obj);
                }));
            });
            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntDelegate>((action) =>
            {
                return(new ILRuntimeTest.TestFramework.IntDelegate((a) =>
                {
                    ((Action <Int32>)action)(a);
                }));
            });
            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.Int2Delegate>((action) =>
            {
                return(new ILRuntimeTest.TestFramework.Int2Delegate((a, b) =>
                {
                    ((Action <Int32, Int32>)action)(a, b);
                }));
            });
            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.InitFloat>((action) =>
            {
                return(new ILRuntimeTest.TestFramework.InitFloat((a, b) =>
                {
                    ((Action <Int32, Single>)action)(a, b);
                }));
            });
            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntDelegate2>((action) =>
            {
                return(new ILRuntimeTest.TestFramework.IntDelegate2((a) =>
                {
                    return ((Func <Int32, Int32>)action)(a);
                }));
            });

            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.Int2Delegate2>((action) =>
            {
                return(new ILRuntimeTest.TestFramework.Int2Delegate2((a, b) =>
                {
                    return ((Func <Int32, Int32, Boolean>)action)(a, b);
                }));
            });

            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntFloatDelegate2>((action) =>
            {
                return(new ILRuntimeTest.TestFramework.IntFloatDelegate2((a, b) =>
                {
                    return ((Func <Int32, Single, String>)action)(a, b);
                }));
            });
            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.BindableProperty <System.Int64> .onChangeWithOldVal>((act) =>
            {
                return(new ILRuntimeTest.TestFramework.BindableProperty <System.Int64> .onChangeWithOldVal((oldVal, newVal) =>
                {
                    ((Action <System.Int64, System.Int64>)act)(oldVal, newVal);
                }));
            });
            // LitJson register
            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(app);

            app.DelegateManager.RegisterMethodDelegate <System.Object>();
            app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestBase.ExtensionClass, System.Object>();
            app.DelegateManager.RegisterMethodDelegate <System.Exception>();
            app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestBase.ExtensionClass, System.Exception>();
            app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestBase.ExtensionClass, System.ArgumentException>();
            app.DelegateManager.RegisterMethodDelegate <System.Exception>();
            app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestBase.ExtensionClass <System.Int32>, System.Exception>();
            app.DelegateManager.RegisterMethodDelegate <System.ArgumentException>();
            app.DelegateManager.RegisterMethodDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance>();
            app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestBase.ExtensionClass <System.Int32>, System.ArgumentException>();
            app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestBase.ExtensionClass>();
            app.DelegateManager.RegisterMethodDelegate <System.Int64, System.Int64>();
            app.DelegateManager.RegisterFunctionDelegate <ILRuntimeTest.TestBase.ExtensionClass, System.Int32>();
            app.DelegateManager.RegisterFunctionDelegate <System.Threading.Tasks.Task>();
            app.DelegateManager.RegisterFunctionDelegate <ILRuntimeTest.TestBase.ExtensionClass, System.Threading.Tasks.Task>();
            app.DelegateManager.RegisterFunctionDelegate <System.Threading.Tasks.Task <System.Int32> >();
            app.DelegateManager.RegisterFunctionDelegate <ILRuntimeTest.TestBase.ExtensionClass, System.Threading.Tasks.Task <System.Int32> >();

            app.Prewarm("TestCases.AsyncAwaitTest", false);
            //app.Prewarm("ILRuntime.Runtime.Enviorment.CrossBindingAdaptorType");
        }
Exemple #5
0
        // manual register
        public static void Init(ILRuntime.Runtime.Enviorment.AppDomain app)
        {
            if (app == null)
            {
                // should log error
                return;
            }

            // adaptor register

            app.RegisterCrossBindingAdaptor(new ClassInheritanceTestAdaptor());
            app.RegisterCrossBindingAdaptor(new InterfaceTestAdaptor());
            app.RegisterCrossBindingAdaptor(new TestClass2Adaptor());
            app.RegisterCrossBindingAdaptor(new TestClass3Adaptor());
            app.RegisterCrossBindingAdaptor(new TestClass4Adaptor());
            app.RegisterCrossBindingAdaptor(new IDisposableClassInheritanceAdaptor());
            app.RegisterCrossBindingAdaptor(new ClassInheritanceTest2Adaptor());
            app.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor());

            // value type register

            app.RegisterValueTypeBinder(typeof(TestVector3), new TestVector3Binder());
            app.RegisterValueTypeBinder(typeof(TestVectorStruct), new TestVectorStructBinder());
            app.RegisterValueTypeBinder(typeof(TestVectorStruct2), new TestVectorStruct2Binder());

            // delegate register

            app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Boolean>();

            app.DelegateManager.RegisterMethodDelegate <System.Int32>();

            app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Int32>();

            app.DelegateManager.RegisterMethodDelegate <System.Int32, System.String, System.String>();

            app.DelegateManager.RegisterMethodDelegate <ILRuntimeTest.TestFramework.BaseClassTest>();

            app.DelegateManager.RegisterFunctionDelegate <System.Int32>();

            app.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Single, System.Int16, System.Double>();
            app.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Boolean>();

            // delegate convertor
            app.DelegateManager.RegisterDelegateConvertor <System.Predicate <ILRuntime.Runtime.Intepreter.ILTypeInstance> >((act) =>
            {
                return(new System.Predicate <ILRuntime.Runtime.Intepreter.ILTypeInstance>((obj) =>
                {
                    return ((Func <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Boolean>)act)(obj);
                }));
            });
            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntDelegate>((action) =>
            {
                return(new ILRuntimeTest.TestFramework.IntDelegate((a) =>
                {
                    ((Action <Int32>)action)(a);
                }));
            });
            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.Int2Delegate>((action) =>
            {
                return(new ILRuntimeTest.TestFramework.Int2Delegate((a, b) =>
                {
                    ((Action <Int32, Int32>)action)(a, b);
                }));
            });
            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.InitFloat>((action) =>
            {
                return(new ILRuntimeTest.TestFramework.InitFloat((a, b) =>
                {
                    ((Action <Int32, Single>)action)(a, b);
                }));
            });
            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntDelegate2>((action) =>
            {
                return(new ILRuntimeTest.TestFramework.IntDelegate2((a) =>
                {
                    return ((Func <Int32, Int32>)action)(a);
                }));
            });

            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.Int2Delegate2>((action) =>
            {
                return(new ILRuntimeTest.TestFramework.Int2Delegate2((a, b) =>
                {
                    return ((Func <Int32, Int32, Boolean>)action)(a, b);
                }));
            });

            app.DelegateManager.RegisterDelegateConvertor <ILRuntimeTest.TestFramework.IntFloatDelegate2>((action) =>
            {
                return(new ILRuntimeTest.TestFramework.IntFloatDelegate2((a, b) =>
                {
                    return ((Func <Int32, Single, String>)action)(a, b);
                }));
            });

            // LitJson register
            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(app);
        }
Exemple #6
0
        /// <summary>
        /// 初始化一下ILRuntime框架的东西
        /// 注册一些回掉
        /// </summary>
        unsafe void InitializeILRuntime()
        {
            // 注册litjson
            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);

            appdomain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter());
            appdomain.RegisterCrossBindingAdaptor(new CoroutineAdapter());

            //添加值绑定
            appdomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
            appdomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());
            appdomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());

            //==============================如果将委托实例传出给ILRuntime外部使用=============================================
            appdomain.DelegateManager.RegisterMethodDelegate <int>();
            appdomain.DelegateManager.RegisterMethodDelegate <int, MemoryStream>();
            appdomain.DelegateManager.RegisterMethodDelegate <Scene, LoadSceneMode>();
            appdomain.DelegateManager.RegisterMethodDelegate <int, object>();
            appdomain.DelegateManager.RegisterMethodDelegate <GameObject>();
            appdomain.DelegateManager.RegisterMethodDelegate <bool>();
            appdomain.DelegateManager.RegisterMethodDelegate <GameObject[]>();
            appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Object[]>();
            appdomain.DelegateManager.RegisterMethodDelegate <Sprite[]>();
            appdomain.DelegateManager.RegisterMethodDelegate <BaseEventData>();
            appdomain.DelegateManager.RegisterMethodDelegate <float>();
            appdomain.DelegateManager.RegisterMethodDelegate <Dictionary <string, string> >();
            appdomain.DelegateManager.RegisterMethodDelegate <string>();
            appdomain.DelegateManager.RegisterMethodDelegate <NotificationMessage>();
            appdomain.DelegateManager.RegisterMethodDelegate <AssetBundlePackage>();
            appdomain.DelegateManager.RegisterMethodDelegate <TrackEntry>();
            appdomain.DelegateManager.RegisterFunctionDelegate <GameObject>();
            appdomain.DelegateManager.RegisterMethodDelegate <System.Int32, System.Byte[]>();

            //===========================委托转换器(DelegateConvertor)================================================
            // 如果你需要将一个不是Action或者Func类型的委托实例传到ILRuntime外部使用的话,
            // 除了委托适配器,还需要额外写一个转换器,将Action和Func转换成你真正需要的那个委托类型
            appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction>((action) =>
            {
                return(new UnityAction(() => { ((Action)action)(); }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <bool> >((action) =>
            {
                return(new UnityAction <bool>((a) => { ((Action <bool>)action)(a); }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <string> >((action) =>
            {
                return(new UnityAction <string>((a) => { ((Action <string>)action)(a); }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <float> >((action) =>
            {
                return(new UnityAction <float>((a) => { ((Action <float>)action)(a); }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <Scene, LoadSceneMode> >((action) =>
            {
                return(new UnityAction <Scene, LoadSceneMode>((s, l) =>
                {
                    ((Action <Scene, LoadSceneMode>)action)(s, l);
                }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <TweenCallback>((action) =>
            {
                return(new TweenCallback(() => { ((Action)action)(); }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <BaseEventData> >((action) =>
            {
                return(new UnityAction <BaseEventData>((p) => { ((Action <BaseEventData>)action)(p); }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <Spine.AnimationState.TrackEntryDelegate>((action) =>
            {
                return(new Spine.AnimationState.TrackEntryDelegate((p) => { ((Action <TrackEntry>)action)(p); }));
            });

            //不要注释  否则会开启大量反射方法
            ILRuntime.Runtime.Generated.CLRBindings.Initialize(appdomain);
            AppDomainCommonSetting.Instance.SetupCLRRedirection(appdomain);
        }
Exemple #7
0
        void InitializeILRuntime()
        {
            #region Delegate

            appDomain.DelegateManager.RegisterMethodDelegate <int>();
            appDomain.DelegateManager.RegisterFunctionDelegate <int, string>();
            appDomain.DelegateManager.RegisterMethodDelegate <string>();
            appDomain.DelegateManager.RegisterMethodDelegate <int, int>();
            appDomain.DelegateManager.RegisterMethodDelegate <List <int>, List <int> >();
            appDomain.DelegateManager.RegisterMethodDelegate <string, string>();
            appDomain.DelegateManager.RegisterMethodDelegate <object, MessageArgs <object> >();
            appDomain.DelegateManager.RegisterMethodDelegate <object, MessageArgs <ILTypeInstance> >();

            //appDomain.DelegateManager.RegisterDelegateConvertor<TestDelegateMethod>((action) =>
            //{
            //    //转换器的目的是把Action或者Func转换成正确的类型,这里则是把Action<int>转换成TestDelegateMethod
            //    return new TestDelegateMethod((a) =>
            //    {
            //        //调用委托实例
            //        ((Action<int>)action)(a);
            //    });
            //});

            //appDomain.DelegateManager.RegisterDelegateConvertor<TestDelegateFunction>((action) =>
            //{
            //    return new TestDelegateFunction((a) =>
            //    {
            //        return ((Func<int, string>)action)(a);
            //    });
            //});

            appDomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <float> >((action) =>
            {
                return(new UnityEngine.Events.UnityAction <float>((a) =>
                {
                    ((Action <float>)action)(a);
                }));
            });

            #endregion

            #region CLRBinding

            //ILRuntime.Runtime.Generated.CLRBindings.Initialize(appDomain);

            #endregion

            #region Adaptor

            appDomain.RegisterCrossBindingAdaptor(new ViewModelBaseAdapter());
            appDomain.RegisterCrossBindingAdaptor(new UnityGuiViewAdapter());
            appDomain.RegisterCrossBindingAdaptor(new ModuleBaseAdapter());
            appDomain.RegisterCrossBindingAdaptor(new ComponentAdapter());

            #endregion

            appDomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());


            #region UniRX

            appDomain.DelegateManager.RegisterMethodDelegate <Exception>();
            appDomain.DelegateManager.RegisterMethodDelegate <UniRx.Unit>();

            #endregion
        }
Exemple #8
0
        public unsafe static void Register(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
        {
#if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE)
            appdomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId;
#endif
            // 注册litjson
            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);

            appdomain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter());
            appdomain.RegisterCrossBindingAdaptor(new CoroutineAdapter());
            appdomain.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor());

            //添加值绑定
            appdomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
            appdomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());
            appdomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());

            //Log 重定向 为了显示行号
            var mi = typeof(HFLog).GetMethod("L", new System.Type[] { typeof(object) });
            appdomain.RegisterCLRMethodRedirection(mi, L);

            mi = typeof(HFLog).GetMethod("C", new System.Type[] { typeof(object), typeof(LogColor) });
            appdomain.RegisterCLRMethodRedirection(mi, C);

            mi = typeof(HFLog).GetMethod("E", new System.Type[] { typeof(object) });
            appdomain.RegisterCLRMethodRedirection(mi, E);

            //==============================如果将委托实例传出给ILRuntime外部使用=============================================
            appdomain.DelegateManager.RegisterMethodDelegate <int>();
            appdomain.DelegateManager.RegisterMethodDelegate <int, MemoryStream>();
            appdomain.DelegateManager.RegisterMethodDelegate <Scene, LoadSceneMode>();
            appdomain.DelegateManager.RegisterMethodDelegate <int, object>();
            appdomain.DelegateManager.RegisterMethodDelegate <GameObject>();
            appdomain.DelegateManager.RegisterMethodDelegate <bool>();
            appdomain.DelegateManager.RegisterMethodDelegate <GameObject[]>();
            appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Object[]>();
            appdomain.DelegateManager.RegisterMethodDelegate <Sprite[]>();
            appdomain.DelegateManager.RegisterMethodDelegate <BaseEventData>();
            appdomain.DelegateManager.RegisterMethodDelegate <float>();
            appdomain.DelegateManager.RegisterMethodDelegate <Dictionary <string, string> >();
            appdomain.DelegateManager.RegisterMethodDelegate <string>();
            appdomain.DelegateManager.RegisterMethodDelegate <NotificationMessage>();
            appdomain.DelegateManager.RegisterMethodDelegate <AssetPackage>();
            appdomain.DelegateManager.RegisterFunctionDelegate <GameObject>();
            appdomain.DelegateManager.RegisterMethodDelegate <System.Int32, System.Byte[]>();

            //===========================委托转换器(DelegateConvertor)================================================
            // 如果你需要将一个不是Action或者Func类型的委托实例传到ILRuntime外部使用的话,
            // 除了委托适配器,还需要额外写一个转换器,将Action和Func转换成你真正需要的那个委托类型
            appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction>((action) =>
            {
                return(new UnityAction(() => { ((Action)action)(); }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <bool> >((action) =>
            {
                return(new UnityAction <bool>((a) => { ((Action <bool>)action)(a); }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <string> >((action) =>
            {
                return(new UnityAction <string>((a) => { ((Action <string>)action)(a); }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <float> >((action) =>
            {
                return(new UnityAction <float>((a) => { ((Action <float>)action)(a); }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <Scene, LoadSceneMode> >((action) =>
            {
                return(new UnityAction <Scene, LoadSceneMode>((s, l) =>
                {
                    ((Action <Scene, LoadSceneMode>)action)(s, l);
                }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <TweenCallback>((action) =>
            {
                return(new TweenCallback(() => { ((Action)action)(); }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <BaseEventData> >((action) =>
            {
                return(new UnityAction <BaseEventData>((p) => { ((Action <BaseEventData>)action)(p); }));
            });
        }
Exemple #9
0
 public void Register(AppDomain appdomain)
 {
     appdomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
     appdomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());
     appdomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());
 }