加载必需的内置资源。
此函数会在 Assets/Editor Default Resources/ 文件夹中查找必需的资源。以下示例显示了加载 iPhone 纹理并将其用于对一个立方体进行纹理处理。
using UnityEngine; using UnityEditor;
public class LoadRequiredExample { [MenuItem("Examples/LoadRequired Editor Example")] static void loadRequiredExample() { Texture tex = (Texture)EditorGUIUtility.LoadRequired("BuildSettings.iPhone");
Renderer r = GameObject.Find("Cube").GetComponent<Renderer>(); r.sharedMaterial.mainTexture = tex; } }