obj | 要查询的 GameObject 或 MonoScript |
Texture2D 返回与对象关联的自定义图标。如果对象没有关联的自定义图标,则返回 null。
获取与对象关联的自定义图标。只有 GameObject 和 MonoScript 具有关联的自定义图标。
using UnityEngine; using UnityEditor;
class Example { [MenuItem("Examples/Get Icon for GameObject")] public static void GetIconForGameObject() { var go = GameObject.Find("Main Camera"); var icon = EditorGUIUtility.GetIconForObject(go); Debug.Log("Icon for " + go + " is " + icon); }
[MenuItem("Examples/Get Icon for MonoScript")] public static void GetIconForMonoScript() { var monoScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/MyMonoBehaviour.cs"); var icon = EditorGUIUtility.GetIconForObject(monoScript); Debug.Log("Icon for " + monoScript.GetClass().FullName + " is " + icon); } }