Version: 2017.2
public static Object Load (string path);
public static Object Load (string path, Type systemTypeInstance);

参数

path 目标文件夹的路径名称。使用空字符串(即 "")时,该函数将加载 Resources 文件夹的全部内容。
systemTypeInstance 返回的对象的类型筛选器。

描述

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

如果在 path 处找到指定资源,则返回该资源,否则返回 null。 如果提供该参数,则仅返回 type 类型的对象。 path 是相对于项目的 Assets 文件夹中的任何 Resources 文件夹的相对路径,必须省略扩展名。

注意:Unity 中的所有资源名称和路径都使用正斜杠。使用反斜杠的路径将无法正常工作。

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

public static T Load (string path);

参数

path 目标文件夹的路径名称。使用空字符串(即 "")时,该函数将加载 Resources 文件夹的全部内容。

描述

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

如果在 path 处找到指定资源,则返回该资源,否则返回 null。 将仅返回 T 类型的对象。 path 是相对于项目的 Assets 文件夹中的任何 Resources 文件夹的相对路径,必须省略扩展名。

注意:Unity 中的所有资源名称和路径都使用正斜杠。使用反斜杠的路径将无法正常工作。

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961