Exemplo n.º 1
0
        /// <summary>
        /// 主工程的绑定
        /// </summary>
        /// <param name="isRegisterBindings"></param>
        static public void Bind(bool isRegisterBindings)
        {
            var AppDomain = BDFramework.ILRuntimeHelper.AppDomain;

            //绑定的初始化
            //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)
            {
                //手动绑定放前
                ManualCLRBindings.Initialize(AppDomain);
                //自动绑定最后
                CLRBindings.Initialize(AppDomain);
                //PreCLRBinding.Initialize(AppDomain);
                BDebug.Log("[ILRuntime] CLR Binding Success!!!");
            }
        }
Exemplo n.º 2
0
    public static void InitILRuntime(AppDomain appdomain)
    {
        // 注册重定向函数

        // 注册委托
        //appdomain.DelegateManager.RegisterMethodDelegate<List<object>>();
        //appdomain.DelegateManager.RegisterMethodDelegate<byte[], int, int>();
        //appdomain.DelegateManager.RegisterMethodDelegate<ILTypeInstance>();

        //注册绑定的导出类
        //Debug的功能需要打印堆栈,所以这里要自定义,不能用系统生成的
        UnityEngineDebugBinding.Register(appdomain);

        //值类型绑定,后续改成自动生成
        appdomain.RegisterValueTypeBinder(typeof(UnityEngine.Vector3), new Vector3Binder());
        appdomain.RegisterValueTypeBinder(typeof(UnityEngine.Quaternion), new QuaternionBinder());
        appdomain.RegisterValueTypeBinder(typeof(UnityEngine.Vector2), new Vector2Binder());
        appdomain.RegisterValueTypeBinder(typeof(UnityEngine.Vector2Int), new Vector2IntBinder());
        appdomain.RegisterValueTypeBinder(typeof(FP), new Fix64Binder());
        appdomain.RegisterValueTypeBinder(typeof(TSVector2), new TSVector2Binder());
        appdomain.RegisterValueTypeBinder(typeof(TSVector), new TSVectorBinder());
        appdomain.RegisterValueTypeBinder(typeof(TSQuaternion), new TSQuaternionBinder());
        appdomain.RegisterValueTypeBinder(typeof(TSMatrix), new TSMatrixBinder());
        appdomain.RegisterValueTypeBinder(typeof(TSMatrix4x4), new TSMatrix4x4Binder());

        CLRBindings.Initialize(appdomain);
        appdomain.RegisterCrossBindingAdaptor(new CoroutineAdapter());

        LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
    }
Exemplo n.º 3
0
        public static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
        {
#if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE)
            //由于Unity的Profiler接口只允许在主线程使用,为了避免出异常,需要告诉ILRuntime主线程的线程ID才能正确将函数运行耗时报告给Profiler
            appdomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId;
#endif
            //这里做一些ILRuntime的注册,这里我们注册值类型Binder,注释和解注下面的代码来对比性能差别
            appdomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
            appdomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());
            appdomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());

            InitDelegates(appdomain);
            SetupCLRRedirection(appdomain);

            // 注册适配器(需要在适配器添加 ILAdapterAttribute 标签)
            Assembly assembly = typeof(Init).Assembly;
            foreach (Type type in assembly.GetTypes())
            {
                object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj = Activator.CreateInstance(type);
                CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
                if (adaptor == null)
                {
                    continue;
                }
                appdomain.RegisterCrossBindingAdaptor(adaptor);
            }

            CLRBindings.Initialize(appdomain);
            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
        }
Exemplo n.º 4
0
        public static void InitILRuntime(AppDomain appDomain)
        {
            //TODO:注册重定向方法

            //TODO:适配委托
            appDomain.DelegateManager.RegisterMethodDelegate <float>();
            appDomain.DelegateManager.RegisterMethodDelegate <object, GameFramework.Event.GameEventArgs>();

            appDomain.DelegateManager.RegisterMethodDelegate <List <object> >();
            appDomain.DelegateManager.RegisterMethodDelegate <AChannel, System.Net.Sockets.SocketError>();
            appDomain.DelegateManager.RegisterMethodDelegate <byte[], int, int>();
            appDomain.DelegateManager.RegisterMethodDelegate <IResponse>();
            appDomain.DelegateManager.RegisterMethodDelegate <Session, object>();
            appDomain.DelegateManager.RegisterMethodDelegate <Session, byte, ushort, MemoryStream>();
            appDomain.DelegateManager.RegisterMethodDelegate <Session>();
            appDomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>();

            appDomain.DelegateManager.RegisterFunctionDelegate <IMessageAdaptor.Adaptor>();
            appDomain.DelegateManager.RegisterMethodDelegate <IMessageAdaptor.Adaptor>();

            //TODO:注册委托
            appDomain.DelegateManager.RegisterDelegateConvertor <UnityAction>((action) =>
            {
                return(new UnityAction(() =>
                {
                    ((Action)action)();
                }));
            });

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

            appDomain.DelegateManager.RegisterDelegateConvertor <System.EventHandler <GameFramework.Event.GameEventArgs> >((act) =>
            {
                return(new System.EventHandler <GameFramework.Event.GameEventArgs>((sender, e) =>
                {
                    ((Action <System.Object, GameFramework.Event.GameEventArgs>)act)(sender, e);
                }));
            });


            //注册CLR绑定代码
            CLRBindings.Initialize(appDomain);

            //TODO:注册跨域继承适配器
            appDomain.RegisterCrossBindingAdaptor(new GameEventArgsAdaptor());
            appDomain.RegisterCrossBindingAdaptor(new IReferenceAdaptor());
            appDomain.RegisterCrossBindingAdaptor(new IMessageAdaptor());
            appDomain.RegisterCrossBindingAdaptor(new IDisposableAdaptor());
            appDomain.RegisterCrossBindingAdaptor(new IAsyncStateMachineAdaptor());


            //注册LitJson
            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appDomain);
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
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;
    }
