加载内置资源。
此函数将在 Assets/Editor Default Resources/ + path 中查找资源。如果未找到,它将尝试按名称查找内置编辑器资源。
using UnityEngine; using UnityEditor;
public class LoadExample { [MenuItem("Examples/Load Editor Texture Example")] static void loadExample() { Texture tex = (Texture)EditorGUIUtility.Load("aboutwindow.mainheader"); Debug.Log("Got: " + tex.name + " !");
Renderer r = GameObject.Find("Cube").GetComponent<Renderer>(); r.sharedMaterial.mainTexture = tex; } }