public void Convert(AssetUpdateDifferenceList differenceList, AssetUpdateConfigList configList) { if (string.IsNullOrEmpty(_baseDownloadUrl) || string.IsNullOrEmpty(_baseSaveFolder)) { return; } if (differenceList == null) { return; } var packageDict = configList?.GetDict(); if (differenceList.adds != null && differenceList.adds.dict != null) { foreach (var vPair in differenceList.adds.dict) { ConverUpdateItem(vPair, packageDict); } } if (differenceList.modifys != null && differenceList.modifys.dict != null) { foreach (var vPair in differenceList.modifys.dict) { ConverUpdateItem(vPair, packageDict); } } if (differenceList.removes != null && differenceList.removes.dict != null) { foreach (var vPair in differenceList.removes.dict) { ConverRemoveItem(vPair, packageDict); } } }
//////////////////////////// protected IEnumerator OnUpdateAsset() { AssetUpdateAssetList newAssetList = new AssetUpdateAssetList(); //从服务器下载下来的资源列表 AssetUpdateAssetList oldAssetList = new AssetUpdateAssetList(); //从远端下载资源列表到本地 bool isNetworkDownloadFinish = false; var networkAssetList = GetNetworkAssetPath(); if (!File.Exists(networkAssetList)) { var networkAssetListUrl = GetNetworkAssetUrl(); var task = AssetDownloadManager.GetInstance().Download(new string[] { networkAssetListUrl }, new string[] { networkAssetList }); task.onCompleted = (_) => { isNetworkDownloadFinish = true; }; //等待下载结束 while (!isNetworkDownloadFinish) { yield return(null); } } if (File.Exists(assetFolderPath)) { oldAssetList.Import(assetFolderPath); } else { onFinish?.Invoke(-1); yield break; } //读取本地资源列表 var localAssetList = GetLocalAssetListPath(); if (!File.Exists(localAssetList)) { oldAssetList.Scan(assetFolderPath); oldAssetList.Export(localAssetList); } else { oldAssetList.Import(assetFolderPath); } //配置列表读取 var networkConfigList = GetNetworkConfigPath(); AssetUpdateConfigList configList = null; if (File.Exists(networkConfigList)) { configList = new AssetUpdateConfigList(); configList.Import(networkConfigList); } //做资源对比 AssetUpdateDifferenceList differenceList = new AssetUpdateDifferenceList(); differenceList.Compare(newAssetList, oldAssetList); if (differenceList.IsVerify()) //资源一致,不需要更新 { onFinish?.Invoke(0); yield break; } //差异表转成更新列表去更新 AssetUpdateUpdateList assetUpdateUpdateList = new AssetUpdateUpdateList(updateDownloadUrl, downloadFolderPath, assetFolderPath); assetUpdateUpdateList.Convert(differenceList, configList); //启动更新 bool isUpdateFinsin = false; AssetUpdateUpdater updater = new AssetUpdateUpdater(assetUpdateUpdateList); updater.Update(); updater.onFinish = () => { isUpdateFinsin = true; }; while (!isUpdateFinsin) { yield return(null); } onFinish?.Invoke(1); yield break; }