Resources.LoadAll 加载全部

static function LoadAll (path : string, type : Type) : Object[]

Description描述

Loads all assets in a folder or file at path in the Resources folder.

加载Resources文件夹中的path文件夹或者文件中的所有资源。

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 will be returned. The path is relative to the Resources folder. The Resources folder can be anywhere inside the Assets folder.

如果path是一个文件夹,文件中的所有资源都将被返回。如果path为一个文件,只有这个资源将被返回。只有type类型的物体将被返回。Path相对于Resources文件夹。Resources文件夹可以在Assets文件夹中的任何位置。

using UnityEngine;

using System.Collections;



public class example : MonoBehaviour {

	void Start() {

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

		Object[] textures = Resources.LoadAll("Textures", typeof(Texture2D));

		Texture2D texture = textures[Random.Range(0, textures.Length)];

		go.renderer.material.mainTexture = texture;

	}

}
// 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 inclusive.

//加载"Resources/Texture"文件夹中所有资源

//然后从列表中选择随机的一个

//注意:Random.Range这里返回 [低,高)范围,例如,高值不包括在内。

function Start (){

	var go = new GameObject.CreatePrimitive(PrimitiveType.Cube);

	var textures : Object[] = Resources.LoadAll("Textures", Texture2D);

	var texture : Texture2D = textures[Random.Range(0, textures.Length)];

	go.renderer.material.mainTexture = texture;

}

Resources.LoadAll 加载全部_unity3d游戏脚本制作教程-游戏蛮牛出品

Resources.LoadAll 加载全部

static function LoadAll (path : string, type : Type) : Object[]

Description描述

Loads all assets in a folder or file at path in the Resources folder.

加载Resources文件夹中的path文件夹或者文件中的所有资源。

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 will be returned. The path is relative to the Resources folder. The Resources folder can be anywhere inside the Assets folder.

如果path是一个文件夹,文件中的所有资源都将被返回。如果path为一个文件,只有这个资源将被返回。只有type类型的物体将被返回。Path相对于Resources文件夹。Resources文件夹可以在Assets文件夹中的任何位置。

using UnityEngine;

using System.Collections;



public class example : MonoBehaviour {

	void Start() {

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

		Object[] textures = Resources.LoadAll("Textures", typeof(Texture2D));

		Texture2D texture = textures[Random.Range(0, textures.Length)];

		go.renderer.material.mainTexture = texture;

	}

}
// 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 inclusive.

//加载"Resources/Texture"文件夹中所有资源

//然后从列表中选择随机的一个

//注意:Random.Range这里返回 [低,高)范围,例如,高值不包括在内。

function Start (){

	var go = new GameObject.CreatePrimitive(PrimitiveType.Cube);

	var textures : Object[] = Resources.LoadAll("Textures", Texture2D);

	var texture : Texture2D = textures[Random.Range(0, textures.Length)];

	go.renderer.material.mainTexture = texture;

}