예제 #1
0
        void OnApplicationQuit()
        {
#if UNITY_EDITOR
            SqliteLoder.Close();
            ILRuntimeHelper.Close();
#endif
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        /// <param name="copyto"></param>
        /// <returns></returns>
        static IEnumerator IE_CopyDLL_WhithLaunch(string source, string copyto)
        {
//            if (Application.isEditor)
//            {
//                source = "file://" + source;
//            }

            BDebug.Log("复制到第一路径:" + source);

            var www = new WWW(source);

            yield return(www);

            if (www.isDone && www.error == null)
            {
                FileHelper.WriteAllBytes(copyto, www.bytes);

                //解释执行模式
                ILRuntimeHelper.LoadHotfix(copyto);
                ILRuntimeHelper.AppDomain.Invoke("BDLauncherBridge", "Start", null, new object[] { true, false });
            }
            else
            {
                Debug.LogError("可寻址目录不包括DLL:" + source);
            }
        }
예제 #3
0
        //
        /// <summary>
        /// 游戏逻辑的Assembly
        /// </summary>
        //        public static  Assembly GameAssembly { get; private set; }
        /// <summary>
        /// 开始热更脚本逻辑
        /// </summary>
        private void LoadScrpit(string root)
        {
            if (root != "") //热更代码模式
            {
                if (Config.CodeRunMode == HotfixCodeRunMode.ByILRuntime)
                {
                    //解释执行模式
                    ILRuntimeHelper.LoadHotfix(root);
                    ILRuntimeHelper.AppDomain.Invoke("BDLauncherBridge", "Start", null, new object[] { true });
                }
                else
                {
                    //
                    //反射模式
                    string dllPath = root + "/" + Utils.GetPlatformPath(Application.platform) + "/hotfix/hotfix.dll";

                    IEnumeratorTool.StartCoroutine(this.IE_LoadScript(dllPath));
                }
            }
            else
            {
                //PC 模式非热更

                //这里用反射是为了 不访问逻辑模块的具体类,防止编译失败
                var assembly = Assembly.GetExecutingAssembly();
                //
                var type   = assembly.GetType("BDLauncherBridge");
                var method = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);
                method.Invoke(null, new object[] { false });
            }
        }
예제 #4
0
        void OnApplicationQuit()
        {
#if UNITY_EDITOR
            BDFramework.Sql.SqliteHelper.DB.Close();
            ILRuntimeHelper.Close();
#endif
        }
예제 #5
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="source"></param>
        /// <param name="copyto"></param>
        /// <returns></returns>
        static IEnumerator IE_LoadScript(string root, HotfixCodeRunMode mode)
        {
            string dllPath = "";

            if (Application.isEditor)
            {
                dllPath = root + "/" + BDUtils.GetPlatformPath(Application.platform) + "/hotfix/hotfix.dll";
            }
            else
            {
                //这里情况比较复杂,Mobile上基本认为Persistent才支持File操作,
                //可寻址目录也只有 StreamingAsset
                var firstPath = Application.persistentDataPath + "/" + BDUtils.GetPlatformPath(Application.platform) +
                                "/hotfix/hotfix.dll";
                var secondPath = Application.streamingAssetsPath + "/" + BDUtils.GetPlatformPath(Application.platform) +
                                 "/hotfix/hotfix.dll";
                if (!File.Exists(firstPath))
                {
                    var www = new WWW(secondPath);
                    yield return(www);

                    if (www.isDone && www.error == null)
                    {
                        FileHelper.WriteAllBytes(firstPath, www.bytes);
                    }
                }
                dllPath = firstPath;
            }

            //反射执行
            if (mode == HotfixCodeRunMode.ByReflection)
            {
                var bytes = File.ReadAllBytes(dllPath);
                var mdb   = dllPath + ".mdb";
                if (File.Exists(mdb))
                {
                    var bytes2 = File.ReadAllBytes(mdb);
                    Assembly = Assembly.Load(bytes, bytes2);
                }
                else
                {
                    Assembly = Assembly.Load(bytes);
                }
                var type   = Assembly.GetType("BDLauncherBridge");
                var method = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);
                method.Invoke(null, new object[] { false, true });
            }
            //解释执行
            else if (mode == HotfixCodeRunMode.ByILRuntime)
            {
                //解释执行模式
                ILRuntimeHelper.LoadHotfix(dllPath);
                ILRuntimeHelper.AppDomain.Invoke("BDLauncherBridge", "Start", null, new object[] { true, false });
            }
        }
예제 #6
0
        void OnApplicationQuit()
        {
#if UNITY_EDITOR
            if (SqliteHelper.DB != null)
            {
                SqliteHelper.DB.Close();
            }

            ILRuntimeHelper.Close();
#endif
        }
