Exemplo n.º 1
0
        private IEnumerator RequestCopy()
        {
            var v1       = Versions.LoadVersion(_savePath + Versions.Filename);
            var basePath = GetStreamingAssetsPath() + "/";
            var request  = UnityWebRequest.Get(basePath + Versions.Filename);
            var path     = _savePath + Versions.Filename + ".tmp";

            request.downloadHandler = new DownloadHandlerFile(path);
            yield return(request.SendWebRequest());

            if (string.IsNullOrEmpty(request.error))
            {
                var v2 = Versions.LoadVersion(path);
                if (v2 > v1)
                {
                    var mb = UIDialogue.Show("提示", "是否将资源解压到本地?", "解压", "跳过");
                    yield return(mb);

                    _step = mb.isOk ? EStep.Coping : EStep.Versions;
                }
                else
                {
                    Versions.LoadVersions(path);
                    _step = EStep.Versions;
                }
            }
            else
            {
                _step = EStep.Versions;
            }
            request.Dispose();
        }
Exemplo n.º 2
0
 public void Clear()
 {
     UIDialogue.Show("提示", "清除数据后所有数据需要重新下载,请确认!", "清除").onComplete += id =>
     {
         if (id != UIDialogue.EventId.Ok)
         {
             return;
         }
         OnClear();
     };
 }
Exemplo n.º 3
0
        public void OnReachablityChanged(NetworkReachability reachability)
        {
            if (_step == EStep.Wait)
            {
                return;
            }

            _reachabilityChanged = true;
            if (_step == EStep.Download)
            {
                _downloader.Stop();
            }

            if (reachability == NetworkReachability.NotReachable)
            {
                UIDialogue.Show("提示!", "找不到网络,请确保手机已经联网", "确定", "退出").onComplete += delegate(UIDialogue.EventId id)
                {
                    if (id == UIDialogue.EventId.Ok)
                    {
                        if (_step == EStep.Download)
                        {
                            _downloader.Restart();
                        }
                        else
                        {
                            StartUpdate();
                        }
                        _reachabilityChanged = false;
                    }
                    else
                    {
                        Quit();
                    }
                };
            }
            else
            {
                if (_step == EStep.Download)
                {
                    _downloader.Restart();
                }
                else
                {
                    StartUpdate();
                }
                _reachabilityChanged = false;
                UIDialogue.CloseAll();
            }
        }
Exemplo n.º 4
0
        private IEnumerator RequestVersions()
        {
            OnMessage("正在获取版本信息...");
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                var mb = UIDialogue.Show("提示", "请检查网络连接状态", "重试", "退出");
                yield return(mb);

                if (mb.isOk)
                {
                    StartUpdate();
                }
                else
                {
                    Quit();
                }
                yield break;
            }

            var request = UnityWebRequest.Get(GetDownloadURL(Versions.Filename));

            request.downloadHandler = new DownloadHandlerFile(_savePath + Versions.Filename);
            yield return(request.SendWebRequest());

            var error = request.error;

            request.Dispose();
            if (!string.IsNullOrEmpty(error))
            {
                var mb = UIDialogue.Show("提示", string.Format("获取服务器版本失败:{0}", error), "重试", "退出");
                yield return(mb);

                if (mb.isOk)
                {
                    StartUpdate();
                }
                else
                {
                    Quit();
                }
                yield break;
            }
            try
            {
                _versions = Versions.LoadVersions(_savePath + Versions.Filename, true);
                if (_versions.Count > 0)
                {
                    PrepareDownloads();
                    _step = EStep.Prepared;
                }
                else
                {
                    OnComplete();
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                UIDialogue.Show("提示", "版本文件加载失败", "重试", "退出").onComplete +=
                    delegate(UIDialogue.EventId id)
                {
                    if (id == UIDialogue.EventId.Ok)
                    {
                        StartUpdate();
                    }
                    else
                    {
                        Quit();
                    }
                };
            }
        }
Exemplo n.º 5
0
        private IEnumerator Checking()
        {
            if (!Directory.Exists(_savePath))
            {
                Directory.CreateDirectory(_savePath);
            }

            //if (_step == EStep.Wait)
            //{
            //    yield return RequestVFS();
            //    _step = EStep.Copy;
            //}

            _step = EStep.Copy;

            if (_step == EStep.Copy)
            {
                yield return(RequestCopy());
            }

            if (_step == EStep.Coping)
            {
                var path     = _savePath + Versions.Filename + ".tmp";
                var versions = Versions.LoadVersions(path);
                var basePath = GetStreamingAssetsPath() + "/";
                yield return(UpdateCopy(versions, basePath));

                _step = EStep.Versions;
            }

            if (_step == EStep.Versions)
            {
                yield return(RequestVersions());
            }

            if (_step == EStep.Prepared)
            {
                OnMessage("正在检查版本信息...");
                var totalSize = _downloader.size;
                if (totalSize > 0)
                {
                    var tips = string.Format("发现内容更新,总计需要下载 {0} 内容", Downloader.GetDisplaySize(totalSize));
                    var mb   = UIDialogue.Show("提示", tips, "下载", "退出");
                    yield return(mb);

                    if (mb.isOk)
                    {
                        _downloader.StartDownload();
                        _step = EStep.Download;
                    }
                    else
                    {
                        Quit();
                    }
                }
                else
                {
                    OnComplete();
                }
            }
        }