using System.Linq; using System.Collections.Generic; using UnityEngine; using UnityEditor; using System.IO; namespace BFEditor.Build { public class ABCycleDependUtils { static AssetBundleManifest manifest; public static bool CheckABCycleDepend(string outputPath) { Debug.Log("[bfinfo]检查循环依赖..."); manifest = GetManifest(outputPath); if (manifest == null) { return true; } var result = true; var allABs = manifest.GetAllAssetBundles(); var totalCount = allABs.Length; var unit = (float)totalCount / 100; var index = 1; var i = 0; foreach (var ab in allABs) { if (i >= index * unit) { EditorUtility.DisplayProgressBar("提示", "正在检查ab循环依赖...", (float)index / 100); index++; } result = CheckCycleDepend(ab) && result; i++; } EditorUtility.ClearProgressBar(); return result; } static AssetBundleManifest GetManifest(string outputPath) { var streamPath = Path.Combine(outputPath, "asset_bundle_manifest.ab"); if (!File.Exists(streamPath)) { Debug.LogError("文件不存在 " + streamPath); return null; } var assetBundle = AssetBundle.LoadFromFile(streamPath); var manifest = assetBundle.LoadAsset("AssetBundleManifest"); assetBundle.Unload(false); return manifest; } static bool CheckCycleDepend(string assetBundle) { var result = true; var depends = manifest.GetAllDependencies(assetBundle); foreach (var depend in depends) { var depend2 = manifest.GetAllDependencies(depend); if (depend2.Contains(assetBundle)) { Debug.LogError("存在循环依赖 " + assetBundle + " " + depend); result = false; } } return result; } } }