Skip to content

Commit d1b1878

Browse files
committed
Cleaned up the code. Fixed prefab tree lines rendering bug.
1 parent f4dc26c commit d1b1878

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

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

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public override sealed void OnGui(Rect rect)
331331
return;
332332
}
333333

334-
int levels = (int)((rect.x + firstElementXOffset) / columnSize);
334+
var levels = (int)((rect.x + firstElementXOffset) / columnSize);
335335

336336
if (levels <= 0)
337337
{
@@ -348,26 +348,27 @@ public override sealed void OnGui(Rect rect)
348348
rect.x = startXPosition;
349349
rect.width = columnSize + firstElementWidthOffset;
350350

351-
int siblingIndex = target.transform.GetSiblingIndex();
351+
var transf = target.transform;
352+
var siblingIndex = transf.GetSiblingIndex();
352353

353354
if (levels > levelRenderers.Count)
354355
{
355356
//Initialize missing tree line level render
356-
int startIndex = levelRenderers.Count;
357+
var startIndex = levelRenderers.Count;
357358
int x;
358359
for (x = startIndex; x < levels; x++)
359360
{
360-
var levelRenderer = new TreeLineLevelRenderer(x + 1);
361+
var levelRenderer = new TreeLineLevelRenderer();
361362
levelRenderers.Add(levelRenderer);
362363
}
363364

364365
x--;
365-
Transform transf = target.transform;
366366

367+
Transform transfBuf = transf;
367368
for (; x >= startIndex; x--)
368369
{
369-
levelRenderers[x].Initialize(transf);
370-
transf = transf.parent;
370+
levelRenderers[x].Initialize(transfBuf);
371+
transfBuf = transfBuf.parent;
371372
}
372373
}
373374

@@ -387,16 +388,10 @@ public override sealed void OnGui(Rect rect)
387388
private class TreeLineLevelRenderer
388389
{
389390
private bool renderedLastLevelGameobject = false;
390-
private int level;
391-
392-
public TreeLineLevelRenderer(int level)
393-
{
394-
this.level = level;
395-
}
396391

397392
public void Initialize(Transform transf)
398393
{
399-
int siblingIndex = transf.GetSiblingIndex();
394+
var siblingIndex = transf.GetSiblingIndex();
400395
renderedLastLevelGameobject = GetParentChildCount(transf) == (siblingIndex + 1);
401396
}
402397

@@ -426,16 +421,14 @@ public void OnGUI(Rect rect, GameObject target, int siblingIndex, bool isCurrent
426421

427422
private int GetParentChildCount(Transform target)
428423
{
429-
if (level == 1)
430-
{
431-
var scene = target.gameObject.scene;
432-
return scene.rootCount;
433-
}
434-
else
424+
var parent = target.parent;
425+
if (parent != null)
435426
{
436-
var parent = target.parent;
437427
return parent.childCount;
438428
}
429+
430+
var scene = target.gameObject.scene;
431+
return scene.rootCount;
439432
}
440433

441434
private int GetParentChildCount(GameObject target)

0 commit comments

Comments
 (0)