/// <summary> /// 下载版本信息文本失败监听 /// </summary> /// <param name="arg1"></param> /// <param name="arg2"></param> private void OnHttpReadTextFailure(object sender, IEventArgs e) { #if UNITY_EDITOR HttpReadTextEventArgs args = (HttpReadTextEventArgs)e; if (args != null) { UnityEngine.Debug.LogError("下载文本失败! \n Url: " + args.Url + "\n 详细信息: " + args.Additive); } #endif }
/// <summary> /// 下载版本信息文本成功监听 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnHttpReadTextSuccess(object sender, IEventArgs e) { HttpReadTextEventArgs args = (HttpReadTextEventArgs)e; if (args != null) { if (args.Url == Path.Combine(GameMain.ResourceMG.ResUpdatePath, _assetPlatformVersionText)) { AssetPlatformVersionInfo assetPlatform = JsonUtility.FromJson <AssetPlatformVersionInfo>(args.Additive); string platformName = GameFrameworkCommon.GetPlatformName(); if (assetPlatform.Platforms.Contains(platformName)) { //资源的更新路径 GameMain.ResourceMG.ResUpdatePath = Path.Combine(GameMain.ResourceMG.ResUpdatePath, platformName); //读取远程的文本 string remotePath = Path.Combine(GameMain.ResourceMG.ResUpdatePath, _assetVersionTxt); GameMain.WebRequestMG.ReadHttpText(remotePath); } else { #if UNITY_EDITOR UnityEngine.Debug.Log("服务器上不包含当前平台的资源文件!"); #endif } } else if (args.Url == Path.Combine(GameMain.ResourceMG.ResUpdatePath, _assetVersionTxt)) { _remoteVersion = JsonUtility.FromJson <AssetBundleVersionInfo>(args.Additive); if (_remoteVersion == null) { #if UNITY_EDITOR UnityEngine.Debug.LogError("Remote version is null."); #endif return; } if (!CompareVersion()) { //更新资源 UpdateResource(); //下载资源 DownloadResource(); } #if UNITY_EDITOR Debug.Log(">>>>>资源已经是最新版本了!"); #endif //资源更新完成 _resourceUpdateDone = true; } } }
/// <summary> /// 回调函数,读取Http的文本 /// </summary> /// <param name="path">Http读取的远程路径</param> /// <param name="result">读取结果</param> /// <param name="content">读取的文本内容</param> private void ReadHttpTextCallback(string path, bool result, string content) { HttpReadTextEventArgs httpReadTextEventArgs = new HttpReadTextEventArgs(); httpReadTextEventArgs.Url = path; httpReadTextEventArgs.Additive = content; if (result) { _event.CallEvent(this, EventType.HttpReadTextSuccess, httpReadTextEventArgs); } else { _event.CallEvent(this, EventType.HttpReadTextFailure, httpReadTextEventArgs); } }