示例#1
0
        void ComparServerVersion()
        {
            string url      = ResourceManager.ResourceUrl + "version.txt";
            string savepath = Application.persistentDataPath + "/version.txt";

            Downloader.DownloadFiles(new List <DownloadFile>()
            {
                new DownloadFile(url, savepath)
            },
                                     (obj) =>
            {
                if (!File.Exists(savepath))
                {
                    _onShowUpdateStepFail(0);
                    return;
                }

                string str    = File.ReadAllText(savepath);
                string[] strs = str.Split(' ');
                if (strs.Length != 3)
                {
                    _onShowUpdateStepFail(1);
                    return;
                }

                float serverCodeVersion;
                if (!float.TryParse(strs[0], out serverCodeVersion))
                {
                    _onShowUpdateStepFail(2);
                    return;
                }

                uint crc;
                if (!uint.TryParse(strs[1], out crc))
                {
                    _onShowUpdateStepFail(3);
                    return;
                }

                GameClient.Instance.targetVersion = strs[2];
                File.Delete(savepath);

                if ((int)serverCodeVersion > (int)ResourceManager.CodeVersion)
                {
#if UNITY_ANDROID && !UNITY_EDITOR
                    bool updateInGame = ILRuntimeHelper.GetUpdateInGame();
                    if (updateInGame)
                    {
                        _targetVersion = (int)serverCodeVersion;
                        ChangeCurrentUpdateState(UpdateState.DownloadPatchConfig);
                    }
                    else
                    {
                        ChangeCurrentUpdateState(UpdateState.OpenNewClientUrl, false);
                    }
#else
                    ChangeCurrentUpdateState(UpdateState.OpenNewClientUrl, false);
#endif
                }
                else
                {
                    uint localCrc = FileHelper.GetFileCrc(ResourceManager.DataPath + "ResourceList.ab");
                    if (crc != localCrc)
                    {
                        _resourceCrc = crc;
                        ChangeCurrentUpdateState(UpdateState.DownloadResourceList);
                    }
                    else
                    {
                        ChangeCurrentUpdateState(UpdateState.CheckLoacalResource);
                    }
                }
            });
        }