public static async Task <bool> IsGameVersionCodeEqual() { UnityWebRequestAsync webRequestAsync = MonoBehaviourHelper.CreateTempComponent <UnityWebRequestAsync>(); try { GlobalProto.VersionCodeInfo NowLineCodeInfo = null; GlobalProto.VersionCodeInfo UpdatingCodeInfo = null; string PathNowLineCodeInfo = GlobalConfigComponent.intance.GlobalProto.GetNowLineCodeInfoPath(); //下载PathNowLineCodeInfo await webRequestAsync.DownloadAsync(PathNowLineCodeInfo); NowLineCodeInfo = GlobalConfigComponent.intance.GlobalProto.GetNowLineCodeInfo(webRequestAsync.Request.downloadHandler.text); string PathUpdatingCodeInfo = GlobalConfigComponent.intance.GlobalProto.GetUpdatingCodeInfoPath(); //下载PathUpdatingCodeInfo await webRequestAsync.DownloadAsync(PathUpdatingCodeInfo); UpdatingCodeInfo = GlobalConfigComponent.intance.GlobalProto.GetUpdatingCodeInfo(webRequestAsync.Request.downloadHandler.text); webRequestAsync.Dispose(); //比较VersionCode StaticData.DebugGreen($"local versionGameCode:{StaticData.localVersionGameCode},remote NowLineCodeInfo GameVersionCode:{NowLineCodeInfo.GameVersionCode} remote NowLineCodeInfo ResVersionCode:{NowLineCodeInfo.ResVersionCode},remote UpdatingCodeInfo GameVersionCode:{UpdatingCodeInfo.GameVersionCode} remote UpdatingCodeInfo ResVersionCode:{UpdatingCodeInfo.ResVersionCode}"); if (StaticData.localVersionGameCode < NowLineCodeInfo.GameVersionCode) { //强更 TipsDifferentVersion(); StaticData.intParentResABDirectory = NowLineCodeInfo.ResVersionCode; StaticData.isUsePlatformUpdatingGateWay = false; return(false); } else if (StaticData.localVersionGameCode == NowLineCodeInfo.GameVersionCode) { //热更本地资源 StaticData.intParentResABDirectory = NowLineCodeInfo.ResVersionCode; StaticData.isUsePlatformUpdatingGateWay = false; return(true); } else { //已经是最新包,只需要更新最新包资源即可 StaticData.intParentResABDirectory = UpdatingCodeInfo.ResVersionCode; StaticData.isUsePlatformUpdatingGateWay = true; return(true); } } catch (Exception e) { if (e.Message.Contains("request error")) { Debug.Log($"load VersionGameCode error:'{e.Message}'"); return(true); } } finally { GameObject.Destroy(webRequestAsync.gameObject); } return(false); }
/// <summary> /// 返回是否需要下载 /// </summary> /// <returns></returns> public async Task <bool> LoadInfo() { UnityWebRequestAsync webRequestAsync = MonoBehaviourHelper.CreateTempComponent <UnityWebRequestAsync>(); string remoteVersionText = string.Empty; try { //下载remote version.txt string versionUrl = LoadBundlePathRoot() + "StreamingAssets/Version.txt"; await webRequestAsync.DownloadAsync(versionUrl); remoteVersionText = webRequestAsync.Request.downloadHandler.text; } catch (Exception e) { if (e.Message.Contains("request error")) { webRequestAsync.Dispose(); Debug.Log($"load VersionText error:'{e.Message}'"); StaticData.isUseStreamingAssetRes = true; OnFileServerNotReach(e.Message); return(false); } } finally { Destroy(webRequestAsync.gameObject); } Debug.Log($"remoteVersionText:{remoteVersionText}"); if (!remoteVersionText.StartsWith("{")) { Debug.Log("remote version text is not a correct json"); this.remoteVersionConfig = null; return(false); } this.remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(remoteVersionText); var needDown = await AnalyseVersionConfig(); if (needDown == false) { return(false); } return(true); }