예제 #7
0
 /// <summary>
 /// 开始热更脚本逻辑
 /// </summary>
 private void LaunchScrpit()
 {
     if (IsCodeHotfix) //热更代码模式
     {
         ILRuntimeHelper.LoadHotfix(IsLoadPdb);
         ILRuntimeHelper.AppDomain.Invoke("BDLauncherBridge", "Start", null, new object[] { IsCodeHotfix, IsAssetbundleModel });
     }
     else
     {
         //这里用反射是为了 不访问逻辑模块的具体类,防止编译失败
         var assembly = Assembly.GetExecutingAssembly();
         var type     = assembly.GetType("BDLauncherBridge");
         var method   = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);
         method.Invoke(null, new object[] { IsCodeHotfix, IsAssetbundleModel });
     }
 }
예제 #8
0
 /// <summary>
 /// 开始热更脚本逻辑
 /// </summary>
 private void LoadScrpit(string root)
 {
     if (root != "") //热更代码模式
     {
         ILRuntimeHelper.LoadHotfix(root);
         ILRuntimeHelper.AppDomain.Invoke("BDLauncherBridge", "Start", null,
                                          new object[] { true });
     }
     else
     {
         //这里用反射是为了 不访问逻辑模块的具体类,防止编译失败
         var assembly = Assembly.GetExecutingAssembly();
         var type     = assembly.GetType("BDLauncherBridge");
         var method   = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);
         method.Invoke(null, new object[] { false });
     }
 }
예제 #9
0
 /// <summary>
 /// 加载
 /// </summary>
 /// <param name="source"></param>
 /// <param name="copyto"></param>
 /// <returns></returns>
 static void LoadHotfixDLL(string dllPath, HotfixCodeRunMode mode, Type[] mainProjecTypes)
 {
     //反射执行
     if (mode == HotfixCodeRunMode.Huatuo)
     {
         new NotSupportedException("暂未实现");
         // BDebug.Log("【ScriptLaunch】反射Dll路径:" + dllPath, "red");
         // Assembly Assembly;
         // var dllBytes = File.ReadAllBytes(dllPath);
         // var pdbPath = dllPath + ".pdb";
         // if (File.Exists(pdbPath))
         // {
         //     var pdbBytes = File.ReadAllBytes(pdbPath);
         //     Assembly = Assembly.Load(dllBytes, pdbBytes);
         // }
         // else
         // {
         //     Assembly = Assembly.Load(dllBytes);
         // }
         //
         // BDebug.Log("【ScriptLaunch】反射加载成功,开始执行Start");
         // var type = typeof(ScriptLoder).Assembly.GetType("BDLauncherBridge");
         // var method = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);
         //
         // method.Invoke(null, new object[] {mainProjecTypes, Assembly.GetTypes()});
     }
     //解释执行
     else if (mode == HotfixCodeRunMode.ILRuntime)
     {
         BDebug.Log("【ScriptLaunch】热更Dll路径:" + dllPath, "red");
         //解释执行模式
         ILRuntimeHelper.LoadHotfix(dllPath, CLRBindAction);
         var hotfixTypes = ILRuntimeHelper.GetHotfixTypes().ToArray();
         ILRuntimeHelper.AppDomain.Invoke("BDLauncherBridge", "Start", null,
                                          new object[] { mainProjecTypes, hotfixTypes });
     }
     else
     {
         BDebug.Log("【ScriptLaunch】Dll路径:内置", "red");
     }
 }
예제 #10
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="source"></param>
        /// <param name="copyto"></param>
        /// <returns></returns>
        static void LoadHotfixDLL(string dllPath, HotfixCodeRunMode mode, Type[] mainProjecTypes)
        {
            //反射执行
            if (mode == HotfixCodeRunMode.ByReflection)
            {
                BDebug.Log("反射Dll路径:" + dllPath, "red");
                Assembly Assembly;
                var      dllBytes = File.ReadAllBytes(dllPath);
                var      pdbPath  = dllPath + ".pdb";
                if (File.Exists(pdbPath))
                {
                    var pdbBytes = File.ReadAllBytes(pdbPath);
                    Assembly = Assembly.Load(dllBytes, pdbBytes);
                }
                else
                {
                    Assembly = Assembly.Load(dllBytes);
                }

                BDebug.Log("反射加载成功,开始执行Start");
                var type   = typeof(ScriptLoder).Assembly.GetType("BDLauncherBridge");
                var method = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);

                method.Invoke(null, new object[] { mainProjecTypes, Assembly.GetTypes() });
            }
            //解释执行
            else if (mode == HotfixCodeRunMode.ByILRuntime)
            {
                BDebug.Log("热更Dll路径:" + dllPath, "red");
                //解释执行模式
                ILRuntimeHelper.LoadHotfix(dllPath, GamelogicILRBindAction);
                var hotfixTypes = ILRuntimeHelper.GetHotfixTypes().ToArray();
                ILRuntimeHelper.AppDomain.Invoke("BDLauncherBridge", "Start", null,
                                                 new object[] { mainProjecTypes, hotfixTypes });
            }
            else
            {
                BDebug.Log("Dll路径:内置", "red");
            }
        }
