public void InitAssets(DownloadData downloadData) { byte[] bytes = FileUtil.GetAsset($"{PathUtil.GetPath(PathType.PersistentDataPath, "Res")}/AssetBundleConfig.json"); localAssetBundleConfig = JsonUtil.ToObject <AssetBundleConfig>(bytes.GetString()); List <DownloadData> downloadDataList = new List <DownloadData>(); foreach (string item in localAssetBundleConfig.assetBundleDataDict.Keys) { DownloadData data = new DownloadData(item, "", $"{PathUtil.GetPath(PathType.PersistentDataPath, "Res")}/{item}.unity3d"); downloadDataList.Add(data); } //开始初始化资源 DownloadManager.Instance.DownloadAsync(downloadDataList.ToArray()); }
public void CheckLocalAsset() { byte[] bytes = FileUtil.GetAsset($"{PathUtil.GetPath(PathType.PersistentDataPath, "Res")}/AssetBundleConfig.json"); if (bytes != null) { //开始更新 localAssetBundleConfig = JsonUtil.ToObject <AssetBundleConfig>(bytes.GetString()); CheckUpdateAsset(null, string.Empty); return; } DownloadData downloadData = new DownloadData("AssetBundleConfig", "", $"{PathUtil.GetPath(PathType.PersistentDataPath, "Res")}/AssetBundleConfig.json"); downloadData.complete = InitAssets; downloadData.error = CheckUpdateAsset; DownloadManager.Instance.DownloadAsync(downloadData); }
public void InitAssets(byte[] bytes) { Message?.Invoke("初始化资源"); FileUtil.SaveAsset(PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle()), "AssetBundleConfig.json", bytes); localAssetBundleConfig = JsonUtil.ToObject <AssetBundleConfig>(bytes.GetString()); List <string> keyList = new List <string>(); keyList.Add(PathUtil.GetPlatformForAssetBundle()); keyList.Add($"{PathUtil.GetPlatformForAssetBundle()}.manifest"); foreach (string item in localAssetBundleConfig.assetBundleDataDict.Keys) { keyList.Add($"{item}.unity3d"); } copyCount = keyList.Count; //开始拷贝资源 StartCoroutine(CopyAssets(keyList.ToArray())); }
public void InitAssets(Action <string> message = null, Action <int, int> copyProgress = null, Action <int, int> downloadProgress = null, Action <int, int> checkProgress = null, Action complete = null, Action <DownloadData, string> error = null) { Message = message; CopyProgress = copyProgress; DownloadProgress = downloadProgress; CheckProgress = checkProgress; Complete = complete; Error = error; if (File.Exists($"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/AssetBundleConfig.json")) { byte[] bytes = FileUtil.GetAsset($"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/AssetBundleConfig.json"); localAssetBundleConfig = JsonUtil.ToObject <AssetBundleConfig>(bytes.GetString()); //更新资源 UpdateAssets(string.Empty); return; } else { StartCoroutine(WebUtil.Download($"{"file:///"}{PathUtil.GetPath(PathType.StreamingAssetsPath, "Res", PathUtil.GetPlatformForAssetBundle())}/AssetBundleConfig.json", InitAssets, UpdateAssets)); } }
public void UpdateAssets(DownloadData downloadData) { Message?.Invoke("检测资源中"); byte[] bytes = FileUtil.GetAsset($"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/ServerAssetBundleConfig.json"); serverAssetBundleConfig = JsonUtil.ToObject <AssetBundleConfig>(bytes.GetString()); List <DownloadData> downloadDataList = new List <DownloadData>(); if (localAssetBundleConfig == null) { foreach (string item in serverAssetBundleConfig.assetBundleDataDict.Keys) { DownloadData data = new DownloadData(item, $"{url}/{PathUtil.GetPlatformForAssetBundle()}/{item}.unity3d", $"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/{item}.unity3d"); data.Complete += DownloadComplete; data.Error += Error; downloadDataList.Add(data); } } else if (localAssetBundleConfig.version < serverAssetBundleConfig.version) { foreach (string item in ComputeUpdateAssets()) { DownloadData data = new DownloadData(item, $"{url}/{PathUtil.GetPlatformForAssetBundle()}/{item}.unity3d", $"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/{item}.unity3d"); data.Complete += DownloadComplete; data.Error += Error; downloadDataList.Add(data); } } DownloadData data1 = new DownloadData(PathUtil.GetPlatformForAssetBundle(), $"{url}/{PathUtil.GetPlatformForAssetBundle()}/{PathUtil.GetPlatformForAssetBundle()}", $"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/{PathUtil.GetPlatformForAssetBundle()}"); data1.Complete += DownloadComplete; data1.Error += Error; DownloadData data2 = new DownloadData($"{PathUtil.GetPlatformForAssetBundle()}.manifest", $"{url}/{PathUtil.GetPlatformForAssetBundle()}/{PathUtil.GetPlatformForAssetBundle()}.manifest", $"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/{PathUtil.GetPlatformForAssetBundle()}.manifest"); data2.Complete += DownloadComplete; data2.Error += Error; downloadDataList.Add(data1); downloadDataList.Add(data2); updateCount = downloadDataList.Count; DownloadManager.Instance.DownloadAsync(downloadDataList.ToArray()); }