Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Resources.Load 加载
# [Resources](Resources.html).Load 加载 static function *Load* (*path* : string) : [Object](../Object/Object.html) *Description* 描述 Loads an asset stored at path in the Resources folder. 加载储存在 Resources 文件夹中 path 处的资源。 Returns the asset at path if it can be found otherwise returns null. The path is relative to the Resources folder, extensions must be omitted. The Resources folder can be anywhere inside the Assets folder. 如果发现,返回所在 path 处的资源,否则返回 null。只有 type 类型的物体将被返回. Path 相对于 Resources 文件夹,扩展名必须被忽略。Resouces 文件夹可以在 Assets 文件夹中的任何位置。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Start() { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Plane); go.renderer.material.mainTexture = Resources.Load("glass"); } } ``` ``` // Assigns a texture named "Assets/Resources/glass" to a Plane. //指定一个名为"Assets/Resources/glass" 的纹理到一个平面 function Start () { var go = new GameObject.CreatePrimitive(PrimitiveType.Plane); go.renderer.material.mainTexture = Resources.Load("glass"); } ``` 另一个例子: * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Start() { GameObject instance = Instantiate(Resources.Load("enemy")); } } ``` ``` // Instantiates a prefab at the path "Assets/Resources/enemy". //在路径 "Assets/Resources/enemy"实例一个预设 function Start () { var instance : GameObject = Instantiate(Resources.Load("enemy")); } ``` •static function *Load* (*path* : string, *type* : Type) : [Object](../Object/Object.html) *Description* 描述 Loads an asset stored at path in the Resources folder. 加载储存在 Resources 文件夹中 path 处的资源。 Returns the asset at path if it can be found otherwise returns null. Only objects of type will be returned. The path is relative to the Resources folder, extensions must be omitted. The Resources folder can be anywhere inside the Assets folder. 如果发现,返回所在 path 处的资源,否则返回 null,只返回 type 的物体。路径相对于 Resources 文件夹,扩展必须被省略。Resources 文件夹可以在 Assets 文件夹内的任何地方。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Start() { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); go.renderer.material.mainTexture = Resources.Load("glass", typeof(Texture2D)); } } ``` ``` // Assigns a texture named "glass" to a Plane. //指定一个名为glass的纹理给平面 function Start () { var go = new GameObject.CreatePrimitive(PrimitiveType.Cube); go.renderer.material.mainTexture = Resources.Load("glass", Texture2D); } ``` * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Start() { GameObject instance = Instantiate(Resources.Load("enemy", typeof(GameObject))); } } ``` ``` // Instantiates a prefab named "Resources/enemy". //实例一个预设名为"Resources/enemy" function Start () { var instance : GameObject = Instantiate(Resources.Load("enemy", GameObject)); } ```
da
2022年5月23日 14:32
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码