Beispiel #1
0
        /// <summary>
        /// 将lua数据释放到可读写目录
        /// </summary>
        /// <returns></returns>
        IEnumerator OnExtractResource()
        {
            string dataPath = Util.DataPath;         //数据目录
            string resPath  = Util.AppContentPath(); //游戏包资源目录

            if (Directory.Exists(dataPath))
            {
                Directory.Delete(dataPath, true);
            }
            Directory.CreateDirectory(dataPath);

            string infile  = resPath + "files.txt";
            string outfile = dataPath + "files.txt";

            if (File.Exists(outfile))
            {
                File.Delete(outfile);
            }

            string message = "正在解包文件:>files.txt";

            Debug.Log(infile);
            Debug.Log(outfile);
            PreInit.ReleaseLuaRes();
            if (Application.platform == RuntimePlatform.Android)
            {
                WWW www = new WWW(infile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outfile, www.bytes);
                }
                yield return(0);
            }
            else
            {
                File.Copy(infile, outfile, true);
            }
            yield return(new WaitForEndOfFrame());

            //释放所有文件到数据目录
            string[] files = File.ReadAllLines(outfile);
            foreach (var file in files)
            {
                string[] fs = file.Split('|');
                infile  = resPath + fs[0]; //
                outfile = dataPath + fs[0];

                message = "正在解包文件:>" + fs[0];
                Debug.Log("正在解包文件:>" + infile);
                facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);

                string dir = Path.GetDirectoryName(outfile);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                if (Application.platform == RuntimePlatform.Android)
                {
                    WWW www = new WWW(infile);
                    yield return(www);

                    if (www.isDone)
                    {
                        File.WriteAllBytes(outfile, www.bytes);
                    }
                    yield return(0);
                }
                else
                {
                    if (File.Exists(outfile))
                    {
                        File.Delete(outfile);
                    }
                    File.Copy(infile, outfile, true);
                }
                yield return(new WaitForEndOfFrame());
            }


            string resInFile  = resPath + "resIndex.txt";
            string resOutFile = dataPath + "resIndex.txt";

            PreInit.ReleaseGameRes();
            if (File.Exists(resOutFile))
            {
                File.Delete(resOutFile);
            }
            if (Application.platform == RuntimePlatform.Android)
            {
                WWW www = new WWW(resInFile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(resOutFile, www.bytes);
                }
                yield return(0);
            }
            else
            {
                File.Copy(resInFile, resOutFile, true);
            }

            string inApkInfo  = resPath + "versionInfo.xml";
            string outApkInfo = dataPath + "versionInfo.xml";

            if (File.Exists(outApkInfo))
            {
                File.Delete(outApkInfo);
            }
            if (Application.platform == RuntimePlatform.Android)
            {
                WWW www = new WWW(inApkInfo);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outApkInfo, www.bytes);
                }
                yield return(0);
            }
            else
            {
                File.Copy(inApkInfo, outApkInfo, true);
            }

            //释放所有文件到数据目录
            string[] resFiles = File.ReadAllLines(resOutFile);
            foreach (var file in resFiles)
            {
                string[] fs = file.Split('|');
                resInFile  = resPath + "Android/" + fs[0]; //
                resOutFile = dataPath + "Android/" + fs[0];

                message = "正在解包文件:>" + fs[0];
                Debug.Log("正在解包文件:>" + resInFile);
                facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);
                string tarDir = Path.GetDirectoryName(resOutFile);
                if (!Directory.Exists(tarDir))
                {
                    Directory.CreateDirectory(tarDir);
                }

                if (Application.platform == RuntimePlatform.Android)
                {
                    WWW www = new WWW(resInFile);
                    yield return(www);

                    if (www.isDone)
                    {
                        File.WriteAllBytes(resOutFile, www.bytes);
                    }
                    yield return(0);
                }
                else
                {
                    if (File.Exists(resOutFile))
                    {
                        File.Delete(resOutFile);
                    }
                    File.Copy(resInFile, resOutFile, true);
                }
                yield return(new WaitForEndOfFrame());
            }

            yield return(new WaitForEndOfFrame());


            message = "解包完成!!!";
            facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);
            yield return(new WaitForSeconds(0.1f));

            message = string.Empty;
            PreInit.ExtResFinish();
            //释放完成,开始启动更新资源
            StartCoroutine(OnUpdateLuaResource());
        }