Exemplo n.º 7
0
        public static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
        {
            // 注册重定向函数

            // 注册委托
            appdomain.DelegateManager.RegisterMethodDelegate <int, int>();
            appdomain.DelegateManager.RegisterMethodDelegate <float, float>();
            appdomain.DelegateManager.RegisterMethodDelegate <float, float, float>();
            appdomain.DelegateManager.RegisterMethodDelegate <List <object> >();
            appdomain.DelegateManager.RegisterMethodDelegate <AChannel, System.Net.Sockets.SocketError>();
            appdomain.DelegateManager.RegisterMethodDelegate <byte[], int, int>();
            appdomain.DelegateManager.RegisterMethodDelegate <IResponse>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session, object>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session, byte, ushort, MemoryStream>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session>();
            appdomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>();
            appdomain.DelegateManager.RegisterMethodDelegate <EventContext>();
            appdomain.DelegateManager.RegisterFunctionDelegate <Google.Protobuf.Adapt_IMessage.Adaptor>();
            appdomain.DelegateManager.RegisterMethodDelegate <Google.Protobuf.Adapt_IMessage.Adaptor>();
            appdomain.DelegateManager.RegisterDelegateConvertor <FairyGUI.EventCallback0>((act) =>
            {
                return(new FairyGUI.EventCallback0(() =>
                {
                    ((Action)act)();
                }));
            });
            appdomain.DelegateManager.RegisterDelegateConvertor <FairyGUI.EventCallback1>((act) =>
            {
                return(new FairyGUI.EventCallback1((context) =>
                {
                    ((Action <FairyGUI.EventContext>)act)(context);
                }));
            });


            CLRBindings.Initialize(appdomain);

            // 注册适配器
            Assembly assembly = typeof(Init).Assembly;

            foreach (Type type in assembly.GetTypes())
            {
                object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj = Activator.CreateInstance(type);
                CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
                if (adaptor == null)
                {
                    continue;
                }
                appdomain.RegisterCrossBindingAdaptor(adaptor);
            }

            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
        }
Exemplo n.º 8
0
 public static void OnILRuntimeInitialized(ILRAppDomain appDomain)
 {
     CLRBindings.Initialize(appDomain);
     // 跨域继承适配器
     registeCrossAdaptor(appDomain);
     // 跨域调用的委托
     registeAllDelegate(appDomain);
     ILRUtility.callStatic("GameILR", "startILR");
 }
Exemplo n.º 9
0
        public static void LoadHotfix(string dllPath, bool isRegisterBindings = true)
        {
            //
            IsRunning = true;
            string pdbPath = dllPath.Replace(".dll", ".pdb");

            Debug.Log("DLL加载路径:" + dllPath);
            //
            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)
            {
                CLRBindings.Initialize(AppDomain);
                CLRManualBindings.Initialize(AppDomain);
                // ILRuntime.Runtime.Generated.PreCLRBuilding.Initialize(AppDomain);
            }

            JsonMapper.RegisterILRuntimeCLRRedirection(AppDomain);

            if (Application.isEditor)
            {
                AppDomain.DebugService.StartDebugService(56000);
                Debug.Log("热更调试器 准备待命~");
            }
        }
Exemplo n.º 10
0
        public static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
        {
            // 注册重定向函数

            // 注册委托
            appdomain.DelegateManager.RegisterMethodDelegate <object>();
            appdomain.DelegateManager.RegisterMethodDelegate <object[]>();
            appdomain.DelegateManager.RegisterMethodDelegate <long>();
            appdomain.DelegateManager.RegisterMethodDelegate <ulong>();
            appdomain.DelegateManager.RegisterMethodDelegate <int>();
            appdomain.DelegateManager.RegisterMethodDelegate <uint>();
            appdomain.DelegateManager.RegisterMethodDelegate <short>();
            appdomain.DelegateManager.RegisterMethodDelegate <ushort>();
            appdomain.DelegateManager.RegisterMethodDelegate <char>();
            appdomain.DelegateManager.RegisterMethodDelegate <string>();
            appdomain.DelegateManager.RegisterMethodDelegate <object, object>();
            appdomain.DelegateManager.RegisterMethodDelegate <int, object>();
            appdomain.DelegateManager.RegisterMethodDelegate <long, object>();
            appdomain.DelegateManager.RegisterMethodDelegate <string, object>();

            appdomain.DelegateManager.RegisterMethodDelegate <List <object> >();
            appdomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>();

            ILRegType.RegisterMethodDelegate(appdomain);
            ILRegType.RegisterFunctionDelegate(appdomain);
            ILRegType.RegisterDelegateConvertor(appdomain);

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

            // 注册适配器
            Assembly assembly = typeof(GameEntry).Assembly;

            foreach (Type type in assembly.GetTypes())
            {
                object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj = Activator.CreateInstance(type);
                CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
                if (adaptor == null)
                {
                    continue;
                }

                appdomain.RegisterCrossBindingAdaptor(adaptor);
            }

            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
        }
Exemplo n.º 11
0
        public static unsafe void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appDomain)
        {
            // 注册重定向函数

            // 注册委托
            appDomain.DelegateManager.RegisterMethodDelegate <List <object> >();
            appDomain.DelegateManager.RegisterMethodDelegate <AChannel, System.Net.Sockets.SocketError>();
            appDomain.DelegateManager.RegisterMethodDelegate <byte[], int, int>();
            appDomain.DelegateManager.RegisterMethodDelegate <IResponse>();
            appDomain.DelegateManager.RegisterMethodDelegate <Session, object>();
            appDomain.DelegateManager.RegisterMethodDelegate <Session, Packet>();
            appDomain.DelegateManager.RegisterMethodDelegate <Session>();
            appDomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>();
            appDomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance, System.Boolean>();

            appDomain.DelegateManager.RegisterFunctionDelegate <ILTypeInstance, System.Boolean>();

            appDomain.DelegateManager.RegisterDelegateConvertor <Predicate <ILTypeInstance> >((act) =>
            {
                return(new Predicate <ILTypeInstance>((obj) =>
                {
                    return ((Func <ILTypeInstance, System.Boolean>)act)(obj);
                }));
            });


            CLRBindings.Initialize(appDomain);

            // 注册适配器
            Assembly assembly = typeof(Init).Assembly;

            foreach (Type type in assembly.GetTypes())
            {
                object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj = Activator.CreateInstance(type);
                CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
                if (adaptor == null)
                {
                    continue;
                }
                appDomain.RegisterCrossBindingAdaptor(adaptor);
            }

            // 初始化ILRuntime的protobuf
            InitializeILRuntimeProtobuf(appDomain);
            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appDomain);
        }