예제 #11
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="source"></param>
        /// <param name="copyto"></param>
        /// <returns></returns>
        static void LoadDLL(string dllPath, HotfixCodeRunMode mode)
        {
            //反射执行
            if (mode == HotfixCodeRunMode.ByReflection)
            {
                BDebug.Log("Dll路径:" + dllPath, "red");
                var dllBytes = File.ReadAllBytes(dllPath);
                var pdbPath  = dllPath + ".pdb";
                if (File.Exists(pdbPath))
                {
                    var pdbBytes = File.ReadAllBytes(pdbPath);
                    Assembly = Assembly.Load(dllBytes, pdbBytes);
                }
                else
                {
                    Assembly = Assembly.Load(dllBytes);
                }

                BDebug.Log("代码加载成功,开始执行Start");
                var type   = Assembly.GetType("BDLauncherBridge");
                var method = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);
                method.Invoke(null, new object[] { false, true });
            }
            //解释执行
            else if (mode == HotfixCodeRunMode.ByILRuntime)
            {
                BDebug.Log("Dll路径:" + dllPath, "red");
                //解释执行模式
                ILRuntimeHelper.LoadHotfix(dllPath);
                ILRuntimeHelper.AppDomain.Invoke("BDLauncherBridge", "Start", null, new object[] { true, false });
            }
            else
            {
                BDebug.Log("Dll路径:内置", "red");
            }
        }
예제 #12
0
        /// <summary>
        /// 开始热更脚本逻辑
        /// </summary>
        static public void Load(string root, HotfixCodeRunMode mode)
        {
            if (root != "")
            {
                string dllPath = root + "/" + BDUtils.GetPlatformPath(Application.platform) + "/hotfix/hotfix.dll";

                //反射
                if (mode == HotfixCodeRunMode.ByReflection &&
                    (Application.isEditor || Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.WindowsPlayer))
                {
                    //反射模式只支持Editor PC Android
                    if (File.Exists(dllPath)) //支持File操作 或者存在
                    {
                        var bytes    = File.ReadAllBytes(dllPath);
                        var bytes2   = File.ReadAllBytes(dllPath + ".mdb");
                        var assembly = Assembly.Load(bytes, bytes2);
                        var type     = assembly.GetType("BDLauncherBridge");
                        var method   = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);
                        method.Invoke(null, new object[] { false, true });
                    }
                    else
                    {
                        //不支持file操作 或者不存在,继续尝试
                        IEnumeratorTool.StartCoroutine(IE_LoadDLL_AndroidOrPC(dllPath));
                    }
                }
                //ILR
                else
                {
                    //
                    //ILRuntime基于文件流,所以不支持file操作的,得拷贝到支持File操作的目录

                    //这里情况比较复杂,Mobile上基本认为Persistent才支持File操作,
                    //可寻址目录也只有 StreamingAsset
                    var firstPath  = Application.persistentDataPath + "/" + BDUtils.GetPlatformPath(Application.platform) + "/hotfix/hotfix.dll";
                    var secondPath = Application.streamingAssetsPath + "/" + BDUtils.GetPlatformPath(Application.platform) + "/hotfix/hotfix.dll";

                    if (!File.Exists(dllPath)) //仅当指定的路径不存在(或者不支持File操作)时,再进行可寻址
                    {
                        dllPath = firstPath;
                        if (!File.Exists(firstPath))
                        {
                            //验证 可寻址目录2
                            IEnumeratorTool.StartCoroutine(IE_CopyDLL_WhithLaunch(secondPath, firstPath));
                            return;
                        }
                    }

                    //解释执行模式
                    ILRuntimeHelper.LoadHotfix(dllPath);
                    ILRuntimeHelper.AppDomain.Invoke("BDLauncherBridge", "Start", null, new object[] { true, false });
                }
            }
            else
            {
                //PC模式

                //这里用反射是为了 不访问逻辑模块的具体类,防止编译失败
                var assembly = Assembly.GetExecutingAssembly();
                //
                var type   = assembly.GetType("BDLauncherBridge");
                var method = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);
                method.Invoke(null, new object[] { false, false });
            }
        }