Version: 2017.3

AssetDatabase.LoadAllAssetsAtPath

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

参数

assetPath 资源的文件系统路径。

描述

返回一个含 assetPath 下所有资源的数组。

Some Asset files may contain multiple sub Assets (such as a Maya file which may contain multiple Meshes and GameObjects).
All paths are relative to the project folder, for example: "Assets/MyTextures/hello.png".
This function returns the main Asset and all sub Assets at a given path, including those hidden in the Project view.

注意:主资源并不保证在数组中处于索引 0 处

另请参阅:AssetDatabase.LoadMainAssetAtPathAssetDatabase.LoadAllAssetRepresentationsAtPathAssetDatabase.AddObjectToAssetHideFlags.HideInHierarchy

using UnityEngine;
using UnityEditor;

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

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

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

// outputs: // 5 Assets // MySpriteTexture (UnityEngine.Texture2D) // MyTexture_0 (UnityEngine.Sprite) // MyTexture_1 (UnityEngine.Sprite) // MyTexture_2 (UnityEngine.Sprite) // MyTexture_3 (UnityEngine.Sprite) } }

另请参阅:AssetDatabase.LoadAssetAtPath。