Legacy Documentation: Version 2018.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

AssetDatabase.LoadAllAssetsAtPath

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static method LoadAllAssetsAtPath(assetPath: string): Object[];
public static Object[] LoadAllAssetsAtPath(string assetPath);

Parameters

assetPathFilesystem path to the asset.

Description

Returns an array of all Assets at 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.

Note: The main asset is not guaranteed to be at index 0 in the array

See Also: AssetDatabase.LoadMainAssetAtPath, AssetDatabase.LoadAllAssetRepresentationsAtPath, AssetDatabase.AddObjectToAsset, HideFlags.HideInHierarchy.

#pragma strict
public class Example extends MonoBehaviour {
	@MenuItem("AssetDatabase/LoadAllAssetsAtPath")
	private static function PrintAssets() {
		var data: Object[] = AssetDatabase.LoadAllAssetsAtPath("Assets/MySpriteTexture.png");
		Debug.Log(data.Length + " Assets");
		for (var o: Object in data) {
			Debug.Log(o);
		}
		//  MyTexture_3 (UnityEngine.Sprite)
	}
}
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) } }

See Also: AssetDatabase.LoadAssetAtPath.

对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答