private void Update() { switch (_step) { case Step.Wait: break; case Step.Version: _step = Step.Wait; OnMessage("正在获取版本信息..."); if (!Directory.Exists(_savePath)) { Directory.CreateDirectory(_savePath); } if (Application.internetReachability == NetworkReachability.NotReachable) { MessageBox.Show("提示", "请检查网络连接状态", "重试", "退出").onComplete = OnErrorAction; return; } var request = Download(Versions.Filename); var oper = request.SendWebRequest(); oper.completed += delegate(AsyncOperation operation) { if (!string.IsNullOrEmpty(request.error)) { MessageBox.Show("提示", string.Format("获取服务器版本失败:{0}", request.error), "重试", "退出").onComplete = OnErrorAction; } else { try { Versions.serverVersion = Versions.LoadFullVersion(_savePath + Versions.Filename); var newFiles = Versions.GetNewFiles(PatchId.Level1, _savePath); if (newFiles.Count > 0) { foreach (var item in newFiles) { _downloader.AddDownload(GetDownloadURL(item.name), item.name, _savePath + item.name, item.hash, item.len); } _step = Step.Prepared; } else { OnComplete(); } } catch (Exception e) { Debug.LogException(e); MessageBox.Show("提示", "版本文件加载失败", "重试", "退出").onComplete += OnErrorAction; } } }; break; case Step.Prepared: OnMessage("正在检查版本信息..."); _step = Step.Wait; var totalSize = _downloader.size; if (totalSize > 0) { var tips = string.Format("发现内容更新,总计需要下载 {0} 内容", Downloader.GetDisplaySize(totalSize)); MessageBox.Show("提示", tips, "下载", "退出").onComplete += delegate(MessageBox.EventId id) { if (id == MessageBox.EventId.Ok) { _downloader.StartDownload(); _step = Step.Download; } else { Quit(); } }; } else { OnComplete(); } break; } }