获取unity所有Icons

 1 using UnityEngine;
 2 using UnityEditor;
 3 using System.Reflection;
 4 using System.Collections.Generic;
 5 using System;
 6 
 7 public class Script_GetIcons : EditorWindow
 8 {
 9     [MenuItem("Window/Open My Window Icons")]
10     public static void OpenMyWindow()
11     {
12         EditorWindow.GetWindow<Script_03_30>("icons");
13     }
14     private Vector2 m_Scroll;
15     private List<string> m_Icons = null;
16     void Awake()
17     {
18         m_Icons = new List<string>(); ;
19         Texture2D[] t = Resources.FindObjectsOfTypeAll<Texture2D>();
20         foreach (Texture2D x in t)
21         {
22             Debug.unityLogger.logEnabled = false;
23             GUIContent gc = EditorGUIUtility.IconContent(x.name);
24             Debug.unityLogger.logEnabled = true;
25             if (gc != null && gc.image != null)
26             {
27                 m_Icons.Add(x.name);
28             }
29         }
30         Debug.Log(m_Icons.Count);
31     }
32     void OnGUI()
33     {
34         m_Scroll = GUILayout.BeginScrollView(m_Scroll);
35         float width = 50f;
36         int count = (int)(position.width / width);
37         for (int i = 0; i < m_Icons.Count; i += count)
38         {
39             GUILayout.BeginHorizontal();
40             for (int j = 0; j < count; j++)
41             {
42                 int index = i + j;
43                 if (index < m_Icons.Count)
44                     GUILayout.Button(EditorGUIUtility.IconContent(m_Icons[index]), GUILayout.Width(width), GUILayout.Height(30));
45             }
46             GUILayout.EndHorizontal();
47         }
48 
49         EditorGUILayout.EndScrollView();
50     }
51 }

 

posted @ 2022-07-12 17:42  枫亦  阅读(11)  评论(0)    收藏  举报