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;
}

• static function LoadAll (path : string) : 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. 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");
		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");
	var texture : Texture2D = textures[Random.Range(0, textures.Length)];
	go.renderer.material.mainTexture = texture;
}
最后修改:2011年3月13日 Sunday 20:15

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。