public static void BuildAssetBundlesAll() { string outputPath = AssetPathManager.GetAssetBundleOutPutPath(); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } BuildAssetBundleOptions option = BuildAssetBundleOptions.DeterministicAssetBundle; //*该方法会自动检查目标路径下是否存在需要 build 的 bundle 已经存在的不会重新打包 不是单纯的名字检查 会检查bundle与要打得bundle是否符合*/ AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(outputPath, option, BuildTarget.iOS); Log.Print("Build succeed", manifest.GetAllAssetBundles().ToString()); AssetDatabase.Refresh(); }
public static bool DeleteAllFile() { string fullPath = AssetPathManager.GetAssetBundleOutPutPath(); //获取指定路径下面的所有资源文件 然后进行删除 if (Directory.Exists(fullPath)) { DirectoryInfo direction = new DirectoryInfo(fullPath); FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { if (files[i].Name.EndsWith(".meta")) { continue; } string FilePath = fullPath + "/" + files[i].Name; File.Delete(FilePath); } return(true); } return(false); }
/// <summary> /// check bundle exist and load /// </summary> /// <param name="bundleName"></param> /// <returns></returns> public IEnumerator CheckLoadBundleFromLocalFile(string bundleName, Action loadSucceedCallBack = null, Action loadFailedCallBack = null, Action <float> loadingCallBack = null) { if (string.IsNullOrEmpty(bundleName)) { Log.Error("Bundle name error", bundleName); loadFailedCallBack?.Invoke(); yield break; } if (!IsBundleExistInCache(bundleName)) { string path = Path.Combine(AssetPathManager.GetAssetBundleOutPutPath(), bundleName); if (File.Exists(path)) { var _bundeCreateRequest = new AssetBundleCreateRequest(); bundleCreateRequests.Add(bundleName, _bundeCreateRequest); _bundeCreateRequest = AssetBundle.LoadFromFileAsync(path); int displayProgress = 1; int toProgress = 0; while (!_bundeCreateRequest.isDone) { toProgress = (int)(100 * _bundeCreateRequest.progress); while (displayProgress <= toProgress) { loadingCallBack?.Invoke((float)displayProgress / 100.0f); yield return(GameConstants.Wait1In60Second); displayProgress++; } yield return(GameConstants.Wait1In60Second); } toProgress = 100; while (displayProgress <= toProgress) { loadingCallBack?.Invoke((float)displayProgress / 100.0f); yield return(GameConstants.Wait1In60Second); displayProgress++; } if (_bundeCreateRequest.assetBundle != null) { AddBundleCache(_bundeCreateRequest.assetBundle); loadSucceedCallBack?.Invoke(); } else { loadFailedCallBack?.Invoke(); } bundleCreateRequests.Remove(bundleName); } else { Log.Error("Bundle not exist", bundleName); loadFailedCallBack?.Invoke(); yield break; } } else { loadSucceedCallBack?.Invoke(); } }
public bool CheckBundleExistInLocalFile(string name) { return(File.Exists(Path.Combine(AssetPathManager.GetAssetBundleOutPutPath(), name))); }
/// <summary> /// 从远程下载bundle /// ! 测试使用mac本地服务器 url地址配置在GameCanstants中 /// </summary> /// <param name="bundleName"></param> /// <param name="downloadSucceedCallBack"></param> /// <param name="downloadFailedCallBack">范</param> /// <returns></returns> public IEnumerator CheckDownloadBundleFromRemoteServer(BundleCacheItem cacheItem, Action downloadSucceedCallBack = null, Action downloadFailedCallBack = null, Action <float> downloadingCallBack = null) { if (!cacheItem.NeedDownload()) { downloadSucceedCallBack?.Invoke(); yield break; } string _bundleName = cacheItem.BundleName; string downloadUrl = GetBundleRemoteUrl(_bundleName, cacheItem.BundleVersion); if (string.IsNullOrEmpty(downloadUrl)) { yield break; } UnityEngine.Networking.UnityWebRequest request = UnityWebRequest.Get(downloadUrl); request.timeout = 600; bundleWebRequests.Add(_bundleName, request); request.SendWebRequest(); int displayProgress = 1; int toProgress = 0; while (!request.isDone) { toProgress = (int)(100 * request.downloadProgress); while (displayProgress <= toProgress) { downloadingCallBack?.Invoke((float)displayProgress / 100.0f); yield return(GameConstants.Wait1In60Second); displayProgress++; } yield return(GameConstants.Wait1In60Second); } toProgress = 100; while (displayProgress <= toProgress) { downloadingCallBack?.Invoke((float)displayProgress / 100.0f); yield return(GameConstants.Wait1In60Second); displayProgress++; } if (request.isHttpError || request.isNetworkError) { Log.Error(request.error); //TODO display dialog yield break; } string localSavePath = Path.Combine(AssetPathManager.GetAssetBundleOutPutPath(), cacheItem.BundleName); //*删除旧版本bundle */ try { string dicPath = Path.GetDirectoryName(localSavePath); if (!Directory.Exists(dicPath)) { Directory.CreateDirectory(dicPath); File.Delete(localSavePath); } } catch (Exception ex) { Log.Error(ex.Message); } var data = request.downloadHandler.data; try { string dicPath = Path.GetDirectoryName(localSavePath); if (!Directory.Exists(dicPath)) { Directory.CreateDirectory(dicPath); } File.WriteAllBytes(localSavePath, data); } catch (Exception e) { Log.Error(e.Message); } // yield return GameConstants.Wait2In10Second; bundleWebRequests.Remove(_bundleName); request.Dispose(); downloadSucceedCallBack?.Invoke(); }