Version: 2023.2

AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName

切换到手册
public static string[] GetAssetPathsFromAssetBundleAndAssetName (string assetBundleName, string assetName);

描述

获取所有标有 assetBundleName 且有指定 assetName 的 资源的资源路径。

获取所有标有 assetBundleName 且有指定 assetName 的 资源的资源路径,与其扩展名或路径无关, 例如当 assetName 为"House"时,资产的路径可为 "Assets/House.prefab", "Assets/Textures/House.png" 和 "Assets/Data/House.xml"。

using UnityEditor;
using UnityEngine;

public class ExampleScript { [MenuItem("AssetDatabase/Display assets in an AssetBundle")] static void ExampleScriptCode1() { string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName("assetname", "House"); foreach (var assetPath in assetPaths) Debug.Log(assetPath); }

[MenuItem("AssetDatabase/AssetBundle creation")] static void ExampleScriptCode2() { BuildPipeline.BuildAssetBundles("Assets/AssetBundles", BuildAssetBundleOptions.None, BuildTarget.StandaloneOSX); } }