Version: 2021.1

AssetDatabase.LoadAllAssetRepresentationsAtPath

切换到手册
public static Object[] LoadAllAssetRepresentationsAtPath (string assetPath);

描述

返回 assetPath 下所有的子资源。

此函数仅返回 Project 视图中可见的子资源。
所有路径均相对于项目文件夹,例如:“Assets/MyTextures/hello.png”

注意:可通过 AssetDatabase.AddObjectToAsset 显式添加子资源
另请参阅:AssetDatabase.LoadMainAssetAtPathAssetDatabase.LoadAllAssetsAtPathHideFlags.HideInHierarchy

using UnityEngine;
using UnityEditor;

public class Example : MonoBehaviour { [MenuItem("AssetDatabase/LoadAllAssetRepresentationsAtPath")] private static void PrintSubAssets() { Object[] data = AssetDatabase.LoadAllAssetRepresentationsAtPath("Assets/MySpriteTexture.png");

Debug.Log(data.Length + " Sub Assets");

foreach (Object o in data) { Debug.Log(o); }

// outputs: // 4 Sub Assets // MyTexture_0 (UnityEngine.Sprite) // MyTexture_1 (UnityEngine.Sprite) // MyTexture_2 (UnityEngine.Sprite) // MyTexture_3 (UnityEngine.Sprite) } }