Skip to content

Commit

Permalink
Cleaned up the code. Fixed prefab tree lines rendering bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Grizmu committed Aug 11, 2024
1 parent f4dc26c commit d1b1878
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions Assets/Editor Toolbox/Editor/Hierarchy/HierarchyPropertyLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public override sealed void OnGui(Rect rect)
return;
}

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

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

int siblingIndex = target.transform.GetSiblingIndex();
var transf = target.transform;
var siblingIndex = transf.GetSiblingIndex();

if (levels > levelRenderers.Count)
{
//Initialize missing tree line level render
int startIndex = levelRenderers.Count;
var startIndex = levelRenderers.Count;
int x;
for (x = startIndex; x < levels; x++)
{
var levelRenderer = new TreeLineLevelRenderer(x + 1);
var levelRenderer = new TreeLineLevelRenderer();
levelRenderers.Add(levelRenderer);
}

x--;
Transform transf = target.transform;

Transform transfBuf = transf;
for (; x >= startIndex; x--)
{
levelRenderers[x].Initialize(transf);
transf = transf.parent;
levelRenderers[x].Initialize(transfBuf);
transfBuf = transfBuf.parent;
}
}

Expand All @@ -387,16 +388,10 @@ public override sealed void OnGui(Rect rect)
private class TreeLineLevelRenderer
{
private bool renderedLastLevelGameobject = false;
private int level;

public TreeLineLevelRenderer(int level)
{
this.level = level;
}

public void Initialize(Transform transf)
{
int siblingIndex = transf.GetSiblingIndex();
var siblingIndex = transf.GetSiblingIndex();
renderedLastLevelGameobject = GetParentChildCount(transf) == (siblingIndex + 1);
}

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

private int GetParentChildCount(Transform target)
{
if (level == 1)
{
var scene = target.gameObject.scene;
return scene.rootCount;
}
else
var parent = target.parent;
if (parent != null)
{
var parent = target.parent;
return parent.childCount;
}

var scene = target.gameObject.scene;
return scene.rootCount;
}

private int GetParentChildCount(GameObject target)
Expand Down

0 comments on commit d1b1878

Please sign in to comment.