Skip to content

Commit 9a70230

Browse files
committed
Changed namespace, implemented right gutter
1 parent 58e50c4 commit 9a70230

File tree

1 file changed

+64
-8
lines changed

1 file changed

+64
-8
lines changed

Editor/QuickToggle.cs

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using UnityEngine;
66
using Object = UnityEngine.Object;
77

8-
namespace UnityToolbag
8+
namespace SubjectNerd.QuickToggle
99
{
1010
[InitializeOnLoad]
1111
public class QuickToggle
@@ -14,10 +14,14 @@ public class QuickToggle
1414
private const string PrefKeyShowToggle = "UnityToolbag.QuickToggle.Visible";
1515
private const string PrefKeyShowDividers = "UnityToolbag.QuickToggle.Dividers";
1616
private const string PrefKeyShowIcons = "UnityToolbag.QuickToggle.Icons";
17+
private const string PrefKeyGutterLevel = "UnityToolbag.QuickToggle.Gutter";
1718

1819
private const string MENU_NAME = "Window/Hierarchy Quick Toggle/Show Toggles";
1920
private const string MENU_DIVIDER = "Window/Hierarchy Quick Toggle/Dividers";
2021
private const string MENU_ICONS = "Window/Hierarchy Quick Toggle/Object Icons";
22+
private const string MENU_GUTTER_0 = "Window/Hierarchy Quick Toggle/Right Gutter/0";
23+
private const string MENU_GUTTER_1 = "Window/Hierarchy Quick Toggle/Right Gutter/1";
24+
private const string MENU_GUTTER_2 = "Window/Hierarchy Quick Toggle/Right Gutter/2";
2125
#endregion
2226

2327
private static readonly Type HierarchyWindowType;
@@ -45,6 +49,10 @@ private static bool SetupMenuCheckMarks()
4549
Menu.SetChecked(MENU_NAME, EditorPrefs.GetBool(PrefKeyShowToggle));
4650
Menu.SetChecked(MENU_DIVIDER, EditorPrefs.GetBool(PrefKeyShowDividers));
4751
Menu.SetChecked(MENU_ICONS, EditorPrefs.GetBool(PrefKeyShowIcons));
52+
53+
int gutterLevel = EditorPrefs.GetInt(PrefKeyGutterLevel, 0);
54+
gutterCount = gutterLevel;
55+
UpdateGutterMenu(gutterCount);
4856
return true;
4957
}
5058

@@ -63,11 +71,51 @@ private static void ToggleIcons()
6371
private static void ToggleSettings(string prefKey, string menuString, out bool valueBool)
6472
{
6573
valueBool = !EditorPrefs.GetBool(prefKey);
66-
EditorPrefs.SetBool(prefKey, valueBool);
67-
Menu.SetChecked(menuString, valueBool);
68-
EditorApplication.RepaintHierarchyWindow();
74+
EditorPrefs.SetBool(prefKey, valueBool);
75+
Menu.SetChecked(menuString, valueBool);
76+
EditorApplication.RepaintHierarchyWindow();
6977
}
70-
#endregion
78+
79+
[MenuItem(MENU_GUTTER_0, false, 40)]
80+
private static void SetGutter0() { SetGutterLevel(0); }
81+
[MenuItem(MENU_GUTTER_1, false, 41)]
82+
private static void SetGutter1() { SetGutterLevel(1); }
83+
[MenuItem(MENU_GUTTER_2, false, 42)]
84+
private static void SetGutter2() { SetGutterLevel(2); }
85+
86+
private static void SetGutterLevel(int gutterLevel)
87+
{
88+
gutterLevel = Mathf.Clamp(gutterLevel, 0, 2);
89+
EditorPrefs.SetInt(PrefKeyGutterLevel, gutterLevel);
90+
gutterCount = gutterLevel;
91+
UpdateGutterMenu(gutterCount);
92+
EditorApplication.RepaintHierarchyWindow();
93+
}
94+
95+
private static void UpdateGutterMenu(int gutterLevel)
96+
{
97+
string[] gutterKeys = new[] { MENU_GUTTER_0, MENU_GUTTER_1, MENU_GUTTER_2 };
98+
bool[] gutterValues = null;
99+
switch (gutterLevel)
100+
{
101+
case 1:
102+
gutterValues = new[] { false, true, false };
103+
break;
104+
case 2:
105+
gutterValues = new[] { false, false, true };
106+
break;
107+
default:
108+
gutterValues = new[] { true, false, false };
109+
break;
110+
}
111+
for (int i = 0; i < gutterKeys.Length; i++)
112+
{
113+
string key = gutterKeys[i];
114+
bool isChecked = gutterValues[i];
115+
Menu.SetChecked(key, isChecked);
116+
}
117+
}
118+
#endregion
71119

72120
static QuickToggle()
73121
{
@@ -134,6 +182,8 @@ public PropagateState(bool isVisibility, bool propagateValue)
134182
private static bool isFrameFresh;
135183
private static bool isMousePressed;
136184

185+
private static int gutterCount = 0;
186+
137187
private static void ResetVars()
138188
{
139189
isFrameFresh = false;
@@ -167,14 +217,20 @@ private static void DrawHierarchyItem(int instanceId, Rect selectionRect)
167217
return;
168218

169219
// Reserve the draw rects
220+
float gutterX = selectionRect.height*gutterCount;
221+
if (gutterX > 0)
222+
gutterX += selectionRect.height*0.1f;
223+
float xMax = selectionRect.xMax - gutterX;
224+
170225
Rect visRect = new Rect(selectionRect)
171226
{
172-
xMin = selectionRect.xMax - (selectionRect.height * 2.1f),
173-
xMax = selectionRect.xMax - selectionRect.height
227+
xMin = xMax - (selectionRect.height * 2.1f),
228+
xMax = xMax - selectionRect.height
174229
};
175230
Rect lockRect = new Rect(selectionRect)
176231
{
177-
xMin = selectionRect.xMax - selectionRect.height
232+
xMin = xMax - (selectionRect.height * 1.05f),
233+
xMax = xMax - (selectionRect.height * 0.05f)
178234
};
179235

180236
// Get states

0 commit comments

Comments
 (0)