From d1b187820cf5027b096eb648aefea66c5511ec8a Mon Sep 17 00:00:00 2001 From: Grizmu <5132247+Grizmu@users.noreply.github.com> Date: Sun, 11 Aug 2024 14:45:27 +0200 Subject: [PATCH] Cleaned up the code. Fixed prefab tree lines rendering bug. --- .../Hierarchy/HierarchyPropertyLabel.cs | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/Assets/Editor Toolbox/Editor/Hierarchy/HierarchyPropertyLabel.cs b/Assets/Editor Toolbox/Editor/Hierarchy/HierarchyPropertyLabel.cs index ec0b3785..e3122f6a 100644 --- a/Assets/Editor Toolbox/Editor/Hierarchy/HierarchyPropertyLabel.cs +++ b/Assets/Editor Toolbox/Editor/Hierarchy/HierarchyPropertyLabel.cs @@ -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) { @@ -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; } } @@ -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); } @@ -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)