Exemplo n.º 1
0
        public static WWWLoader Load(string url, MonoBehaviour behaviour = null)
        {
            WWWLoader loader = GetLoader(url);

            CoroutineManager.Wait(loader.Wait, () => s_LoaderDict.Remove(url), behaviour);
            return(loader);
        }
Exemplo n.º 2
0
 private static WWWLoader GetLoader(string url)
 {
     if (!s_LoaderDict.ContainsKey(url))
     {
         Debugger.Log("Load: " + url);
         s_LoaderDict[url] = new WWWLoader(url);
     }
     return(s_LoaderDict[url]);
 }
Exemplo n.º 3
0
        public static WaitUntil Load(string url, Action <WWWLoader> callback, MonoBehaviour behaviour = null)
        {
            WWWLoader loader = GetLoader(url);

            CoroutineManager.Wait(loader.Wait, () =>
            {
                if (callback != null)
                {
                    callback(loader);
                }
                s_LoaderDict.Remove(url);
            }, behaviour);
            return(loader.Wait);
        }
Exemplo n.º 4
0
        private IEnumerator DoVersionUpdate(Action callback)
        {
            // 对比文件
            m_UpdateStepType = UpdateStepType.FileCompare;

            string[] streamingVersions = ConstValue.VERSION.Split('.');
            string   cdnCurVerUrl      = ConstValue.CDN_URL + "/" + ConstValue.GAME_NAME + "/" + ConstValue.BUNDLE_DIR + "/" + streamingVersions[0] + "." + streamingVersions[1];

            // 下载并解析CDN上的文件列表和Manifest
            WWWLoader cdnFileListLoader = WWWManager.Load(cdnCurVerUrl + "/" + m_ModuleName + "/" + ConstValue.FILE_LIST_NAME, this);

            yield return(cdnFileListLoader.Wait);

            m_CdnFileList = StringParser.StringToJo(cdnFileListLoader.Text, false);

            // 统计需要下载的和需要删除的
            CountFiles();

            // 下载
            if (m_UpdateIndex > 1)
            {
                LuaTable UIManager       = LuaMain.LuaEnv.Global.GetInPath <LuaTable>("LuaClass.UIManager.Instance");
                LuaTable moduleTypeClass = LuaMain.LuaEnv.Global.GetInPath <LuaTable>("LuaClass.ModuleType");
                m_LoadingUI = LuaMain.Instance.FuncInvoke(UIManager, "Open", UIManager, moduleTypeClass.Get <object>("Common"), "LoadingUI") as LuaTable;
            }
            m_UpdateStepType = UpdateStepType.FileDownload;
            for (m_Index = 0; m_Index < UpdateFileNameList.Count; m_Index++)
            {
                string fileName = UpdateFileNameList[m_Index];
                m_CurrentLoader = WWWManager.Load(cdnCurVerUrl + "/" + fileName, this);
                yield return(m_CurrentLoader.Wait);

                if (m_CurrentLoader.Error != null)
                {
                    // 下载失败,需要重新更新
                    Debugger.Log("Update failed by: " + m_CurrentLoader.Error);
                    m_UpdateStepType = UpdateStepType.UpdateFailed;
                    OnUpdateFaild(fileName, m_CurrentLoader.Error);
                    yield break;
                }

                byte[] bytes = m_CurrentLoader.Bytes;
                if (bytes != null)
                {
                    FileManager.Write(ConstValue.PERSISTENT_DIR_PATH + "/" + fileName, bytes);
                }
            }

            // 删除
            m_UpdateStepType = UpdateStepType.FileDelete;
            for (m_Index = 0; m_Index < DeleteFileNameList.Count; m_Index++)
            {
                string fileName = DeleteFileNameList[m_Index];
                FileManager.Delete(ConstValue.PERSISTENT_DIR_PATH + "/" + fileName);
                yield return(null);
            }

            // 将CDN上的Version文件和Manifest文件写入本地
            m_UpdateStepType = UpdateStepType.VersionWrite;

            // 将Persistent的文件列表替换成Cdn上的文件列表,并写入文件
            m_PersistentFileList = m_CdnFileList;
            SetPersistentFileList();

            // 将Version标记为最新的版本
            string[] cdnVersions    = m_CdnVersion.Split('.');
            string[] nativeVersions = m_Version.Split('.');
            m_Version = nativeVersions[0] + "." + nativeVersions[1] + "." + cdnVersions[2];
            SetPersistentVersion(m_Version);

            // 热更完成
            Action action = () =>
            {
                m_UpdateStepType = UpdateStepType.UpdateFinished;
                //优先读Persistent
                m_AssetPathType = AssetPathType.Persistent;
            };

            action += callback;
            CoroutineManager.MainThread(action);
        }