Exemplo n.º 12
0
        public static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
        {
            // 注册重定向函数

            // 注册委托
            appdomain.DelegateManager.RegisterMethodDelegate <List <object> >();
            appdomain.DelegateManager.RegisterMethodDelegate <AChannel, System.Net.Sockets.SocketError>();
            appdomain.DelegateManager.RegisterMethodDelegate <byte[], int, int>();
            appdomain.DelegateManager.RegisterMethodDelegate <IResponse>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session, object>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session, byte, ushort, MemoryStream>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session>();
            appdomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>();
            appdomain.DelegateManager.RegisterFunctionDelegate <Google.Protobuf.Adapt_IMessage.Adaptor>();
            appdomain.DelegateManager.RegisterMethodDelegate <Google.Protobuf.Adapt_IMessage.Adaptor>();

            // Task Override
            appdomain.DelegateManager.RegisterFunctionDelegate <TaskStatus>();
            appdomain.DelegateManager.RegisterFunctionDelegate <object, bool>();

            // ParentTask Override
            appdomain.DelegateManager.RegisterFunctionDelegate <TaskStatus, TaskStatus>();
            appdomain.DelegateManager.RegisterMethodDelegate <int, TaskStatus>();
            appdomain.DelegateManager.RegisterMethodDelegate <TaskStatus>();

            CLRBindings.Initialize(appdomain);

            // 注册适配器
            Assembly assembly = typeof(Init).Assembly;

            foreach (Type type in assembly.GetTypes())
            {
                object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj = Activator.CreateInstance(type);
                CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
                if (adaptor == null)
                {
                    continue;
                }
                appdomain.RegisterCrossBindingAdaptor(adaptor);
            }

            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
        }
Exemplo n.º 13
0
        public static unsafe void InitILRuntime()
        {
            // 注册重定向函数
            MethodInfo mi = typeof(Log).GetMethod("Debug", new Type[] { typeof(string) });

            Init.Instance.AppDomain.RegisterCLRMethodRedirection(mi, ILRedirection.LogDebug);

            MethodInfo mi2 = typeof(Log).GetMethod("Info", new Type[] { typeof(string) });

            Init.Instance.AppDomain.RegisterCLRMethodRedirection(mi2, ILRedirection.LogInfo);

            MethodInfo mi3 = typeof(Log).GetMethod("Error", new Type[] { typeof(string) });

            Init.Instance.AppDomain.RegisterCLRMethodRedirection(mi3, ILRedirection.LogError);

            // 注册委托
            Init.Instance.AppDomain.DelegateManager.RegisterMethodDelegate <List <object> >();
            Init.Instance.AppDomain.DelegateManager.RegisterMethodDelegate <AChannel, System.Net.Sockets.SocketError>();
            Init.Instance.AppDomain.DelegateManager.RegisterMethodDelegate <byte[], int, int>();
            Init.Instance.AppDomain.DelegateManager.RegisterMethodDelegate <IResponse>();
            Init.Instance.AppDomain.DelegateManager.RegisterMethodDelegate <Session, PacketInfo>();
            Init.Instance.AppDomain.DelegateManager.RegisterMethodDelegate <Session, object>();

            CLRBindings.Initialize(Init.Instance.AppDomain);

            // 注册适配器
            Assembly assembly = typeof(Init).Assembly;

            foreach (Type type in assembly.GetTypes())
            {
                object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj = Activator.CreateInstance(type);
                CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
                if (adaptor == null)
                {
                    continue;
                }
                Init.Instance.AppDomain.RegisterCrossBindingAdaptor(adaptor);
            }

            // 初始化ILRuntime的protobuf
            InitializeILRuntimeProtobuf();
        }
Exemplo n.º 14
0
    public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
    {
        // 注册委托
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction>((act) =>
        {
            return(new UnityEngine.Events.UnityAction(() =>
            {
                ((Action)act)();
            }));
        });

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

        // 注册适配器
        appdomain.RegisterCrossBindingAdaptor(new IUIInterfaceAdapter());
    }
Exemplo n.º 15
0
        /// <summary>
        /// 初始化ILRuntime
        /// </summary>
        public static void InitILRuntime(AppDomain appDomain)
        {
            //注册重定向方法

            //注册委托
            appDomain.DelegateManager.RegisterDelegateConvertor <UnityAction <float> >((action) =>
            {
                return(new UnityAction <float>((a) =>
                {
                    ((System.Action <float>)action)(a);
                }));
            });

            CLRBindings.Initialize(appDomain);

            //注册适配器
            appDomain.RegisterCrossBindingAdaptor(new IUpdaterAdapter());
        }
Exemplo n.º 16
0
        public static void InitILRuntime(AppDomain appDomain)
        {
            //TODO:注册重定向方法

            //TODO:适配委托
            appDomain.DelegateManager.RegisterMethodDelegate <float>();
            appDomain.DelegateManager.RegisterMethodDelegate <object, GameFramework.Event.GameEventArgs>();

            //TODO:注册委托
            appDomain.DelegateManager.RegisterDelegateConvertor <UnityAction>((action) =>
            {
                return(new UnityAction(() =>
                {
                    ((Action)action)();
                }));
            });

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

            appDomain.DelegateManager.RegisterDelegateConvertor <System.EventHandler <GameFramework.Event.GameEventArgs> >((act) =>
            {
                return(new System.EventHandler <GameFramework.Event.GameEventArgs>((sender, e) =>
                {
                    ((Action <System.Object, GameFramework.Event.GameEventArgs>)act)(sender, e);
                }));
            });


            //注册CLR绑定代码
            CLRBindings.Initialize(appDomain);

            //TODO:注册适配器
            appDomain.RegisterCrossBindingAdaptor(new GameEventArgsAdaptor());
            appDomain.RegisterCrossBindingAdaptor(new IReferenceAdaptor());

            //注册LitJson
            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appDomain);
        }
Exemplo n.º 17
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);
    }
Exemplo n.º 18
0
 void init()
 {
     //值类型绑定
     appdomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
     appdomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());
     appdomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());
     //委托绑定
     appdomain.DelegateManager.RegisterMethodDelegate <System.Int32>();
     appdomain.DelegateManager.RegisterDelegateConvertor <TestDelegate>((act) =>
     {
         return(new TestDelegate((intarg) =>
         {
             ((Action <System.Int32>)act)(intarg);
         }));
     });
     //重定向
     CLRBindings.Initialize(appdomain);
     LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
 }
