Version: 2021.1

AssetDatabase.GetAssetBundleDependencies

切换到手册
public static string[] GetAssetBundleDependencies (string assetBundleName, bool recursive);

参数

assetBundleName 需要依赖项的 AssetBundle 的名称。
recursive 如果为 false,仅返回其为输入直接依赖项的 AssetBundle;如果为 true,则包含输入的所有间接依赖项。

返回

string[] 输入依赖的所有 AssetBundle 的名称。

描述

给定一个 assetBundleName,返回其依赖的 AssetBundle 列表。

using System.Text;
using UnityEditor;
using UnityEngine;

public class AssetDatabaseExamples : MonoBehaviour { [MenuItem("AssetDatabase/Find Bundles With Dependencies")] static void BundleDependency() { var allBundleNames = AssetDatabase.GetAllAssetBundleNames(); foreach (var bundle in allBundleNames) { var dependencies = AssetDatabase.GetAssetBundleDependencies(bundle, true); if (dependencies.Length == 0) continue; var dependencyString = new StringBuilder(); foreach (var dependency in dependencies) { dependencyString.Append($"\"{dependency}\" "); } Debug.Log($"{bundle} depends on {dependencyString}"); } } }