Version: 2020.3

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 } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961