/// <summary> /// 清除不再使用的ab包 /// </summary> /// <param name="deleteList"></param> public void Clear(IEnumerable <ABInfo> oldList, IEnumerable <ABInfo> newList) { var deleteList = ABUtility.GetDeleteABList(oldList, newList); foreach (var name in deleteList) { File.Delete(Path.Combine(LocalAssetBundlePath, name)); File.Delete(Path.Combine(LocalAssetBundlePath, name + ".manifest")); } // 清除空目录 ABUtility.ClearEmtry(LocalAssetBundlePath); }
private void Create() { if (string.IsNullOrEmpty(Version)) { throw new InvalidDataException("必须填写版本号"); } if (Version == GetCurrentVersion()) { Debug.LogWarning("不使用新的版本号将导致新的版本无法被察觉, 从而导致无法升级"); } if (!Directory.Exists(OutputPath)) { Directory.CreateDirectory(OutputPath); var manifest = BuildPipeline.BuildAssetBundles(OutputPath, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget); if (manifest) { CreateResourceListJsonFile(manifest); CreateVersionJsonFile(); ABUtility.ClearEmtry(OutputPath); } else { Clear(); } } else { var ab = AssetBundle.LoadFromFile(Path.Combine(OutputPath, "AssetBundles")); var oldManifest = ab.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); var oldABList = ABUtility.CreateABListFromManifest(oldManifest); ab.Unload(true); var newManifest = BuildPipeline.BuildAssetBundles(OutputPath, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget); if (newManifest) { CreateResourceListJsonFile(newManifest); CreateVersionJsonFile(); var newABList = ABUtility.CreateABListFromManifest(newManifest); var deleteList = ABUtility.GetDeleteABList(oldABList, newABList); foreach (var name in deleteList) { File.Delete(Path.Combine(OutputPath, name)); File.Delete(Path.Combine(OutputPath, name + ".manifest")); } ABUtility.ClearEmtry(OutputPath); } else { Clear(); } } }