返回一个包含所有标记有指定 Asset Bundle 名称的资源路径的数组。
所有返回的路径都相对于项目文件夹,例如:如果“hello.png”已添加到 Asset Bundle 中,则会返回“Assets/MyTextures/hello.png”。
using System.Collections.Generic; using UnityEditor; using UnityEngine;
public class GetAssetPathsFromAssetBundleExample : MonoBehaviour { [MenuItem("APIExamples/GetAssetPathsFromAssetBundle")] static void GatherAllAssetsInAssetBundles() { string[] allAssetBundles = AssetDatabase.GetAllAssetBundleNames();
List<string> allAssetsInAnAssetBundle = new List<string>(); for (int i = 0; i < allAssetBundles.Length; ++i) { var curBundleName = allAssetBundles[i]; var assetsInCurBundle = AssetDatabase.GetAssetPathsFromAssetBundle(curBundleName);
allAssetsInAnAssetBundle.AddRange(assetsInCurBundle); }
//allAssetsInAnAssetBundle now contains all assets that belong to an asset bundle } }