Skip to content

Commit 67c5548

Browse files
committed
Add folder color picker dynamic icons
closed when unselected, open when selected
1 parent ad3a04e commit 67c5548

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

Editor/FolderEditor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
22
using UnityEditor;
33
using UnityEditor.Experimental;
44
using UnityEngine;
@@ -41,8 +41,8 @@ private void DoIconColorPicker()
4141
int index = 1 + column + row * HierarchyFolderIcon.IconColumnCount;
4242
float width = gridRect.width / HierarchyFolderIcon.IconColumnCount;
4343
float height = gridRect.height / HierarchyFolderIcon.IconRowCount;
44-
Rect rect = new Rect(gridRect.x + width * column, gridRect.y + height * row, width, height);
45-
var (icon, _) = HierarchyFolderIcon.coloredFolderIcons[index];
44+
var rect = new Rect(gridRect.x + width * column, gridRect.y + height * row, width, height);
45+
var (openIcon, closeIcon) = HierarchyFolderIcon.ColoredFolderIcons(index);
4646

4747
if (Event.current.type == EventType.Repaint)
4848
{
@@ -60,7 +60,7 @@ private void DoIconColorPicker()
6060
}
6161
}
6262

63-
if (GUI.Button(rect, icon, EditorStyles.label))
63+
if (GUI.Button(rect, currentIndex == index ? openIcon : closeIcon, EditorStyles.label))
6464
{
6565
Undo.RecordObject(target, "Set Folder Color");
6666
colorIndexProperty.intValue = currentIndex == index ? 0 : index;

Editor/HierarchyFolderIcon.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public class HierarchyFolderIcon
4040
private static MethodInfo meth_isExpanded;
4141
private static MethodInfo meth_getAllSceneHierarchyWindows;
4242

43-
private static (Texture2D, Texture2D)[] _coloredFolderIcons;
44-
public static (Texture2D, Texture2D)[] coloredFolderIcons => _coloredFolderIcons;
43+
private static (Texture2D open, Texture2D closed)[] _coloredFolderIcons;
44+
public static (Texture2D open, Texture2D closed) ColoredFolderIcons(int i) => _coloredFolderIcons[i];
4545

4646
public static int IconColumnCount => IconColors.GetLength(0);
4747
public static int IconRowCount => IconColors.GetLength(1);
@@ -202,13 +202,10 @@ private static void RefreshFolderIcons(int instanceid, Rect selectionrect)
202202
var itemObject = (Object) prop_objectPPTR.GetValue(item);
203203
if (!Folder.TryGetIconIndex(itemObject, out int colorIndex)) { continue; }
204204

205-
206205
var isExpanded = (bool) meth_isExpanded.Invoke(data, new object[] { item });
207206

208-
Texture2D open, closed;
209-
var count = _coloredFolderIcons.Length;
210-
(open, closed) = coloredFolderIcons[Mathf.Clamp(colorIndex, 0, count) % count];
211-
item.icon = isExpanded ? open : closed;
207+
var icons = ColoredFolderIcons(Mathf.Clamp(colorIndex, 0, _coloredFolderIcons.Length - 1));
208+
item.icon = isExpanded ? icons.open : icons.closed;
212209

213210
prop_selectedIcon.SetValue(item, isExpanded ? openFolderSelectedTexture : closedFolderSelectedTexture);
214211
}

0 commit comments

Comments
 (0)