コード例 #1
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);
        }
コード例 #2
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!!!");
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public static void LoadHotfix(string root)
        {
            if (AppDomain != null)
            {
                //AppDomain.FreeILIntepreter(AppDomain.);
            }

            //
            IsRunning = true;
            string dllPath = root + "/" + Utils.GetPlatformPath(Application.platform) + "/hotfix/hotfix.dll";
            string pdbPath = root + "/" + Utils.GetPlatformPath(Application.platform) + "/hotfix/hotfix.pdb";

            BDebug.Log("DLL加载路径:" + dllPath, "red");
            //
            AppDomain = new AppDomain();
            if (File.Exists(pdbPath))
            {
                var dllfs = File.ReadAllBytes(dllPath);
                var pdbfs = File.ReadAllBytes(pdbPath);
                using (MemoryStream dll = new MemoryStream(dllfs))
                {
                    using (MemoryStream pdb = new MemoryStream(pdbfs))
                    {
                        AppDomain.LoadAssembly(dll, pdb, new PdbReaderProvider());
                    }
                }
            }
            else
            {
                UnityWebRequest request;
                using (System.IO.FileStream fs = new System.IO.FileStream(dllPath, FileMode.Open, FileAccess.Read))
                {
                    AppDomain.LoadAssembly(fs);
                }
            }


            //绑定的初始化
            AdapterRegister.RegisterCrossBindingAdaptor(AppDomain);
            ILRuntime.Runtime.Generated.CLRBindings.Initialize(AppDomain);
            ILRuntime.Runtime.Generated.CLRManualBindings.Initialize(AppDomain);
//          ILRuntime.Runtime.Generated.PreCLRBuilding.Initialize(AppDomain);
            //
            ILRuntimeDelegateHelper.Register(AppDomain);
            JsonMapper.RegisterILRuntimeCLRRedirection(AppDomain);
            if (Application.isEditor)
            {
                AppDomain.DebugService.StartDebugService(56000);
                Debug.Log("热更调试器 准备待命~");
            }
            //
            AppDomain.Invoke("HotfixCheck", "Log", null, null);
        }
コード例 #5
0
        public static void LoadHotfix(bool isLoadPdb)
        {
            string dllPath = "hotfix/hotfix.dll";
            string pdbPath = "hotfix/hotfix.pdb";

            IsRunning = true;
          #if UNITY_EDITOR
            dllPath = Path.Combine(Application.streamingAssetsPath, dllPath);
            pdbPath = Path.Combine(Application.streamingAssetsPath, pdbPath);
          #elif UNITY_IPHONE || UNITY_ANDROID
            dllPath = Path.Combine(Application.persistentDataPath, dllPath);
            pdbPath = Path.Combine(Application.persistentDataPath, pdbPath);
          #endif



            AppDomain = new AppDomain();
            if (isLoadPdb)
            {
                var dllfs = File.ReadAllBytes(dllPath);
                var pdbfs = File.ReadAllBytes(pdbPath);
                using (MemoryStream dll = new MemoryStream(dllfs))
                {
                    using (MemoryStream pdb = new MemoryStream(pdbfs))
                    {
                        AppDomain.LoadAssembly(dll, pdb, new PdbReaderProvider());
                    }
                }
            }
            else
            {
                using (System.IO.FileStream fs = new System.IO.FileStream(dllPath, FileMode.Open, FileAccess.Read))
                {
                    AppDomain.LoadAssembly(fs);
                }
            }


            //绑定的初始化
            AdapterRegister.RegisterCrossBindingAdaptor(AppDomain);
            ILRuntime.Runtime.Generated.CLRBindings.Initialize(AppDomain);
            ILRuntime.Runtime.Generated.CLRManualBindings.Initialize(AppDomain);
            //
            ILRuntimeDelegateHelper.Register(AppDomain);
            JsonMapper.RegisterILRuntimeCLRRedirection(AppDomain);
            if (Application.isEditor)
            {
                AppDomain.DebugService.StartDebugService(56000);
                Debug.Log("热更调试器 准备待命~");
            }
            //
            AppDomain.Invoke("HotfixCheck", "Log", null, null);
        }
コード例 #6
0
        public static void LoadHotfix(string root, bool isRegisterBindings = true)
        {
            //
            IsRunning = true;
            string dllPath = root + "/" + Utils.GetPlatformPath(Application.platform) + "/hotfix/hotfix.dll";
            string pdbPath = root + "/" + Utils.GetPlatformPath(Application.platform) + "/hotfix/hotfix.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);
            }



            //绑定的初始化
            AdapterRegister.RegisterCrossBindingAdaptor(AppDomain);
            ILRuntimeDelegateHelper.Register(AppDomain);
            //是否注册各种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);
        }