| | |
| | | } |
| | | public static void GetAssetVersionFile() |
| | | { |
| | | checkAssetCompleted = false; |
| | | Debug.LogFormat("开始获取资源版本文件:时间 {0}", DateTime.Now); |
| | | var assetVersionUrl = StringUtility.Concat(VersionUtility.Instance.versionInfo.GetResourcesURL(VersionConfig.Get().branch), Language.fixPath, "/AssetsVersion.txt"); |
| | | assetVerUrl = assetVersionUrl; |
| | | Debug.Log("http地址:assetVersionUrl " + assetVersionUrl); |
| | | HttpRequest.Instance.UnityWebRequestGet(assetVersionUrl, 5, OnGetAssetVersionFile); |
| | | VersionConfig.GetAsync().ContinueWith(config => |
| | | { |
| | | checkAssetCompleted = false; |
| | | Debug.LogFormat("开始获取资源版本文件:时间 {0}", DateTime.Now); |
| | | var assetVersionUrl = StringUtility.Concat(VersionUtility.Instance.versionInfo.GetResourcesURL(config.branch), Language.fixPath, "/AssetsVersion.txt"); |
| | | assetVerUrl = assetVersionUrl; |
| | | Debug.Log("http地址:assetVersionUrl " + assetVersionUrl); |
| | | HttpRequest.Instance.UnityWebRequestGet(assetVersionUrl, 5, OnGetAssetVersionFile); |
| | | }).Forget(); |
| | | |
| | | } |
| | | |
| | | private static void OnGetAssetVersionFile(bool _ok, string _result) |
| | | private static async void OnGetAssetVersionFile(bool _ok, string _result) |
| | | { |
| | | Debug.LogFormat("获取资源版本文件结果:时间 {0},结果 {1}, 文件大小 {2}", DateTime.Now, _ok, _result.Length); |
| | | if (_ok) |
| | | { |
| | | assetVersionsLocalMd5 = FileExtersion.GetStringMD5Hash(_result); |
| | | var assetVersions = UpdateAssetVersions(_result); |
| | | var assetVersions = await UpdateAssetVersions(_result); |
| | | BeginCheckAssets(); |
| | | } |
| | | else |
| | |
| | | if (InGameDownTestUtility.enable && !InGameDownTestUtility.isReadStreamingAssets) |
| | | checkStream = false; |
| | | #endif |
| | | BeginCheckAssetsAsync(checkStream).Forget(); |
| | | } |
| | | |
| | | ThreadPool.QueueUserWorkItem( |
| | | (object aaa) => |
| | | private static async UniTaskVoid BeginCheckAssetsAsync(bool checkStream) |
| | | { |
| | | int count = 0; |
| | | foreach (var assetVersion in assetVersions.Values) |
| | | { |
| | | bool checkReuslt; |
| | | if (checkStream) |
| | | { |
| | | foreach (var assetVersion in assetVersions.Values) |
| | | { |
| | | bool checkReuslt; |
| | | if (checkStream) |
| | | { |
| | | AssetVersion localAssetVersion = null; |
| | | localAssetVersions.TryGetValue(assetVersion.relativePath, out localAssetVersion); |
| | | checkReuslt = assetVersion.CheckLocalFileValid(localAssetVersion); |
| | | } |
| | | else |
| | | { |
| | | checkReuslt = assetVersion.CheckLocalFileValid(false); |
| | | } |
| | | if (!checkReuslt) |
| | | { |
| | | if (assetVersion.IsPriorAsset()) |
| | | { |
| | | priorDownLoadAssetVersions.Add(assetVersion); |
| | | } |
| | | else |
| | | { |
| | | unpriorDownLoadAssetVersions.Add(assetVersion); |
| | | } |
| | | |
| | | assetVersion.localValid = false; |
| | | } |
| | | else |
| | | { |
| | | assetVersion.localValid = true; |
| | | } |
| | | } |
| | | |
| | | m_PriorAssetDownLoadDone = priorDownLoadAssetVersions.Count <= 0; |
| | | m_UnPriorAssetDownLoadDone = unpriorDownLoadAssetVersions.Count <= 0; |
| | | |
| | | checkAssetCompleted = true; |
| | | AssetVersion localAssetVersion = null; |
| | | localAssetVersions.TryGetValue(assetVersion.relativePath, out localAssetVersion); |
| | | checkReuslt = assetVersion.CheckLocalFileValid(localAssetVersion); |
| | | } |
| | | ); |
| | | else |
| | | { |
| | | checkReuslt = assetVersion.CheckLocalFileValid(false); |
| | | } |
| | | |
| | | if (!checkReuslt) |
| | | { |
| | | if (await assetVersion.IsPriorAsset()) |
| | | priorDownLoadAssetVersions.Add(assetVersion); |
| | | else |
| | | unpriorDownLoadAssetVersions.Add(assetVersion); |
| | | |
| | | assetVersion.localValid = false; |
| | | } |
| | | else |
| | | { |
| | | assetVersion.localValid = true; |
| | | } |
| | | |
| | | count++; |
| | | if (count % 50 == 0) |
| | | await UniTask.Yield(); // 每50个让出一帧,避免主线程卡顿 |
| | | } |
| | | |
| | | m_PriorAssetDownLoadDone = priorDownLoadAssetVersions.Count <= 0; |
| | | m_UnPriorAssetDownLoadDone = unpriorDownLoadAssetVersions.Count <= 0; |
| | | checkAssetCompleted = true; |
| | | } |
| | | |
| | | public static void BeginDownLoadTask(bool _prior) |
| | |
| | | } |
| | | } |
| | | |
| | | public static Dictionary<string, AssetVersion> UpdateAssetVersions(string _assetVersionFile) |
| | | public async static UniTask<Dictionary<string, AssetVersion>> UpdateAssetVersions(string _assetVersionFile) |
| | | { |
| | | InitPackageVersionInfo(); |
| | | await InitPackageVersionInfo(); |
| | | var lines = _assetVersionFile.Split(new string[] { FileExtersion.lineSplit }, StringSplitOptions.RemoveEmptyEntries); |
| | | assetVersions.Clear(); |
| | | for (int i = 0; i < lines.Length; i++) |
| | |
| | | return assetVersions; |
| | | } |
| | | |
| | | static void InitPackageVersionInfo() |
| | | static async UniTask InitPackageVersionInfo() |
| | | { |
| | | var text = Resources.Load<TextAsset>("AssetsVersionCmp"); |
| | | var text = await Resources.LoadAsync<TextAsset>("AssetsVersionCmp") as TextAsset; |
| | | if (text != null) |
| | | { |
| | | var lines = text.text.Split(new string[] { FileExtersion.lineSplit }, StringSplitOptions.RemoveEmptyEntries); |