返回介绍

Resources.Load 加载

发布于 2019-12-18 15:38:28 字数 4159 浏览 1011 评论 0 收藏 0

JavaScript => public static function Load(path: string): Object;
JavaScript => public static function Load(path: string, systemTypeInstance: Type): Object;
C# => public static Object Load(string path);
C# => public static Object Load(string path, Type systemTypeInstance);

Parameters 参数

pathPathname of the target folder.
路径名
systemTypeInstanceType filter for objects returned.
要返回的对象类型过滤器。

Description 描述

Loads an asset stored at path in a Resources folder.

加载储存在Resources文件夹中path处的资源。

Returns the asset at path if it can be found otherwise returns null. Only objects of type will be returned if this parameter is supplied. The path is relative to any Resources folder inside the Assets folder of your project, extensions must be omitted.

如果发现,返回所在path处的资源,否则返回null。如果有type参数,只有type类型的物体将被返回。 Path相对于Resources文件夹,忽略扩展名。Resouces文件夹可以在Assets文件夹中的任何位置。

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

注意:路径名使用正斜杠“/”,如果使用反斜杠“\”会不正常运行。

JavaScript:

// Assigns a texture named "Assets/Resources/glass" to a Plane.
 
function Start () {
	var go = new GameObject.CreatePrimitive(PrimitiveType.Plane);
	var rend = go.GetComponent.<Renderer>();
	rend.material.mainTexture = Resources.Load("glass") as Texture;
}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Start() {
        GameObject go = GameObject.CreatePrimitive(PrimitiveType.Plane);
        Renderer rend = go.GetComponent<Renderer>();
        rend.material.mainTexture = Resources.Load("glass") as Texture;
    }
}

JavaScript:

// Instantiates a prefab named "enemy" located in any Resources
// folder in your project's Assets folder.
 
function Start () {
	var instance : GameObject = Instantiate(Resources.Load("enemy", GameObject));
}

C#:

using UnityEngine;
 
using System.Collections;
 
 
 
public class ExampleClass : MonoBehaviour {
 
	void Start() {
 
	// Instantiates a prefab named "enemy" located in any Resources
	// folder in your project's Assets folder.
		GameObject instance = Instantiate(Resources.Load("enemy", typeof(GameObject))) as GameObject;
 
	}
 
}

JavaScript => public static function Load(path: string): T;
C# => public static T Load(string path);

Parameters 参数

pathPathname of the target folder.
路径名

Description 描述

Loads an asset stored at path in a Resources folder.

加载Resources中path处的资源。

Returns the asset at path if it can be found otherwise returns null. Only objects of type T will be returned. The path is relative to any Resources folder inside the Assets folder of your project, extensions must be omitted.

如果发现,返回所在path处的资源,否则返回null。如果有type参数,只有type类型的物体将被返回。 Path相对于Resources文件夹,忽略扩展名。Resouces文件夹可以在Assets文件夹中的任何位置。

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

注意:路径名使用正斜杠“/”,如果使用反斜杠“\”会不正常运行。

Resources

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文