IEnumerator GetUrlListAndCheckUpdate(bool isInternalVersion) { if (isInternalVersion) { // 内部版本使用本地服务器更新 yield return(InternalGetUrlList()); } else { // 外部版本一律使用外网服务器更新 yield return(OutnetGetUrlList()); } // 检测大版本更新 #if UNITY_EDITOR // 编辑器下总是不进行大版本更新 needDownloadGame = false; #else if (isInternalVersion) { #if UNITY_ANDROID if (ChannelManager.instance.IsGooglePlay()) { // TODO:这里还要探索下怎么下载 needDownloadGame = false; Debug.LogError("No support for local server download game for GooglePlay now !!!"); } else { // 对比版本号更新 needDownloadGame = BuildUtils.CheckIsNewVersion(clientAppVersion, serverAppVersion); } #elif UNITY_IPHONE // TODO:iOS下的本地下载要进一步探索,这里先不管 needDownloadGame = false; Debug.LogError("No support for local server download game for iOS now !!!"); #endif } else { // 外部版本对比版本号更新 needDownloadGame = BuildUtils.CheckIsNewVersion(clientAppVersion, serverAppVersion); } #endif // 检测资源更新 if (isInternalVersion) { // 内部版本总是检测资源更新,避免开发过程中需要频繁升级资源版本号 needUpdateGame = true; } else { // 外部版本对比版本号更新 needUpdateGame = BuildUtils.CheckIsNewVersion(clientResVersion, serverResVersion); } #if UNITY_CLIENT || LOGGER_ON System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.AppendFormat("SERVER_LIST_URL = {0}\n", URLSetting.SERVER_LIST_URL); sb.AppendFormat("LOGIN_URL = {0}\n", URLSetting.LOGIN_URL); sb.AppendFormat("REPORT_ERROR_URL = {0}\n", URLSetting.REPORT_ERROR_URL); sb.AppendFormat("NOTIFY_URL = {0}\n", URLSetting.NOTICE_URL); sb.AppendFormat("APP_DOWNLOAD_URL = {0}\n", URLSetting.APP_DOWNLOAD_URL); sb.AppendFormat("SERVER_RESOURCE_ADDR = {0}\n", URLSetting.SERVER_RESOURCE_URL); sb.AppendFormat("noticeVersion = {0}\n", ChannelManager.instance.noticeVersion); sb.AppendFormat("serverAppVersion = {0}\n", serverAppVersion); sb.AppendFormat("serverResVersion = {0}\n", serverResVersion); Logger.Log(sb.ToString()); #endif yield break; }
IEnumerator InitAppVersion() { var streamingAppVersion = "0.0.0"; var streamingResVersion = "0.0.0"; var streamingChannel = "Test"; #if UNITY_EDITOR if (AssetBundleConfig.IsEditorMode) { ChannelManager.Instance.appVersion = streamingAppVersion; ChannelManager.Instance.resVersion = streamingResVersion; channelName = streamingChannel; yield break; } #endif //streaming var appVersionRequest = AssetBundleManager.Instance.RequestAssetFileAsync(BuildUtils.AppVersionFileName); yield return(appVersionRequest); var streamingTxt = appVersionRequest.text; appVersionRequest.Dispose(); if (!string.IsNullOrEmpty(streamingTxt)) { var array = streamingTxt.Split('|'); streamingAppVersion = array[0]; streamingResVersion = array[1]; streamingChannel = array[2]; } //persistent var persistentAppVersion = streamingAppVersion; var persistentResVersion = streamingResVersion; var persistentChannel = streamingChannel; var appVersionPath = AssetBundleUtility.GetPersistentDataPath(BuildUtils.AppVersionFileName); var persistentTxt = GameUtility.SafeReadAllText(appVersionPath); if (string.IsNullOrEmpty(persistentTxt)) { GameUtility.SafeWriteAllText(appVersionPath, streamingAppVersion + "|" + streamingResVersion + "|" + streamingChannel); } else { var array = persistentTxt.Split('|'); persistentAppVersion = array[0]; persistentResVersion = array[1]; persistentChannel = array[2]; } //init ChannelManager.Instance.appVersion = persistentAppVersion; ChannelManager.Instance.resVersion = persistentResVersion; channelName = persistentChannel; Logger.Log(string.Format("persistentResVersion = {0}, persistentResVersion = {1}, persistentChannel = {2}", persistentAppVersion, persistentResVersion, persistentChannel)); Logger.Log(string.Format("streamingAppVersion = {0}, streamingAppVersion = {1}, streamingChannel = {2}", streamingAppVersion, streamingResVersion, streamingChannel)); // 如果persistent目录版本比streamingAssets目录app版本低,说明是大版本覆盖安装,清理过时的缓存 if (BuildUtils.CheckIsNewVersion(persistentAppVersion, streamingAppVersion)) { Debug.Log("大版本覆盖安装,清理过时的缓存"); ChannelManager.Instance.appVersion = streamingAppVersion; ChannelManager.Instance.resVersion = streamingResVersion; var path = AssetBundleUtility.GetPersistentDataPath(); GameUtility.SafeDeleteDir(path); GameUtility.SafeWriteAllText(appVersionPath, streamingAppVersion + "|" + streamingResVersion + "|" + streamingChannel); // 重启资源管理器 yield return(AssetBundleManager.Instance.Cleanup()); yield return(AssetBundleManager.Instance.Initialize()); } }