AssetDatabase.GetAssetPathsFromAssetBundle

切换到手册
public static string[] GetAssetPathsFromAssetBundle (string assetBundleName);

描述

返回一个数组,其中包含使用指定资源包名称标记的所有资源的路径。

返回的所有路径均相对于项目文件夹,例如如果向资源包添加了“hello.png”,则返回“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 } }