1
- using System . Collections . Generic ;
1
+ using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Text ;
3
4
4
5
using UnityEditor ;
@@ -293,37 +294,26 @@ public override void OnGui(Rect rect)
293
294
}
294
295
}
295
296
296
- private class HierarchyTreeLinesLabel : HierarchyPropertyLabel
297
+ private class HierarchyTreeLinesLabel : HierarchyPropertyLabel , IDisposable
297
298
{
298
299
private const float firstElementWidthOffset = 4.0f ;
299
300
private const float firstElementXOffset = - 45.0f ;
300
301
private const float startXPosition = 30.0f ;
301
302
private const float columnSize = 14.0f ;
302
303
303
- private List < TreeLineLevelRenderer > levelRenderers = new List < TreeLineLevelRenderer > ( ) ;
304
+ private readonly List < TreeLineLevelRenderer > levelRenderers = new List < TreeLineLevelRenderer > ( ) ;
304
305
private int itemRenderCount = 0 ;
305
306
306
- public override sealed bool UsesWholeItemRect => true ;
307
-
308
- public override sealed bool DrawForHeaders => true ;
309
-
310
- private bool IsFirstRenderedElement => itemRenderCount == 0 ;
311
-
312
307
public HierarchyTreeLinesLabel ( )
313
308
{
314
- EditorApplication . update += ResetItemRenderCount ;
309
+ EditorApplication . update += ResetItemRenderCount ;
315
310
}
316
311
317
- ~ HierarchyTreeLinesLabel ( )
312
+ public void Dispose ( )
318
313
{
319
314
EditorApplication . update -= ResetItemRenderCount ;
320
315
}
321
316
322
- private void ResetItemRenderCount ( )
323
- {
324
- itemRenderCount = 0 ;
325
- }
326
-
327
317
public override sealed void OnGui ( Rect rect )
328
318
{
329
319
if ( Event . current . type != EventType . Repaint )
@@ -348,8 +338,8 @@ public override sealed void OnGui(Rect rect)
348
338
rect . x = startXPosition ;
349
339
rect . width = columnSize + firstElementWidthOffset ;
350
340
351
- var transf = target . transform ;
352
- var siblingIndex = transf . GetSiblingIndex ( ) ;
341
+ var targetTransform = target . transform ;
342
+ var siblingIndex = targetTransform . GetSiblingIndex ( ) ;
353
343
354
344
if ( levels > levelRenderers . Count )
355
345
{
@@ -364,14 +354,15 @@ public override sealed void OnGui(Rect rect)
364
354
365
355
x -- ;
366
356
367
- Transform transfBuf = transf ;
357
+ Transform transformBuffer = targetTransform ;
368
358
for ( ; x >= startIndex ; x -- )
369
359
{
370
- levelRenderers [ x ] . Initialize ( transfBuf ) ;
371
- transfBuf = transfBuf . parent ;
360
+ levelRenderers [ x ] . Initialize ( transformBuffer ) ;
361
+ transformBuffer = transformBuffer . parent ;
372
362
}
373
363
}
374
364
365
+ Color colorCache = GUI . color ;
375
366
GUI . color = Color . gray ;
376
367
377
368
int i = 0 ;
@@ -380,19 +371,31 @@ public override sealed void OnGui(Rect rect)
380
371
levelRenderers [ i ] . OnGUI ( rect , target , siblingIndex , false ) ;
381
372
rect . x += columnSize ;
382
373
}
374
+
383
375
levelRenderers [ i ] . OnGUI ( rect , target , siblingIndex , true ) ;
384
376
385
- GUI . color = Color . white ;
377
+ GUI . color = colorCache ;
386
378
}
387
379
380
+ private void ResetItemRenderCount ( )
381
+ {
382
+ itemRenderCount = 0 ;
383
+ }
384
+
385
+ public override sealed bool UsesWholeItemRect => true ;
386
+
387
+ public override sealed bool DrawForHeaders => true ;
388
+
389
+ private bool IsFirstRenderedElement => itemRenderCount == 0 ;
390
+
388
391
private class TreeLineLevelRenderer
389
392
{
390
393
private bool renderedLastLevelGameobject = false ;
391
394
392
- public void Initialize ( Transform transf )
395
+ public void Initialize ( Transform transform )
393
396
{
394
- var siblingIndex = transf . GetSiblingIndex ( ) ;
395
- renderedLastLevelGameobject = GetParentChildCount ( transf ) == ( siblingIndex + 1 ) ;
397
+ var siblingIndex = transform . GetSiblingIndex ( ) ;
398
+ renderedLastLevelGameobject = GetParentChildCount ( transform ) == ( siblingIndex + 1 ) ;
396
399
}
397
400
398
401
public void OnGUI ( Rect rect , GameObject target , int siblingIndex , bool isCurrentLevel )
@@ -419,27 +422,27 @@ public void OnGUI(Rect rect, GameObject target, int siblingIndex, bool isCurrent
419
422
}
420
423
}
421
424
422
- private int GetParentChildCount ( Transform target )
425
+ private int GetParentChildCount ( Transform transform )
423
426
{
424
- var parent = target . parent ;
427
+ var parent = transform . parent ;
425
428
if ( parent != null )
426
429
{
427
430
return parent . childCount ;
428
431
}
429
432
430
- var scene = target . gameObject . scene ;
433
+ var scene = transform . gameObject . scene ;
431
434
return scene . rootCount ;
432
435
}
433
436
434
- private int GetParentChildCount ( GameObject target )
437
+ private int GetParentChildCount ( GameObject gameObject )
435
438
{
436
- var parent = target . transform . parent ;
439
+ var parent = gameObject . transform . parent ;
437
440
if ( parent != null )
438
441
{
439
442
return parent . childCount ;
440
443
}
441
444
442
- var scene = target . scene ;
445
+ var scene = gameObject . scene ;
443
446
return scene . rootCount ;
444
447
}
445
448
}
0 commit comments