Skip to content

Commit 9dda253

Browse files
committed
Update docs; fix displaying hierarchy property labels after full-rect labels; update default settings; minor refactor changes
1 parent 491a1ed commit 9dda253

File tree

8 files changed

+57
-41
lines changed

8 files changed

+57
-41
lines changed

Assets/Editor Toolbox/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
## 0.12.13 [WIP]
1+
## 0.12.13 [19.08.2024]
22

33
### Changed:
44
- Hierarchy: Added Tree List renderer, which improves visual identification of parent and child gameobjects
55
- Fix SceneView settings change events firing when they shouldn't
6+
- Fix issue when trying to find private fields/properties from parent classes (e.g. while using conditional attributes)
7+
8+
### Added:
9+
- DisableInEditModeAttribute
610

711
## 0.12.12 [17.06.2024]
812

Assets/Editor Toolbox/Editor/Hierarchy/HierarchyPropertyLabel.cs

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Toolbox.Editor.Hierarchy
99
{
10-
//TODO: refactor
10+
//TODO: refactor: replace labels with drawers (similar approach to the Inspector), possibility to define drawers and implement them using a dedicated base class
1111

1212
/// <summary>
1313
/// Base class for all custom, Hierarchy-related labels based on targeted <see cref="GameObject"/>.
@@ -16,16 +16,6 @@ public abstract class HierarchyPropertyLabel
1616
{
1717
protected GameObject target;
1818

19-
/// <summary>
20-
/// Does this label draw over the whole item?
21-
/// </summary>
22-
public virtual bool UsesWholeItemRect { get; } = false;
23-
24-
/// <summary>
25-
/// Should this label draw for headers too?
26-
/// </summary>
27-
public virtual bool DrawForHeaders { get; } = false;
28-
2919
public virtual bool Prepare(GameObject target, Rect availableRect)
3020
{
3121
return this.target = target;
@@ -52,7 +42,6 @@ public virtual float GetWidth()
5242

5343
public abstract void OnGui(Rect rect);
5444

55-
5645
/// <summary>
5746
/// Returns built-in label class associated to provided <see cref="HierarchyItemDataType"/>.
5847
/// </summary>
@@ -77,31 +66,44 @@ public static HierarchyPropertyLabel GetPropertyLabel(HierarchyItemDataType data
7766
return null;
7867
}
7968

69+
/// <summary>
70+
/// Does this label draw over the whole item?
71+
/// </summary>
72+
public virtual bool UsesWholeItemRect { get; } = false;
73+
74+
/// <summary>
75+
/// Should this label draw for headers too?
76+
/// </summary>
77+
public virtual bool DrawForHeaders { get; } = false;
78+
8079
#region Classes: Internal
8180

8281
private class HierarchyIconLabel : HierarchyPropertyLabel
8382
{
8483
public override void OnGui(Rect rect)
8584
{
8685
var content = EditorGuiUtility.GetObjectContent(target, typeof(GameObject));
87-
if (content.image)
86+
if (content.image == null)
8887
{
89-
GUI.Label(rect, content.image);
88+
return;
9089
}
90+
91+
GUI.Label(rect, content.image);
9192
}
9293
}
9394

9495
private class HierarchyToggleLabel : HierarchyPropertyLabel
9596
{
97+
private readonly GUIContent label = new GUIContent(string.Empty, "Enable/disable GameObject");
98+
9699
public override void OnGui(Rect rect)
97100
{
98-
var content = new GUIContent(string.Empty, "Enable/disable GameObject");
99101
//NOTE: using EditorGUI.Toggle will cause bug and deselect all hierarchy toggles when you will pick a multi-selected property in the Inspector
100102
var result = GUI.Toggle(new Rect(rect.x + EditorGUIUtility.standardVerticalSpacing,
101103
rect.y,
102104
rect.width,
103105
rect.height),
104-
target.activeSelf, content);
106+
target.activeSelf, label);
105107

106108
if (rect.Contains(Event.current.mousePosition))
107109
{
@@ -116,14 +118,16 @@ public override void OnGui(Rect rect)
116118

117119
private class HierarchyTagLabel : HierarchyPropertyLabel
118120
{
121+
private const string untaggedTag = "Untagged";
122+
119123
public override float GetWidth()
120124
{
121125
return Style.maxWidth;
122126
}
123127

124128
public override void OnGui(Rect rect)
125129
{
126-
var content = new GUIContent(target.CompareTag("Untagged") ? string.Empty : target.tag, target.tag);
130+
var content = new GUIContent(target.CompareTag(untaggedTag) ? string.Empty : target.tag, target.tag);
127131
EditorGUI.LabelField(rect, content, Style.defaultAlignTextStyle);
128132
}
129133
}
@@ -165,18 +169,19 @@ private class HierarchyScriptLabel : HierarchyPropertyLabel
165169
/// </summary>
166170
private List<Component> cachedComponents;
167171

168-
169172
private void CacheComponents(GameObject target)
170173
{
171174
var components = target.GetComponents<Component>();
172175
cachedComponents = new List<Component>(components.Length);
173176
//cache only valid (non-null) components
174177
foreach (var component in components)
175178
{
176-
if (component)
179+
if (component == null)
177180
{
178-
cachedComponents.Add(component);
181+
continue;
179182
}
183+
184+
cachedComponents.Add(component);
180185
}
181186
}
182187

@@ -212,7 +217,6 @@ private GUIContent GetContent(Component component)
212217
return content;
213218
}
214219

215-
216220
public override bool Prepare(GameObject target, Rect availableRect)
217221
{
218222
var isValid = base.Prepare(target, availableRect);
@@ -302,27 +306,27 @@ private class HierarchyTreeLinesLabel : HierarchyPropertyLabel, IDisposable
302306
private const float columnSize = 14.0f;
303307

304308
private readonly List<TreeLineLevelRenderer> levelRenderers = new List<TreeLineLevelRenderer>();
309+
305310
private int itemRenderCount = 0;
306311

307312
public HierarchyTreeLinesLabel()
308313
{
309-
EditorApplication.update += ResetItemRenderCount;
314+
EditorApplication.update += ResetItemRenderCount;
310315
}
311316

312317
public void Dispose()
313318
{
314319
EditorApplication.update -= ResetItemRenderCount;
315320
}
316321

317-
public override sealed void OnGui(Rect rect)
322+
public sealed override void OnGui(Rect rect)
318323
{
319324
if (Event.current.type != EventType.Repaint)
320325
{
321326
return;
322327
}
323328

324329
var levels = (int)((rect.x + firstElementXOffset) / columnSize);
325-
326330
if (levels <= 0)
327331
{
328332
return;
@@ -354,18 +358,18 @@ public override sealed void OnGui(Rect rect)
354358

355359
x--;
356360

357-
Transform transformBuffer = targetTransform;
361+
var transformBuffer = targetTransform;
358362
for (; x >= startIndex; x--)
359363
{
360364
levelRenderers[x].Initialize(transformBuffer);
361365
transformBuffer = transformBuffer.parent;
362366
}
363367
}
364368

365-
Color colorCache = GUI.color;
369+
var colorCache = GUI.color;
366370
GUI.color = Color.gray;
367371

368-
int i = 0;
372+
var i = 0;
369373
for (; i < (levels - 1); i++)
370374
{
371375
levelRenderers[i].OnGUI(rect, target, siblingIndex, false);
@@ -382,9 +386,9 @@ private void ResetItemRenderCount()
382386
itemRenderCount = 0;
383387
}
384388

385-
public override sealed bool UsesWholeItemRect => true;
389+
public sealed override bool UsesWholeItemRect => true;
386390

387-
public override sealed bool DrawForHeaders => true;
391+
public sealed override bool DrawForHeaders => true;
388392

389393
private bool IsFirstRenderedElement => itemRenderCount == 0;
390394

@@ -463,6 +467,8 @@ protected static class Style
463467
internal static readonly GUIContent elementCross;
464468
internal static readonly GUIContent elementPass;
465469

470+
internal static readonly Color characterColor;
471+
466472
static Style()
467473
{
468474
elementLast = new GUIContent("└");
@@ -501,6 +507,11 @@ static Style()
501507
{
502508
fontSize = 18,
503509
};
510+
511+
if (!EditorGUIUtility.isProSkin)
512+
{
513+
centreAlignTreeLineStyle.normal.textColor = Color.white;
514+
}
504515
}
505516
}
506517
}

Assets/Editor Toolbox/Editor/ToolboxEditorHierarchy.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ static ToolboxEditorHierarchy()
3030
EditorApplication.hierarchyWindowItemOnGUI += OnItemCallback;
3131
}
3232

33-
3433
/// <summary>
3534
/// All valid and prepared label drawers for each item.
3635
/// </summary>
3736
private static readonly List<HierarchyPropertyLabel> propertyLabels = new List<HierarchyPropertyLabel>();
3837

39-
4038
/// <summary>
4139
/// Tries to display item label in the Hierarchy Window.
4240
/// </summary>
@@ -72,7 +70,6 @@ private static void OnItemCallback(int instanceId, Rect rect)
7270
}
7371
}
7472

75-
7673
/// <summary>
7774
/// Creates optional information about selected objects using the internal <see cref="Selection"/> class.
7875
/// </summary>
@@ -159,9 +156,13 @@ private static void DrawDefaultItemLabel(Rect rect, GameObject gameObject, strin
159156
{
160157
//each property label has to be created in validated (adjusted) area
161158
//depending on previously occupied rect we have to adjust current rect
162-
contentRect = AppendPropertyLabel(propertyLabels[i], gameObject, availableRect);
163-
availableRect.xMax -= contentRect.width;
164-
159+
var propertyLabel = propertyLabels[i];
160+
contentRect = AppendPropertyLabel(propertyLabel, gameObject, availableRect);
161+
if (!propertyLabel.UsesWholeItemRect)
162+
{
163+
availableRect.xMax -= contentRect.width;
164+
}
165+
165166
EditorGUI.DrawRect(new Rect(contentRect.xMin, rect.y, Style.lineWidth, rect.height), Style.lineColor);
166167
}
167168

@@ -181,7 +182,6 @@ private static void DrawDefaultItemLabel(Rect rect, GameObject gameObject, strin
181182
}
182183
}
183184

184-
185185
private static Rect AppendPropertyLabel(HierarchyPropertyLabel propertyLabel, GameObject target, Rect availableRect)
186186
{
187187
if (propertyLabel.UsesWholeItemRect)
@@ -315,7 +315,6 @@ internal static void RemoveAllowedHierarchyContentCallbacks()
315315

316316
internal static void RepaintHierarchyOverlay() => EditorApplication.RepaintHierarchyWindow();
317317

318-
319318
/// <summary>
320319
/// Determines if <see cref="ToolboxEditorHierarchy"/> can create an additional overlay on the Hierarchy Window.
321320
/// </summary>
@@ -325,7 +324,6 @@ internal static void RemoveAllowedHierarchyContentCallbacks()
325324
internal static bool ShowSelectionsCount { get; set; } = true;
326325
internal static bool DrawSeparationLines { get; set; } = true;
327326

328-
329327
private static class Style
330328
{
331329
internal static readonly float lineWidth = 1.0f;

Assets/Editor Toolbox/EditorSettings.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ MonoBehaviour:
1515
useToolboxHierarchy: 1
1616
drawHorizontalLines: 1
1717
showSelectionsCount: 1
18-
rowDataTypes: 0000000001000000
18+
rowDataTypes: 000000000100000005000000
1919
useToolboxFolders: 1
2020
largeIconScale: 0.8
2121
smallIconScale: 0.7

Assets/Editor Toolbox/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ Each row can contain:
842842
- Tag
843843
- Toggle to enable/disable GameObject
844844
- Icon
845+
- Tree Lines
845846

846847
![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/hierarchy.png)
847848
@@ -928,4 +929,5 @@ Assets/Create/Editor Toolbox/ScriptableObject Creation Wizard
928929

929930
Select a specific object that is under the cursor (default key: tab).
930931

932+
![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/sceneview.png)
931933
![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/sceneview.png)

Assets/Editor Toolbox/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.browar.editor-toolbox",
33
"displayName": "Editor Toolbox",
4-
"version": "0.12.12",
4+
"version": "0.12.13",
55
"unity": "2018.1",
66
"description": "Tools, custom attributes, drawers, hierarchy overlay, and other extensions for the Unity Editor.",
77
"keywords": [

Docs/hierarchy.png

5.61 KB
Loading

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ Each row can contain:
843843
- Toggle to enable/disable GameObject
844844
- Icon
845845
- Tree Lines
846+
846847
![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/hierarchy.png)
847848
848849
### Project <a name="project"></a>

0 commit comments

Comments
 (0)