Exemplo n.º 5
0
        private IEnumerator DoVersionCompare(Action updateAction)
        {
            m_UpdateIndex++;
            // 等待UIRoot加载完毕
            yield return(null);

            if (m_UpdateIndex == 1)
            {
                LuaTable UIManager       = LuaMain.LuaEnv.Global.GetInPath <LuaTable>("LuaClass.UIManager.Instance");
                LuaTable moduleTypeClass = LuaMain.LuaEnv.Global.GetInPath <LuaTable>("LuaClass.ModuleType");
                m_LoadingUI = LuaMain.Instance.FuncInvoke(UIManager, "Open", UIManager, moduleTypeClass.Get <object>("Common"), "LoadingUI") as LuaTable;
            }

            // 对比版本
            m_UpdateStepType = UpdateStepType.VersionCompare;
            Debugger.Log("Start cdn version compare.");

            // 下载CDN服务器上的版本信息
            string[]  streamingVersions = ConstValue.VERSION.Split('.');
            string    cdnCurVerUrl      = ConstValue.CDN_URL + "/" + ConstValue.GAME_NAME + "/" + ConstValue.BUNDLE_DIR + "/" + streamingVersions[0] + "." + streamingVersions[1];
            WWWLoader cdnVersionLoader  = WWWManager.Load(cdnCurVerUrl + "/" + m_ModuleName + "/" + ConstValue.VERSION_NAME, this);

            yield return(cdnVersionLoader.Wait);

            if (cdnVersionLoader.Error != null)
            {
                // 下载失败,需要整包更新或其他原因
                //Debugger.Log("Update failed by: " + cdnVersionLoader.Error);
                //m_UpdateStepType = UpdateStepType.UpdateFailed;
                //OnUpdateFaild(ConstValue.VERSION_NAME, cdnVersionLoader.Error);
                LuaMain.Instance.FuncInvoke(m_LoadingUI, "PlayDefault", m_LoadingUI);
                m_UpdateStepType = UpdateStepType.UpdateCancel;
                yield break;
            }

            // 解析CDN上的版本号
            JsonObject cdnVersionInfoJo = StringParser.StringToJo(cdnVersionLoader.Text, false);

            m_CdnVersion = JsonParser.JoItemToString(cdnVersionInfoJo, ConstValue.VERSION_KEY, ConstValue.VERSION);
            Debugger.Log("Cdn version: " + m_CdnVersion);
            string[] cdnVersions   = m_CdnVersion.Split('.');
            int      cdnHotVersion = StringParser.StringToInt(cdnVersions[2]);

#if UNITY_WEBGL
            if (string.IsNullOrEmpty(m_Version))
            {
                m_Version = cdnVersions[0] + '.' + cdnVersions[1] + '.' + -1;
            }
#endif
            // 解析本地对比后的版本号
            string[] nativeVersions   = m_Version.Split('.');
            int      nativeHotVersion = StringParser.StringToInt(nativeVersions[2]);


            // 大版本号对比
            if (!string.Equals(cdnVersions[0], nativeVersions[0]) ||
                !string.Equals(cdnVersions[1], nativeVersions[1]))
            {
                // 如果资源服上的大版本号和本地的不同,则提示需要重新下载安装游戏
                LuaMain.Instance.FuncInvoke(m_LoadingUI, "ShowReDownloadDialog", m_LoadingUI, m_CdnVersion);
                //Application.Quit();
                yield break;
            }

            // 对比CDN上的和本地对比后的版本号
            if (nativeHotVersion >= cdnHotVersion)
            {
                if (m_UpdateIndex == 1)
                {
                    LuaMain.Instance.FuncInvoke(m_LoadingUI, "PlayDefault", m_LoadingUI);
                }
                else
                {
                    LuaMain.Instance.FuncInvoke(m_LoadingUI, "CheckModule", m_LoadingUI);
                }
                // 本地是最新的热更版本,不需要更新
                if (m_AssetPathType == AssetPathType.Streaming)
                {
                    // 如果最新的热更版本来自Streaming,则清空Persistent,清完后删除Version字段
                    // StartCoroutine(ClearPersistent());
                    if (m_PersistentFileList.Count > 0)
                    {
                        foreach (string fileName in m_PersistentFileList.Keys)
                        {
                            FileManager.Delete(ConstValue.PERSISTENT_DIR_PATH + "/" + m_ModuleName + "/" + fileName);
                            yield return(null);
                        }
                        FileManager.Delete(ConstValue.PERSISTENT_DIR_PATH + "/" + m_ModuleName + "/" + ConstValue.FILE_LIST_NAME);
                    }
                    if (IsPersistentHasVersion())
                    {
                        FileManager.Delete(ConstValue.PERSISTENT_DIR_PATH + "/" + m_ModuleName + "/" + ConstValue.VERSION_NAME);
                    }
                }
                Debugger.Log("Last version in native.");
                // 跳过更新
                m_UpdateStepType = UpdateStepType.UpdateCancel;
                yield break;
            }
            Debugger.Log("Last version in cdn.");
            m_UpdateStepType = UpdateStepType.VersionCompared;

            if (updateAction != null)
            {
                CoroutineManager.MainThread(updateAction);
            }
        }