Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Resources.LoadAll 加载全部
# [Resources](Resources.html).LoadAll 加载全部 static function *LoadAll* (*path* : string, *type* : Type) : [Object](../Object/Object.html)[] *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 文件夹中的任何位置。 * [C#](#) * [JavaScript](#) ``` 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](../Object/Object.html)[] *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 文件夹中的任何位置。 * [C#](#) * [JavaScript](#) ``` 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; } ```
da
2022年5月23日 14:33
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码