@@ -302,6 +302,11 @@ public override void OnGui(Rect rect)
302302
303303 private class HierarchyTreeLinesLabel : HierarchyPropertyLabel , IDisposable
304304 {
305+ //TODO: properties to expose when switching to SerializedReference-based implementation:
306+ // - color
307+ // - isDashed
308+ // - tickness
309+
305310 private const float firstElementWidthOffset = 4.0f ;
306311
307312#if UNITY_2019_1_OR_NEWER
@@ -312,6 +317,7 @@ private class HierarchyTreeLinesLabel : HierarchyPropertyLabel, IDisposable
312317 private const float startXPosition = 0.0f ;
313318#endif
314319 private const float columnSize = 14.0f ;
320+ private const bool isDashed = true ;
315321
316322 private readonly List < TreeLineLevelRenderer > levelRenderers = new List < TreeLineLevelRenderer > ( ) ;
317323
@@ -348,15 +354,14 @@ public sealed override void OnGui(Rect rect)
348354 itemRenderCount ++ ;
349355
350356 rect . x = startXPosition ;
351- //we need 2x column size for full-line cases when object has no children and there is no foldout
352- rect . width = 2 * columnSize + firstElementWidthOffset ;
357+ rect . width = columnSize + firstElementWidthOffset ;
353358
354359 var targetTransform = target . transform ;
355360 var siblingIndex = targetTransform . GetSiblingIndex ( ) ;
356361
357362 if ( levels > levelRenderers . Count )
358363 {
359- //initialize missing tree line level render
364+ //initialize missing tree line level renderer
360365 var startIndex = levelRenderers . Count ;
361366 int x ;
362367 for ( x = startIndex ; x < levels ; x ++ )
@@ -413,34 +418,33 @@ public void Initialize(Transform transform)
413418
414419 public void OnGUI ( Rect rect , GameObject target , int siblingIndex , bool isCurrentLevel )
415420 {
416- //NOTE: currently we are using labels and predefined chars to display tree lines, this is not optimal solution
417- // since we can't really control width, tickiness and other potential useful properties. Using few chars allow us
418- // to display dashed lines very easily but replacing it with standard line would a bit harder.
419- // For now this is ok solution but probably should be replaced with drawing lines using the EditorGUI.DrawRect API,
420- // in the same way we draw lines in the Inspector
421+ var offset = new Vector2 ( )
422+ {
423+ x = EditorGUIUtility . standardVerticalSpacing
424+ } ;
421425
422426 if ( isCurrentLevel )
423427 {
424- var hasChildren = target . transform . childCount > 0 ;
425- GUIContent label ;
428+ //NOTE: extend if there is no foldout button
429+ var isLineExtended = target . transform . childCount == 0 ;
430+ var horizontalSizeOffset = isLineExtended ? rect . width / 2 : 0.0f ;
426431 if ( GetParentChildCount ( target ) == ( siblingIndex + 1 ) )
427432 {
428433 renderedLastLevelGameobject = true ;
429- label = hasChildren ? Style . treeElementLastHalf : Style . treeElementLast ;
434+ HierarchyTreeUtility . DrawCornerLine ( rect , isDashed , Style . treeLineTickness , Style . treeLineColor , offset , horizontalSizeOffset ) ;
430435 }
431436 else
432437 {
433438 renderedLastLevelGameobject = false ;
434- label = hasChildren ? Style . treeElementCrossHalf : Style . treeElementCross ;
439+ HierarchyTreeUtility . DrawCrossLine ( rect , isDashed , Style . treeLineTickness , Style . treeLineColor , offset , horizontalSizeOffset ) ;
435440 }
436441
437- EditorGUI . LabelField ( rect , label , Style . treeElementStyle ) ;
438442 return ;
439443 }
440444
441445 if ( ! renderedLastLevelGameobject )
442446 {
443- EditorGUI . LabelField ( rect , Style . treeElementPass , Style . treeElementStyle ) ;
447+ HierarchyTreeUtility . DrawPassingLine ( rect , isDashed , Style . treeLineTickness , Style . treeLineColor , offset ) ;
444448 }
445449 }
446450
@@ -462,34 +466,22 @@ private int GetParentChildCount(Transform transform)
462466 }
463467 }
464468 }
465- #endregion
469+ #endregion
466470
467471 protected static class Style
468472 {
469473 internal static readonly float minWidth = 17.0f ;
470474 internal static readonly float maxWidth = 60.0f ;
475+ internal static readonly float treeLineTickness = 0.75f ;
471476
472477 internal static readonly GUIStyle defaultAlignTextStyle ;
473478 internal static readonly GUIStyle centreAlignTextStyle ;
474479 internal static readonly GUIStyle rightAlignTextStyle ;
475- internal static readonly GUIStyle treeElementStyle ;
476-
477- internal static readonly GUIContent treeElementLast ;
478- internal static readonly GUIContent treeElementLastHalf ;
479- internal static readonly GUIContent treeElementCross ;
480- internal static readonly GUIContent treeElementCrossHalf ;
481- internal static readonly GUIContent treeElementPass ;
482480
483- internal static readonly Color characterColor ;
481+ internal static readonly Color treeLineColor = Color . white ;
484482
485483 static Style ( )
486484 {
487- treeElementLast = new GUIContent ( "└--" ) ;
488- treeElementLastHalf = new GUIContent ( "└-" ) ;
489- treeElementCross = new GUIContent ( "├--" ) ;
490- treeElementCrossHalf = new GUIContent ( "├-" ) ;
491- treeElementPass = new GUIContent ( "│" ) ;
492-
493485 defaultAlignTextStyle = new GUIStyle ( EditorStyles . miniLabel )
494486 {
495487#if UNITY_2019_3_OR_NEWER
@@ -518,16 +510,6 @@ static Style()
518510 alignment = TextAnchor . UpperRight
519511#endif
520512 } ;
521- treeElementStyle = new GUIStyle ( EditorStyles . label )
522- {
523- padding = new RectOffset ( 4 , 0 , 0 , 0 ) ,
524- fontSize = 12 ,
525- } ;
526-
527- if ( ! EditorGUIUtility . isProSkin )
528- {
529- treeElementStyle . normal . textColor = Color . white ;
530- }
531513 }
532514 }
533515 }
0 commit comments