Exemplo n.º 19
0
        public static void LoadAssembly(byte[] dll_data, byte[] pdb_data = null)
        {
            if (dll_data == null || dll_data.Length == 0)
            {
                Debug.LogError("== LoadAssembly parameter is null ==");
                return;
            }

            //首先实例化ILRuntime的AppDomain,AppDomain是一个应用程序域,每个AppDomain都是一个独立的沙盒
            if (null == _appdomain)
            {
                _appdomain = new ILRuntime.Runtime.Enviorment.AppDomain();

                //TODO For Debug
                //_appdomain.DebugService.StartDebugService(56000);
                LC_AdaptorHelper.Init(_appdomain);
                LC_Helper.Init(_appdomain);

                SetupCLRRedirection();
                SetupCLRRedirection2();

                CLRBindings.Initialize(_appdomain);
#if UNITY_EDITOR
//                _appdomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId;
                //Debug.Log("m_pcAppDomain.UnityMainThreadID:" + _appdomain.UnityMainThreadID);
#endif
            }

            using (var fs = new MemoryStream(dll_data))
            {
                MemoryStream p = null;
                if (pdb_data != null)
                {
                    p = new MemoryStream(pdb_data);
                }
                _appdomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider());
            }
        }
    public static void Init()
    {
        System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch();
        w.Start();

        try
        {
            app = new ILRuntime.Runtime.Enviorment.AppDomain();

            string dllname = "GameLogic";
#if UNITY_EDITOR
            string     dllpath = Application.dataPath + "/../../output/";
            FileStream msDll   = new FileStream(dllpath + dllname + ".dll", FileMode.Open);
            FileStream msPdb   = new FileStream(dllpath + dllname + ".pdb", FileMode.Open);
            app.LoadAssembly(msDll, msPdb, new Mono.Cecil.Pdb.PdbReaderProvider());
            msDll.Close();
            msPdb.Close();
#else
#endif
            SetupCrossBinding();
            SetupMethodDelegate();
            SetupCLRRedirection();
            CLRBindings.Initialize(app);

#if UNITY_EDITOR
            app.DebugService.StartDebugService(56000);
#endif
        }
        catch (Exception ex)
        {
            Debugger.LogException(ex);
        }

        w.Stop();
        Debugger.Log("Init ILRuntime finish. Use time : " + w.ElapsedMilliseconds + " ms", true);
    }
Exemplo n.º 21
0
        public static unsafe void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appDomain)
        {
            // 注册重定向函数

            // 注册委托
            appDomain.DelegateManager.RegisterMethodDelegate <List <object> >();
            appDomain.DelegateManager.RegisterMethodDelegate <AChannel, System.Net.Sockets.SocketError>();
            appDomain.DelegateManager.RegisterMethodDelegate <byte[], int, int>();
            appDomain.DelegateManager.RegisterMethodDelegate <IResponse>();
            appDomain.DelegateManager.RegisterMethodDelegate <Session, PacketInfo>();
            appDomain.DelegateManager.RegisterMethodDelegate <Session, uint, object>();

            CLRBindings.Initialize(appDomain);

            // 注册适配器
            Assembly assembly = typeof(Init).Assembly;

            foreach (Type type in assembly.GetTypes())
            {
                object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj = Activator.CreateInstance(type);
                CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
                if (adaptor == null)
                {
                    continue;
                }
                appDomain.RegisterCrossBindingAdaptor(adaptor);
            }

            // 初始化ILRuntime的protobuf
            InitializeILRuntimeProtobuf(appDomain);
        }
Exemplo n.º 22
0
        public static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
        {
            // 注册重定向函数

            // 注册委托
            appdomain.DelegateManager.RegisterMethodDelegate <List <object> >();
            appdomain.DelegateManager.RegisterMethodDelegate <object>();
            appdomain.DelegateManager.RegisterMethodDelegate <bool>();
            appdomain.DelegateManager.RegisterMethodDelegate <string>();
            appdomain.DelegateManager.RegisterMethodDelegate <float>();
            appdomain.DelegateManager.RegisterMethodDelegate <long, int>();
            appdomain.DelegateManager.RegisterMethodDelegate <long, MemoryStream>();
            appdomain.DelegateManager.RegisterMethodDelegate <long, IPEndPoint>();
            appdomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>();


            appdomain.DelegateManager.RegisterFunctionDelegate <UnityEngine.Events.UnityAction>();
            appdomain.DelegateManager.RegisterFunctionDelegate <System.Object, ET.ETTask>();
            appdomain.DelegateManager.RegisterFunctionDelegate <ILTypeInstance, bool>();
            appdomain.DelegateManager.RegisterFunctionDelegate <System.Collections.Generic.KeyValuePair <System.String, System.Int32>, System.String>();
            appdomain.DelegateManager.RegisterFunctionDelegate <System.Collections.Generic.KeyValuePair <System.Int32, System.Int32>, System.Boolean>();
            appdomain.DelegateManager.RegisterFunctionDelegate <System.Collections.Generic.KeyValuePair <System.String, System.Int32>, System.Int32>();
            appdomain.DelegateManager.RegisterFunctionDelegate <List <int>, int>();
            appdomain.DelegateManager.RegisterFunctionDelegate <List <int>, bool>();
            appdomain.DelegateManager.RegisterFunctionDelegate <int, bool>();     //Linq
            appdomain.DelegateManager.RegisterFunctionDelegate <int, int, int>(); //Linq
            appdomain.DelegateManager.RegisterFunctionDelegate <KeyValuePair <int, List <int> >, bool>();
            appdomain.DelegateManager.RegisterFunctionDelegate <KeyValuePair <int, int>, KeyValuePair <int, int>, int>();

            // 注册适配器
            RegisterAdaptor(appdomain);

            //LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);

            CLRBindings.Initialize(appdomain);
        }
Exemplo n.º 23
0
 public static void DoDestroy(AppDomain appdomain)
 {
     CLRBindings.Shutdown(appdomain);
 }
