Skip to content

Commit 4eca0ee

Browse files
committed
Merge branch 'develop' into feature/custom-contex-menu-controller
2 parents 17c5c66 + 0b53887 commit 4eca0ee

3 files changed

Lines changed: 107 additions & 6 deletions

File tree

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ public override float GetWidth()
179179

180180
private class HierarchyScriptLabel : HierarchyPropertyLabel
181181
{
182+
//TODO: properties to expose when switching to SerializedReference-based implementation:
183+
// - max components
184+
// - how to render standard scripts without custom icons
185+
186+
private const int maxComponents = 5;
187+
188+
private static readonly GUIContent moreLabelContent = new GUIContent("...");
189+
182190
private static Texture componentIcon;
183191
private static Texture transformIcon;
184192
private static Texture warningIcon;
@@ -248,8 +256,15 @@ public override bool Prepare(GameObject target, Rect availableRect)
248256
baseWidth = Style.minWidth;
249257
components = target.GetComponents<Component>();
250258
var componentsCount = components.Length;
259+
//NOTE: ignore transform for >1 components
260+
var componentsToDisplay = componentsCount - 1;
261+
if (componentsToDisplay > maxComponents)
262+
{
263+
componentsToDisplay = maxComponents + 1;
264+
}
265+
251266
summWidth = componentsCount > 1
252-
? (componentsCount - 1) * baseWidth
267+
? componentsToDisplay * baseWidth
253268
: baseWidth;
254269

255270
isHighlighted = availableRect.Contains(Event.current.mousePosition);
@@ -275,20 +290,32 @@ public override void OnGui(Rect rect)
275290
return;
276291
}
277292

278-
rect.xMin -= baseWidth * (componentsCount - 2);
293+
//NOTE: we are already in appropriate position for the first component, let's move it depending on the count
294+
var componentsToDisplay = componentsCount - 1;
295+
if (componentsToDisplay > maxComponents)
296+
{
297+
//NOTE: one additional place for "more"
298+
componentsToDisplay = maxComponents + 1;
299+
}
300+
301+
rect.xMin -= baseWidth * (componentsToDisplay - 1);
279302

280303
var iconRect = rect;
281304
iconRect.xMin = rect.xMin;
282305
iconRect.xMax = rect.xMin + baseWidth;
283306

284-
//draw all icons associated to cached components (except transform)
285-
for (var i = 1; i < components.Length; i++)
307+
//NOTE: draw all icons associated to cached components (except transform)
308+
for (var i = 1; i < componentsCount; i++)
286309
{
310+
if (i > maxComponents)
311+
{
312+
GUI.Label(iconRect, moreLabelContent);
313+
break;
314+
}
315+
287316
var component = components[i];
288317
var content = GetContent(component);
289-
//draw icon for the current component
290318
GUI.Label(iconRect, content);
291-
//adjust rect for the next script icon
292319
iconRect.x += baseWidth;
293320
}
294321

Assets/Editor Toolbox/Editor/Hierarchy/HierarchyTreeUtility.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Toolbox.Editor.Hierarchy
88
/// </summary>
99
internal static class HierarchyTreeUtility
1010
{
11+
//NOTE: consider caching pre-created texturess for dashed lines and use them to optimize each call
1112
private const float dashLength = 4.0f;
1213
private const float spaceLength = 1.0f;
1314

Assets/Examples/Scenes/SampleScene.unity

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,12 @@ GameObject:
468468
- component: {fileID: 580334320}
469469
- component: {fileID: 580334319}
470470
- component: {fileID: 580334318}
471+
- component: {fileID: 580334325}
471472
- component: {fileID: 580334317}
473+
- component: {fileID: 580334324}
474+
- component: {fileID: 580334323}
475+
- component: {fileID: 580334322}
476+
- component: {fileID: 580334321}
472477
m_Layer: 0
473478
m_Name: GameObject (8)
474479
m_TagString: Untagged
@@ -552,6 +557,74 @@ Transform:
552557
m_Father: {fileID: 0}
553558
m_RootOrder: 22
554559
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
560+
--- !u!65 &580334321
561+
BoxCollider:
562+
m_ObjectHideFlags: 0
563+
m_CorrespondingSourceObject: {fileID: 0}
564+
m_PrefabInstance: {fileID: 0}
565+
m_PrefabAsset: {fileID: 0}
566+
m_GameObject: {fileID: 580334316}
567+
m_Material: {fileID: 0}
568+
m_IsTrigger: 0
569+
m_Enabled: 1
570+
serializedVersion: 2
571+
m_Size: {x: 1, y: 1, z: 1}
572+
m_Center: {x: 0, y: 0, z: 0}
573+
--- !u!65 &580334322
574+
BoxCollider:
575+
m_ObjectHideFlags: 0
576+
m_CorrespondingSourceObject: {fileID: 0}
577+
m_PrefabInstance: {fileID: 0}
578+
m_PrefabAsset: {fileID: 0}
579+
m_GameObject: {fileID: 580334316}
580+
m_Material: {fileID: 0}
581+
m_IsTrigger: 0
582+
m_Enabled: 1
583+
serializedVersion: 2
584+
m_Size: {x: 1, y: 1, z: 1}
585+
m_Center: {x: 0, y: 0, z: 0}
586+
--- !u!65 &580334323
587+
BoxCollider:
588+
m_ObjectHideFlags: 0
589+
m_CorrespondingSourceObject: {fileID: 0}
590+
m_PrefabInstance: {fileID: 0}
591+
m_PrefabAsset: {fileID: 0}
592+
m_GameObject: {fileID: 580334316}
593+
m_Material: {fileID: 0}
594+
m_IsTrigger: 0
595+
m_Enabled: 1
596+
serializedVersion: 2
597+
m_Size: {x: 1, y: 1, z: 1}
598+
m_Center: {x: 0, y: 0, z: 0}
599+
--- !u!65 &580334324
600+
BoxCollider:
601+
m_ObjectHideFlags: 0
602+
m_CorrespondingSourceObject: {fileID: 0}
603+
m_PrefabInstance: {fileID: 0}
604+
m_PrefabAsset: {fileID: 0}
605+
m_GameObject: {fileID: 580334316}
606+
m_Material: {fileID: 0}
607+
m_IsTrigger: 0
608+
m_Enabled: 1
609+
serializedVersion: 2
610+
m_Size: {x: 1, y: 1, z: 1}
611+
m_Center: {x: 0, y: 0, z: 0}
612+
--- !u!54 &580334325
613+
Rigidbody:
614+
m_ObjectHideFlags: 0
615+
m_CorrespondingSourceObject: {fileID: 0}
616+
m_PrefabInstance: {fileID: 0}
617+
m_PrefabAsset: {fileID: 0}
618+
m_GameObject: {fileID: 580334316}
619+
serializedVersion: 2
620+
m_Mass: 1
621+
m_Drag: 0
622+
m_AngularDrag: 0.05
623+
m_UseGravity: 1
624+
m_IsKinematic: 0
625+
m_Interpolate: 0
626+
m_Constraints: 0
627+
m_CollisionDetection: 0
555628
--- !u!1 &661896457
556629
GameObject:
557630
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)