Unity 获取Editor中的内置图标
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace XRL
{
public sealed class GUIIcon : EditorWindow
{
[MenuItem("XRL/Open GUIIcon")]
private static void OpenGUIIcon()
{
icons = new List<Texture>(Resources.FindObjectsOfTypeAll<Texture>());
GetWindow<GUIIcon>().Show();
}
private Vector2 scrollPosition;
private static List<Texture> icons;
private string searchContent = "";
private const float width = 50f;
private void OnGUI()
{
GUILayout.BeginHorizontal("Toolbar");
{
GUILayout.Label("Search:", GUILayout.Width(50));
searchContent = GUILayout.TextField(searchContent, "SearchTextField");
}
GUILayout.EndHorizontal();
scrollPosition = GUILayout.BeginScrollView(scrollPosition);
{
List<string> matchNames = new List<string>();
for (int i = 0; i < icons.Count; i++)
{
if (!icons[i].name.Equals(string.Empty) && icons[i].name.ToLower().Contains(searchContent.ToLower()))
{
matchNames.Add(icons[i].name);
}
}
int count = Mathf.RoundToInt(position.width / (width + 3f));
for (int i = 0; i < matchNames.Count; i += count)
{
GUILayout.BeginHorizontal();
for (int j = 0; j < count; j++)
{
int index = i + j;
if (index < matchNames.Count)
{
if (GUILayout.Button(EditorGUIUtility.IconContent(matchNames[index]), GUILayout.Width(width), GUILayout.Height(30)))
{
EditorGUIUtility.systemCopyBuffer = matchNames[index];
Debug.Log(matchNames[index]);
}
}
}
GUILayout.EndHorizontal();
}
}
GUILayout.EndScrollView();
}
}
}