public static Object[] LoadAll (string path);
public static Object[] LoadAll (string path, Type systemTypeInstance);

Parámetros

pathNombre de ruta de la carpeta de destino. Cuando se utiliza el string vacío (es decir, ""), la función cargará todo el contenido de la carpeta Resources.
systemTypeInstanceFiltro de tipo para los objetos retornados.

Descripción

Carga todos los assets en una carpeta o archivo en path en una carpeta Resources.

If path refers to a folder, all assets in the folder will be returned. If path refers to a file, only that asset will be returned. The path is relative to any Resources folder inside the Assets folder of your project.

Note: All asset names and paths in Unity use forward slashes. Paths using backslashes will not work.

// Loads all assets in the "Resources/Textures" folder
// Then picks a random one from the list.
// Note: Random.Range in this case returns [low,high)
// range, i.e. the high value is not included in the range.
using UnityEngine;

public class ExampleClass : MonoBehaviour { private Object[] textures; private GameObject go;

void Start() { textures = Resources.LoadAll("Textures", typeof(Texture2D));

foreach (var t in textures) { Debug.Log(t.name); }

go = GameObject.CreatePrimitive(PrimitiveType.Cube); }

void OnGUI() { if (GUI.Button(new Rect(10, 70, 150, 30), "Change texture")) { // change texture on cube Texture2D texture = (Texture2D)textures[Random.Range(0, textures.Length)]; go.GetComponent<Renderer>().material.mainTexture = texture; } } }

public static T[] LoadAll (string path);

Parámetros

pathNombre de ruta de la carpeta de destino. Cuando se utiliza el string vacío (es decir, ""), la función cargará todo el contenido de la carpeta Resources.

Descripción

Carga todos los assets en una carpeta o archivo en path en una carpeta Resources.

If path refers to a folder, all assets in the folder will be returned. If path refers to a file, only that asset will be returned. Only objects of type T will be returned. The path is relative to any Resources folder inside the Assets folder of your project.

The script example below shows how LoadAll can be used with Linq.

// Loads all assets in the "Resources/Textures" folder
// using Linq.
using UnityEngine;
using System.Linq;

public class ExampleClass : MonoBehaviour { void Start() { var textures = Resources.LoadAll("Textures", typeof(Texture2D)).Cast<Texture2D>().ToArray(); foreach (var t in textures) Debug.Log(t.name); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961