public static List <string> RemoveAssetBundleInParents(string assetPath) { List <string> removeList = new List <string>(); AssetBundleImporter importer = AssetBundleImporter.GetAtPath(assetPath); if (importer == null) { return(removeList); } AssetBundleImporter parentImporter = importer.GetParent(); while (parentImporter != null) { if (!string.IsNullOrEmpty(parentImporter.assetBundleName)) { removeList.Add(string.Format("{0}{1}", parentImporter.assetPath, string.IsNullOrEmpty(parentImporter.assetBundleVariant) ? null : string.Format("({0})", parentImporter.assetBundleVariant))); parentImporter.assetBundleName = null; } parentImporter = parentImporter.GetParent(); } return(removeList); }
public AssetBundleChecker(AssetBundleCheckerConfig config) { this.config = config; assetsPath = AssetBundleUtility.PackagePathToAssetsPath(config.PackagePath); importer = AssetBundleImporter.GetAtPath(assetsPath); }
public static void BuildPathMapping(AssetBundleManifest manifest) { mappingList.Clear(); string outputFilePath = AssetBundleUtility.PackagePathToAssetsPath(AssetBundleConfig.AssetsPathMapFileName); string[] allAssetbundles = manifest.GetAllAssetBundles(); string[] allVariants = manifest.GetAllAssetBundlesWithVariant(); List <string> assetbundlesWithoutVariant = null; List <string> variantWithoutDeplicate = null; ProsessVariant(allAssetbundles, allVariants, out assetbundlesWithoutVariant, out variantWithoutDeplicate); // 处理所有不带variants的assetbundle foreach (string assetbundle in assetbundlesWithoutVariant) { // 该assetbundle中包含的所有asset的路径(相对于Assets文件夹),如: // Assets/AssetsPackage/UI/Prefabs/View/UILoading.prefab string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetbundle); foreach (string assetPath in assetPaths) { string packagePath = AssetBundleUtility.AssetsPathToPackagePath(assetPath); if (!addressList.Contains(packagePath)) { addressList.Add(packagePath); } string mappingItem = string.Format("{0}{1}{2}", assetbundle, PATTREN, packagePath); mappingList.Add(mappingItem); } } // 处理带variants的assetbundle(已经去重) // string variant = "[" + AssetBundleConfig.VariantMapParttren + "]"; foreach (string assetbundle in variantWithoutDeplicate) { // 该assetbundle中包含的所有asset的路径(相对于Assets文件夹),如: // Assets/AssetsPackage/UI/Prefabs/Language/[Chinese]/TestVariant.prefab // Assets/AssetsPackage/UI/Prefabs/Language/[English]/TestVariant.prefab // 由于已经去重,以上条目有且仅有一条出现 string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetbundle); if (assetPaths == null || assetPaths.Length == 0) { UnityEngine.Debug.LogError("Empty assetbundle with variant : " + assetbundle); continue; } // 自本节点向上找到Assetbundle所在 AssetBundleImporter assetbundleImporter = AssetBundleImporter.GetAtPath(assetPaths[0]); while (assetbundleImporter != null && string.IsNullOrEmpty(assetbundleImporter.assetBundleVariant)) { assetbundleImporter = assetbundleImporter.GetParent(); } if (assetbundleImporter == null || string.IsNullOrEmpty(assetbundleImporter.assetBundleVariant)) { UnityEngine.Debug.LogError("Can not find assetbundle with variant : " + assetbundle); continue; } string assetbundlePath = assetbundleImporter.assetPath; if (assetbundlePath.EndsWith("/")) { assetbundlePath = assetbundlePath.Substring(0, assetbundlePath.Length - 1); } // 将拿掉[Variant]目录名如: // Assets/AssetsPackage/UI/Prefabs/Language/TestVariant.prefab // 用此种方式可以统一路径,使加载Assetbundle时的路径与具体激活的variant无关 string nowRoot = GameUtility.FormatToUnityPath(System.IO.Path.GetDirectoryName(assetbundlePath)); foreach (string assetPath in assetPaths) { string nowAsset = assetPath.Replace(assetbundlePath, ""); string nowAssetPath = nowRoot + nowAsset; string packagePath = AssetBundleUtility.AssetsPathToPackagePath(nowAssetPath); if (!addressList.Contains(packagePath)) { addressList.Add(packagePath); } string mappingItem = string.Format("{0}{1}{2}", RemoveVariantSuffix(assetbundle), PATTREN, packagePath); mappingList.Add(mappingItem); } } mappingList.Sort(); addressList.Sort(); if (!GameUtility.SafeWriteAllLines(outputFilePath, mappingList.ToArray())) { Debug.LogError("BuildPathMapping failed!!! try rebuild it again!"); } else { AssetDatabase.Refresh(); AssetBundleEditorHelper.CreateAssetbundleForCurrent(outputFilePath); Debug.Log("BuildPathMapping success..."); } AssetDatabase.Refresh(); }