@@ -302,6 +302,11 @@ public override void OnGui(Rect rect)
302
302
303
303
private class HierarchyTreeLinesLabel : HierarchyPropertyLabel , IDisposable
304
304
{
305
+ //TODO: properties to expose when switching to SerializedReference-based implementation:
306
+ // - color
307
+ // - isDashed
308
+ // - tickness
309
+
305
310
private const float firstElementWidthOffset = 4.0f ;
306
311
307
312
#if UNITY_2019_1_OR_NEWER
@@ -312,6 +317,7 @@ private class HierarchyTreeLinesLabel : HierarchyPropertyLabel, IDisposable
312
317
private const float startXPosition = 0.0f ;
313
318
#endif
314
319
private const float columnSize = 14.0f ;
320
+ private const bool isDashed = true ;
315
321
316
322
private readonly List < TreeLineLevelRenderer > levelRenderers = new List < TreeLineLevelRenderer > ( ) ;
317
323
@@ -348,15 +354,14 @@ public sealed override void OnGui(Rect rect)
348
354
itemRenderCount ++ ;
349
355
350
356
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 ;
353
358
354
359
var targetTransform = target . transform ;
355
360
var siblingIndex = targetTransform . GetSiblingIndex ( ) ;
356
361
357
362
if ( levels > levelRenderers . Count )
358
363
{
359
- //initialize missing tree line level render
364
+ //initialize missing tree line level renderer
360
365
var startIndex = levelRenderers . Count ;
361
366
int x ;
362
367
for ( x = startIndex ; x < levels ; x ++ )
@@ -413,34 +418,33 @@ public void Initialize(Transform transform)
413
418
414
419
public void OnGUI ( Rect rect , GameObject target , int siblingIndex , bool isCurrentLevel )
415
420
{
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
+ } ;
421
425
422
426
if ( isCurrentLevel )
423
427
{
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 ;
426
431
if ( GetParentChildCount ( target ) == ( siblingIndex + 1 ) )
427
432
{
428
433
renderedLastLevelGameobject = true ;
429
- label = hasChildren ? Style . treeElementLastHalf : Style . treeElementLast ;
434
+ HierarchyTreeUtility . DrawCornerLine ( rect , isDashed , Style . treeLineTickness , Style . treeLineColor , offset , horizontalSizeOffset ) ;
430
435
}
431
436
else
432
437
{
433
438
renderedLastLevelGameobject = false ;
434
- label = hasChildren ? Style . treeElementCrossHalf : Style . treeElementCross ;
439
+ HierarchyTreeUtility . DrawCrossLine ( rect , isDashed , Style . treeLineTickness , Style . treeLineColor , offset , horizontalSizeOffset ) ;
435
440
}
436
441
437
- EditorGUI . LabelField ( rect , label , Style . treeElementStyle ) ;
438
442
return ;
439
443
}
440
444
441
445
if ( ! renderedLastLevelGameobject )
442
446
{
443
- EditorGUI . LabelField ( rect , Style . treeElementPass , Style . treeElementStyle ) ;
447
+ HierarchyTreeUtility . DrawPassingLine ( rect , isDashed , Style . treeLineTickness , Style . treeLineColor , offset ) ;
444
448
}
445
449
}
446
450
@@ -462,34 +466,22 @@ private int GetParentChildCount(Transform transform)
462
466
}
463
467
}
464
468
}
465
- #endregion
469
+ #endregion
466
470
467
471
protected static class Style
468
472
{
469
473
internal static readonly float minWidth = 17.0f ;
470
474
internal static readonly float maxWidth = 60.0f ;
475
+ internal static readonly float treeLineTickness = 0.75f ;
471
476
472
477
internal static readonly GUIStyle defaultAlignTextStyle ;
473
478
internal static readonly GUIStyle centreAlignTextStyle ;
474
479
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 ;
482
480
483
- internal static readonly Color characterColor ;
481
+ internal static readonly Color treeLineColor = Color . white ;
484
482
485
483
static Style ( )
486
484
{
487
- treeElementLast = new GUIContent ( "└--" ) ;
488
- treeElementLastHalf = new GUIContent ( "└-" ) ;
489
- treeElementCross = new GUIContent ( "├--" ) ;
490
- treeElementCrossHalf = new GUIContent ( "├-" ) ;
491
- treeElementPass = new GUIContent ( "│" ) ;
492
-
493
485
defaultAlignTextStyle = new GUIStyle ( EditorStyles . miniLabel )
494
486
{
495
487
#if UNITY_2019_3_OR_NEWER
@@ -518,16 +510,6 @@ static Style()
518
510
alignment = TextAnchor . UpperRight
519
511
#endif
520
512
} ;
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
- }
531
513
}
532
514
}
533
515
}
0 commit comments