static void GenerateAssetVersionInfo() { string platform = GameFrameworkCommon.GetPlatformName(); string dirpath = System.IO.Path.Combine(UnityEngine.Application.dataPath.Replace("Assets", ""), "AssetBundles/" + platform); AssetBundleVersionInfo abversion = new AssetBundleVersionInfo(); abversion.IsEncrypt = false; abversion.Version = 10000; abversion.ManifestAssetBundle = platform; var infos = new List <ResourcesInfo>(); var resources = CalculateMd5(dirpath); foreach (var item in resources) { ResourcesInfo info = new ResourcesInfo(); info.Name = item.Key.Substring(item.Key.IndexOf(platform) + platform.Length + 1).Replace(@"\\", "/"); info.MD5 = item.Value; infos.Add(info); } abversion.Resources = infos; string assetversion = EditorJsonUtility.ToJson(abversion); System.IO.File.WriteAllText(System.IO.Path.Combine(ResourceManager.GetDeafultPath(PathType.ReadOnly), CheckResourceState.AssetVersionTxt), assetversion); ATFileOp.ShowExplorerWindow(System.IO.Path.Combine(ResourceManager.GetDeafultPath(PathType.ReadOnly), CheckResourceState.AssetVersionTxt)); }
/// <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; } } }