void OnGUI() { _scroll_pos = EditorGUILayout.BeginScrollView(_scroll_pos); EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button(_refresh_button, EditorStyles.toolbarButton)) { FindIcons(); } GUILayout.FlexibleSpace(); EditorGUILayout.LabelField("Found " + _icons.Count + " icons"); EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("Double-click name to copy", TarfmagougouHelperUII.GetMiniGreyLabelStyle()); EditorGUILayout.Space(); EditorGUIUtility.labelWidth = 100; for (int i = 0; i < _icons.Count; ++i) { EditorGUILayout.LabelField(_icons[i].icon, _icons[i].name); if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown && Event.current.clickCount > 1) { string clipText = "(Texture2D)EditorGUIUtility.IconContent(\"" + _icons[i].name.text + "\").image"; EditorGUIUtility.systemCopyBuffer = clipText; } } EditorGUILayout.EndScrollView(); }
void OnGUI() { _scroll_pos = EditorGUILayout.BeginScrollView(_scroll_pos); EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button(_refresh_button, EditorStyles.toolbarButton)) { FindIcons(); } GUILayout.FlexibleSpace(); EditorGUILayout.LabelField("Found " + _icons.Count + " icons"); EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("Double-click name to copy", TarfmagougouHelperUII.GetMiniGreyLabelStyle()); EditorGUILayout.Space(); EditorGUIUtility.labelWidth = 100; var k = 0; var con = 6; var raw = Mathf.CeilToInt(_icons.Count / con); for (int j = 0; j < raw; j++) { using (var hor = new EditorGUILayout.HorizontalScope()) { for (int i = 0; i < con; ++i) { if (_icons[k].icon.image == null) { continue; } var btn = GUILayout.Button(_icons[k].icon /*, _icons[i].name*/); if (btn) { EditorGUIUtility.systemCopyBuffer = _icons[k].name.text; Debug.Log(_icons[k].name.text + " copied to clipboard."); } k++; if (k == _icons.Count) { break; } } } } EditorGUILayout.EndScrollView(); }
/* Find all textures and filter them to narrow the search. */ void FindIcons() { _icons.Clear(); Texture2D[] t = Resources.FindObjectsOfTypeAll <Texture2D>(); foreach (Texture2D x in t) { if (x.name.Length == 0) { continue; } if (x.hideFlags != HideFlags.HideAndDontSave && x.hideFlags != (HideFlags.HideInInspector | HideFlags.HideAndDontSave)) { continue; } if (!EditorUtility.IsPersistent(x)) { continue; } /* This is the *only* way I have found to confirm the icons are indeed unity builtin. Unfortunately * it uses LogError instead of LogWarning or throwing an Exception I can catch. So make it shut up. */ TarfmagougouHelperUII.DisableLogging(); GUIContent gc = EditorGUIUtility.IconContent(x.name); TarfmagougouHelperUII.EnableLogging(); if (gc == null) { continue; } if (gc.image == null) { continue; } _icons.Add(new BuiltinIcon() { icon = gc, name = new GUIContent(x.name) }); } _icons.Sort(); Resources.UnloadUnusedAssets(); System.GC.Collect(); Repaint(); }
void OnGUI() { _search = EditorGUILayout.TextField(_search); EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button(_refresh_button, EditorStyles.toolbarButton)) { FindIcons(); } GUILayout.FlexibleSpace(); EditorGUILayout.LabelField("Found " + _icons.Count + " icons"); EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("Double-click name to copy", TarfmagougouHelperUII.GetMiniGreyLabelStyle()); _scroll_pos = EditorGUILayout.BeginScrollView(_scroll_pos); EditorGUILayout.Space(); var filteredIcons = string.IsNullOrEmpty(_search) ? _icons : _icons.Where(x => x.name.text.Contains(_search)).ToList(); EditorGUIUtility.labelWidth = 100; for (int i = 0; i < filteredIcons.Count; ++i) { GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent(EditorGUIUtility.FindTexture("SceneLoadIn")), (GUIStyle)"RL FooterButton", GUILayout.Width(24))) { var savePath = EditorUtility.SaveFilePanel("Save Icon", Application.dataPath, filteredIcons[i].name.text, "png"); if (!string.IsNullOrEmpty(savePath)) { SaveTexture(savePath, (Texture2D)filteredIcons[i].icon.image); } } EditorGUILayout.LabelField(filteredIcons[i].icon, filteredIcons[i].name); GUILayout.EndHorizontal(); if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown && Event.current.clickCount > 1) { EditorGUIUtility.systemCopyBuffer = filteredIcons[i].name.text; Debug.Log(filteredIcons[i].name.text + " copied to clipboard."); } } EditorGUILayout.EndScrollView(); }
public static void ShowWindow() { UnityInternalIcons w = EditorWindow.GetWindow <UnityInternalIcons>(); TarfmagougouHelperUII.SetWindowTitle(w, "Internal Icons"); }