Exemplo n.º 24
0
 /// <summary>
 /// 构造一个演示用的AppDomain
 /// </summary>
 /// <param name="application">应用程序</param>
 /// <param name="debugLevel">调试等级</param>
 public DemoAppDomain(IApplication application, DebugLevels debugLevel)
     : base(application, debugLevel)
 {
     Adapter.RegisterAdapter.Register(Domain);
     CLRBindings.Initialize(Domain);
 }
Exemplo n.º 25
0
        public static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
        {
            // 注册重定向函数

            // 注册委托
            appdomain.DelegateManager.RegisterMethodDelegate <List <object> >();
            appdomain.DelegateManager.RegisterMethodDelegate <AChannel, System.Net.Sockets.SocketError>();
            appdomain.DelegateManager.RegisterMethodDelegate <byte[], int, int>();
            appdomain.DelegateManager.RegisterMethodDelegate <IResponse>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session, object>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session, byte, ushort, MemoryStream>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session>();
            appdomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>();
            appdomain.DelegateManager.RegisterFunctionDelegate <Google.Protobuf.Adapt_IMessage.Adaptor>();
            appdomain.DelegateManager.RegisterMethodDelegate <Google.Protobuf.Adapt_IMessage.Adaptor>();

            // 注意: 需要注册重定向函数需要在执行CLRBindings.Initialize前定义

            #region 注册 FairyGUI

            appdomain.DelegateManager.RegisterFunctionDelegate <FairyGUI.GComponent>();

            appdomain.DelegateManager.RegisterDelegateConvertor <FairyGUI.UIObjectFactory.GComponentCreator>((act) =>
            {
                return(new FairyGUI.UIObjectFactory.GComponentCreator(() =>
                {
                    return ((Func <FairyGUI.GComponent>)act)();
                }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <FairyGUI.EventCallback0>((act) =>
            {
                return(new FairyGUI.EventCallback0(() =>
                {
                    ((Action)act)();
                }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <ETModel.DoHideAnimationEvent>((act) =>
            {
                return(new ETModel.DoHideAnimationEvent(() =>
                {
                    ((Action)act)();
                }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <FairyGUI.PlayCompleteCallback>((act) =>
            {
                return(new FairyGUI.PlayCompleteCallback(() =>
                {
                    ((Action)act)();
                }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <ETModel.DoShowAnimationEvent>((act) =>
            {
                return(new ETModel.DoShowAnimationEvent(() =>
                {
                    ((Action)act)();
                }));
            });

            appdomain.DelegateManager.RegisterDelegateConvertor <ETModel.OnHideEvent>((act) =>
            {
                return(new ETModel.OnHideEvent(() =>
                {
                    ((Action)act)();
                }));
            });

            #endregion

            // 进行初始化
            CLRBindings.Initialize(appdomain);

            // 注册适配器
            Assembly assembly = typeof(Init).Assembly;
            foreach (Type type in assembly.GetTypes())
            {
                object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj = Activator.CreateInstance(type);
                CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
                if (adaptor == null)
                {
                    continue;
                }
                appdomain.RegisterCrossBindingAdaptor(adaptor);
            }

            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
        }
Exemplo n.º 26
0
    public static unsafe void InitializeILRuntime(AppDomain appdomain)
    {
        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

        #region 这里添加ILRuntime的注册 HERE TO ADD ILRuntime Registerations

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

        appdomain.DelegateManager.RegisterMethodDelegate <libx.AssetRequest>();
        appdomain.DelegateManager.RegisterFunctionDelegate <System.Threading.Tasks.Task <ILRuntime.Runtime.Intepreter.ILTypeInstance> >();
        appdomain.DelegateManager.RegisterMethodDelegate <Object>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.Object>();
        appdomain.DelegateManager
        .RegisterFunctionDelegate <ILTypeInstance, Boolean>();
        appdomain.DelegateManager.RegisterMethodDelegate <List <Object> >();
        appdomain.DelegateManager
        .RegisterMethodDelegate <IDictionary <String, UnityEngine.Object> >();
        appdomain.DelegateManager.RegisterMethodDelegate <Boolean>();
        appdomain.DelegateManager.RegisterMethodDelegate <Single>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.Object, System.UnhandledExceptionEventArgs>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.Boolean>();
        appdomain.DelegateManager.RegisterMethodDelegate <Boolean, GameObject>();
        appdomain.DelegateManager.RegisterMethodDelegate <Int32, Int32>();
        appdomain.DelegateManager.RegisterMethodDelegate <String>();
        appdomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>();
        appdomain.DelegateManager.RegisterMethodDelegate <GameObject>();
        appdomain.DelegateManager.RegisterMethodDelegate <UIBehaviour, Object>();
        appdomain.DelegateManager.RegisterMethodDelegate <Transform, Object>();
        appdomain.DelegateManager.RegisterMethodDelegate <GameObject>();
        appdomain.DelegateManager.RegisterMethodDelegate <Int32>();
        appdomain.DelegateManager.RegisterMethodDelegate <GameObject, Action>();
        appdomain.DelegateManager.RegisterFunctionDelegate <Object, Boolean>();
        appdomain.DelegateManager.RegisterFunctionDelegate <Boolean>();
        appdomain.DelegateManager.RegisterFunctionDelegate <float>();
        appdomain.DelegateManager.RegisterFunctionDelegate <System.Threading.Tasks.Task>();

        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <System.String> >((act) =>
        {
            return(new UnityEngine.Events.UnityAction <System.String>((arg0) =>
            {
                ((Action <System.String>)act)(arg0);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <System.Boolean> >((act) =>
        {
            return(new UnityEngine.Events.UnityAction <System.Boolean>((arg0) =>
            {
                ((Action <System.Boolean>)act)(arg0);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <System.Threading.WaitCallback>((act) =>
        {
            return(new System.Threading.WaitCallback((state) =>
            {
                ((Action <System.Object>)act)(state);
            }));
        });

        appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction>(act =>
        {
            return(new UnityAction(() => { ((Action)act)(); }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <Single> >(act =>
        {
            return(new UnityAction <Single>(arg0 =>
            {
                ((Action <Single>)act)(arg0);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <System.UnhandledExceptionEventHandler>((act) =>
        {
            return(new System.UnhandledExceptionEventHandler((sender, e) =>
            {
                ((Action <System.Object, System.UnhandledExceptionEventArgs>)act)(sender, e);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <Predicate <Object> >(act =>
        {
            return(new Predicate <Object>(obj =>
            {
                return ((Func <Object, Boolean>)act)(obj);
            }));
        });
        appdomain.DelegateManager
        .RegisterDelegateConvertor <Predicate <ILTypeInstance> >(act =>
        {
            return(new Predicate <ILTypeInstance>(obj =>
            {
                return ((Func <ILTypeInstance, Boolean>)act)(obj);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <Int32> >(act =>
        {
            return(new UnityAction <Int32>(arg0 =>
            {
                ((Action <Int32>)act)(arg0);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <Action <JsonData> >(action =>
        {
            return(new Action <JsonData>(a => { ((Action <JsonData>)action)(a); }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction>(act =>
        {
            return(new UnityAction(async() => { ((Action)act)(); }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <ThreadStart>(act =>
        {
            return(new ThreadStart(() => { ((Action)act)(); }));
        });


        //添加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.PType.RegisterFunctionCreateInstance(PType_CreateInstance);
        ProtoBuf.PType.RegisterFunctionGetRealType(PType_GetRealType);
        JsonMapper.RegisterILRuntimeCLRRedirection(appdomain); //绑定LitJson
        CLRBindings.Initialize(appdomain);                     //CLR绑定

        #endregion
    }
Exemplo n.º 27
0
        public static unsafe void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appDomain)
        {
            // 注册重定向函数

            // 注册委托
            appDomain.DelegateManager.RegisterMethodDelegate <List <object> >();
            appDomain.DelegateManager.RegisterMethodDelegate <byte[], int, int>();
            appDomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>();
            appDomain.DelegateManager.RegisterMethodDelegate <Quick.UI.Tab>();
            appDomain.DelegateManager.RegisterMethodDelegate <BestHTTP.HTTPRequest, BestHTTP.HTTPResponse>();
            appDomain.DelegateManager.RegisterMethodDelegate <BestHTTP.WebSocket.WebSocket>();
            appDomain.DelegateManager.RegisterMethodDelegate <BestHTTP.WebSocket.WebSocket, System.String>();
            appDomain.DelegateManager.RegisterMethodDelegate <BestHTTP.WebSocket.WebSocket, System.UInt16, System.String>();
            appDomain.DelegateManager.RegisterMethodDelegate <BestHTTP.WebSocket.WebSocket, System.Exception>();
            appDomain.DelegateManager.RegisterMethodDelegate <BestHTTP.WebSocket.WebSocket, System.Byte[]>();


            appDomain.DelegateManager.RegisterFunctionDelegate <System.Boolean>();
            appDomain.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Boolean>();
            appDomain.DelegateManager.RegisterFunctionDelegate <ILTypeInstance, System.Int64>();

            appDomain.DelegateManager.RegisterDelegateConvertor <BestHTTP.WebSocket.OnWebSocketOpenDelegate>((act) =>
            {
                return(new BestHTTP.WebSocket.OnWebSocketOpenDelegate((webSocket) =>
                {
                    ((Action <BestHTTP.WebSocket.WebSocket>)act)(webSocket);
                }));
            });

            appDomain.DelegateManager.RegisterDelegateConvertor <BestHTTP.WebSocket.OnWebSocketMessageDelegate>((act) =>
            {
                return(new BestHTTP.WebSocket.OnWebSocketMessageDelegate((webSocket, message) =>
                {
                    ((Action <BestHTTP.WebSocket.WebSocket, string>)act)(webSocket, message);
                }));
            });

            appDomain.DelegateManager.RegisterDelegateConvertor <BestHTTP.WebSocket.OnWebSocketBinaryDelegate>((act) =>
            {
                return(new BestHTTP.WebSocket.OnWebSocketBinaryDelegate((webSocket, data) =>
                {
                    ((Action <BestHTTP.WebSocket.WebSocket, byte[]>)act)(webSocket, data);
                }));
            });

            appDomain.DelegateManager.RegisterDelegateConvertor <BestHTTP.WebSocket.OnWebSocketClosedDelegate>((act) =>
            {
                return(new BestHTTP.WebSocket.OnWebSocketClosedDelegate((webSocket, code, message) =>
                {
                    ((Action <BestHTTP.WebSocket.WebSocket, UInt16, string>)act)(webSocket, code, message);
                }));
            });

            appDomain.DelegateManager.RegisterDelegateConvertor <BestHTTP.WebSocket.OnWebSocketErrorDelegate>((act) =>
            {
                return(new BestHTTP.WebSocket.OnWebSocketErrorDelegate((webSocket, ex) =>
                {
                    ((Action <BestHTTP.WebSocket.WebSocket, System.Exception>)act)(webSocket, ex);
                }));
            });

            appDomain.DelegateManager.RegisterDelegateConvertor <BestHTTP.WebSocket.OnWebSocketErrorDescriptionDelegate>((act) =>
            {
                return(new BestHTTP.WebSocket.OnWebSocketErrorDescriptionDelegate((webSocket, reason) =>
                {
                    ((Action <BestHTTP.WebSocket.WebSocket, string>)act)(webSocket, reason);
                }));
            });



            appDomain.DelegateManager.RegisterDelegateConvertor <System.Predicate <System.Int32> >((act) =>
            {
                return(new System.Predicate <System.Int32>((obj) =>
                {
                    return ((Func <System.Int32, System.Boolean>)act)(obj);
                }));
            });

            appDomain.DelegateManager.RegisterDelegateConvertor <BestHTTP.OnRequestFinishedDelegate>((act) =>
            {
                return(new BestHTTP.OnRequestFinishedDelegate((originalRequest, response) =>
                {
                    ((Action <BestHTTP.HTTPRequest, BestHTTP.HTTPResponse>)act)(originalRequest, response);
                }));
            });
            appDomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction>((act) =>
            {
                return(new UnityEngine.Events.UnityAction(() =>
                {
                    //((Action<>)act)();
                    ((System.Action)act)();
                }));
            });
            appDomain.DelegateManager.RegisterDelegateConvertor <DG.Tweening.TweenCallback>((act) =>
            {
                return(new DG.Tweening.TweenCallback(() =>
                {
                    ((System.Action)act)();
                }));
            });

            appDomain.DelegateManager.RegisterMethodDelegate <Quick.UI.Tab, UnityEngine.EventSystems.PointerEventData>();
            appDomain.DelegateManager.RegisterDelegateConvertor <Quick.UI.Tab.PointerTabFunc>((act) =>
            {
                return(new Quick.UI.Tab.PointerTabFunc((target, eventData) =>
                {
                    ((Action <Quick.UI.Tab, UnityEngine.EventSystems.PointerEventData>)act)(target, eventData);
                }));
            });
            appDomain.DelegateManager.RegisterFunctionDelegate <System.IO.FileInfo, System.IO.FileInfo, System.Int32>();
            appDomain.DelegateManager.RegisterMethodDelegate <System.String>();
            appDomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <System.String> >((act) =>
            {
                return(new UnityEngine.Events.UnityAction <System.String>((arg0) =>
                {
                    ((Action <System.String>)act)(arg0);
                }));
            });


            appDomain.DelegateManager.RegisterMethodDelegate <System.Boolean>();
            appDomain.DelegateManager.RegisterMethodDelegate <Quick.UI.TabGroup, UnityEngine.EventSystems.PointerEventData>();
            appDomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject>();
            appDomain.DelegateManager.RegisterMethodDelegate <System.Int32>();
            appDomain.DelegateManager.RegisterFunctionDelegate <System.Int32>();
            appDomain.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Int32, System.Int32>();
            appDomain.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Boolean>();
            appDomain.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);
                }));
            });
            appDomain.DelegateManager.RegisterDelegateConvertor <System.Predicate <System.Int64> >((act) =>
            {
                return(new System.Predicate <System.Int64>((obj) =>
                {
                    return ((Func <System.Int64, System.Boolean>)act)(obj);
                }));
            });
            appDomain.DelegateManager.RegisterFunctionDelegate <System.Int64, System.Boolean>();

            appDomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Video.VideoPlayer>();
            appDomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Video.VideoPlayer.EventHandler>((act) =>
            {
                return(new UnityEngine.Video.VideoPlayer.EventHandler((source) =>
                {
                    ((Action <UnityEngine.Video.VideoPlayer>)act)(source);
                }));
            });
            appDomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Vector2>();
            appDomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <UnityEngine.Vector2> >((act) =>
            {
                return(new UnityEngine.Events.UnityAction <UnityEngine.Vector2>((arg0) =>
                {
                    ((Action <UnityEngine.Vector2>)act)(arg0);
                }));
            });
            appDomain.DelegateManager.RegisterMethodDelegate <System.Single>();



            appDomain.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance, ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int32>();
            appDomain.DelegateManager.RegisterDelegateConvertor <System.Comparison <ILRuntime.Runtime.Intepreter.ILTypeInstance> >((act) =>
            {
                return(new System.Comparison <ILRuntime.Runtime.Intepreter.ILTypeInstance>((x, y) =>
                {
                    return ((Func <ILRuntime.Runtime.Intepreter.ILTypeInstance, ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int32>)act)(x, y);
                }));
            });

            appDomain.DelegateManager.RegisterDelegateConvertor <System.Comparison <System.IO.FileInfo> >((act) =>
            {
                return(new System.Comparison <System.IO.FileInfo>((x, y) =>
                {
                    return ((Func <System.IO.FileInfo, System.IO.FileInfo, System.Int32>)act)(x, y);
                }));
            });


            appDomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <System.Boolean> >((act) =>
            {
                return(new UnityEngine.Events.UnityAction <System.Boolean>((arg0) =>
                {
                    ((Action <System.Boolean>)act)(arg0);
                }));
            });
            appDomain.DelegateManager.RegisterDelegateConvertor <System.Predicate <System.Int64> >((act) =>
            {
                return(new System.Predicate <System.Int64>((obj) =>
                {
                    return ((Func <System.Int64, System.Boolean>)act)(obj);
                }));
            });

            appDomain.DelegateManager.RegisterDelegateConvertor <System.Comparison <System.Int32> >((act) =>
            {
                return(new System.Comparison <System.Int32>((x, y) =>
                {
                    return ((Func <System.Int32, System.Int32, System.Int32>)act)(x, y);
                }));
            });



            appDomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <System.Int32> >((act) =>
            {
                return(new UnityEngine.Events.UnityAction <System.Int32>((arg0) =>
                {
                    ((Action <System.Int32>)act)(arg0);
                }));
            });

            appDomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <System.Single> >((act) =>
            {
                return(new UnityEngine.Events.UnityAction <System.Single>((arg0) =>
                {
                    ((Action <System.Single>)act)(arg0);
                }));
            });
            appDomain.DelegateManager.RegisterDelegateConvertor <System.Converter <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int64> >((act) =>
            {
                return(new System.Converter <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int64>((input) =>
                {
                    return ((Func <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int64>)act)(input);
                }));
            });
            appDomain.DelegateManager.RegisterMethodDelegate <System.Int64>();
            appDomain.DelegateManager.RegisterMethodDelegate <ETModel.AEvent>();

            appDomain.DelegateManager.RegisterMethodDelegate <System.String, System.String>();
            appDomain.DelegateManager.RegisterMethodDelegate <UnityEngine.UI.Text>();



            CLRBindings.Initialize(appDomain);

            // 注册适配器
            Assembly assembly = typeof(Init).Assembly;

            foreach (Type type in assembly.GetTypes())
            {
                object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj = Activator.CreateInstance(type);
                CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
                if (adaptor == null)
                {
                    continue;
                }
                appDomain.RegisterCrossBindingAdaptor(adaptor);
            }
            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appDomain);
            //ILSerial.RegisterILRuntimeCLRRedirection(appDomain);
        }
Exemplo n.º 28
0
        public static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
        {
            // 注册重定向函数

            // 注册委托
            appdomain.DelegateManager.RegisterMethodDelegate <List <object> >();
            appdomain.DelegateManager.RegisterMethodDelegate <AChannel, System.Net.Sockets.SocketError>();
            appdomain.DelegateManager.RegisterMethodDelegate <byte[], int, int>();
            appdomain.DelegateManager.RegisterMethodDelegate <IResponse>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session, object>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session, ushort, MemoryStream>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session>();
            appdomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>();
            appdomain.DelegateManager.RegisterFunctionDelegate <Google.Protobuf.Adapt_IMessage.Adaptor>();
            appdomain.DelegateManager.RegisterMethodDelegate <Google.Protobuf.Adapt_IMessage.Adaptor>();
            appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject>();
            appdomain.DelegateManager.RegisterMethodDelegate <float>();
            appdomain.DelegateManager.RegisterDelegateConvertor <global::EventTriggerListener.VoidDelegate>((act) =>
            {
                return(new global::EventTriggerListener.VoidDelegate((go) =>
                {
                    ((Action <UnityEngine.GameObject>)act)(go);
                }));
            });
            appdomain.DelegateManager.RegisterMethodDelegate <System.Single>();
            appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <System.Single> >((act) =>
            {
                return(new UnityEngine.Events.UnityAction <System.Single>((arg0) =>
                {
                    ((Action <System.Single>)act)(arg0);
                }));
            });
            #region adapter
            //TODO:Osmin 添加Unity的委托事件
            appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction>((action) =>
            {
                return(new UnityEngine.Events.UnityAction(() =>
                {
                    ((System.Action)action)();
                }));
            });
            appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.EventSystems.EventTrigger.Entry>();
            appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.EventSystems.BaseEventData>();
            appdomain.DelegateManager.RegisterMethodDelegate <System.Object, ILRuntime.Runtime.Intepreter.ILTypeInstance>();
            appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Events.UnityAction <UnityEngine.EventSystems.BaseEventData> >();
            appdomain.DelegateManager.RegisterMethodDelegate <System.Action <UnityEngine.EventSystems.BaseEventData> >();
            appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <UnityEngine.EventSystems.BaseEventData> >((action) =>
            {
                return(new UnityEngine.Events.UnityAction <UnityEngine.EventSystems.BaseEventData>((a) =>
                {
                    ((System.Action <UnityEngine.EventSystems.BaseEventData>)action)(a);
                }));
            });

            //appdomain.DelegateManager.RegisterDelegateConvertor<System.Action<UnityEngine.EventSystems.BaseEventData>>((action) =>
            //{
            //    return new System.Action<UnityEngine.EventSystems.BaseEventData>((a) =>
            //    {
            //        ((System.Action<UnityEngine.EventSystems.BaseEventData>)action)(a);
            //    });
            //});

            appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Transform>();
            appdomain.DelegateManager.RegisterMethodDelegate <System.String>();
            appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <System.String> >((act) =>
            {
                return(new UnityEngine.Events.UnityAction <System.String>((arg0) =>
                {
                    ((Action <System.String>)act)(arg0);
                }));
            });

            appdomain.DelegateManager.RegisterMethodDelegate <System.Int32>();
            appdomain.DelegateManager.RegisterFunctionDelegate <System.String, System.Int32, System.Char, System.Char>();
            appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.UI.InputField.OnValidateInput>((act) =>
            {
                return(new UnityEngine.UI.InputField.OnValidateInput((text, charIndex, addedChar) =>
                {
                    return ((Func <System.String, System.Int32, System.Char, System.Char>)act)(text, charIndex, addedChar);
                }));
            });



            #endregion

            CLRBindings.Initialize(appdomain);

            // 注册适配器
            Assembly assembly = typeof(Init).Assembly;
            foreach (Type type in assembly.GetTypes())
            {
                object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj = Activator.CreateInstance(type);
                CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
                if (adaptor == null)
                {
                    continue;
                }
                appdomain.RegisterCrossBindingAdaptor(adaptor);
            }
            appdomain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter());

            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
        }
Exemplo n.º 29
0
        private void ILHotfixInitialize()
        {
            CLRBindings.Initialize(_appDomain);

            _appDomain.RegisterCrossBindingAdaptor(new ILHotfixProcedureAdapter());
        }
Exemplo n.º 30
0
        public static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
        {
            // 注册重定向函数

            // 注册委托
            appdomain.DelegateManager.RegisterMethodDelegate <List <object> >();
            appdomain.DelegateManager.RegisterMethodDelegate <AChannel, System.Net.Sockets.SocketError>();
            appdomain.DelegateManager.RegisterMethodDelegate <byte[], int, int>();
            appdomain.DelegateManager.RegisterMethodDelegate <IResponse>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session, object>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session, ushort, MemoryStream>();
            appdomain.DelegateManager.RegisterMethodDelegate <Session>();
            appdomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>();
            appdomain.DelegateManager.RegisterFunctionDelegate <Google.Protobuf.Adapt_IMessage.Adaptor>();
            appdomain.DelegateManager.RegisterMethodDelegate <Google.Protobuf.Adapt_IMessage.Adaptor>();
            appdomain.DelegateManager.RegisterMethodDelegate <System.String>();
            appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject>();
            appdomain.DelegateManager.RegisterDelegateConvertor <global::UIEventListener.VoidDelegate>((act) =>
            {
                return(new global::UIEventListener.VoidDelegate((go) =>
                {
                    ((Action <UnityEngine.GameObject>)act)(go);
                }));
            });

            appdomain.DelegateManager.RegisterMethodDelegate <System.Int32>();
            appdomain.DelegateManager.RegisterDelegateConvertor <DG.Tweening.TweenCallback>((act) =>
            {
                return(new DG.Tweening.TweenCallback(() =>
                {
                    ((Action)act)();
                }));
            });
            appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <System.Int32> >((act) =>
            {
                return(new UnityEngine.Events.UnityAction <System.Int32>((arg0) =>
                {
                    ((Action <System.Int32>)act)(arg0);
                }));
            });
            appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject, System.Int32>();
            appdomain.DelegateManager.RegisterDelegateConvertor <global::UIEventListener.IntDelegate>((act) =>
            {
                return(new global::UIEventListener.IntDelegate((go, index) =>
                {
                    ((Action <UnityEngine.GameObject, System.Int32>)act)(go, index);
                }));
            });

            CLRBindings.Initialize(appdomain);

            // 注册适配器
            Assembly assembly = typeof(Init).Assembly;

            foreach (Type type in assembly.GetTypes())
            {
                object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj = Activator.CreateInstance(type);
                CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
                if (adaptor == null)
                {
                    continue;
                }
                appdomain.RegisterCrossBindingAdaptor(adaptor);
            }

            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
        }