diff --git a/Editor/HierarchyData.cs b/Editor/HierarchyData.cs index 97fd4c2..3954fe4 100644 --- a/Editor/HierarchyData.cs +++ b/Editor/HierarchyData.cs @@ -87,6 +87,7 @@ public class TreeData public bool enabled = true; public bool drawOverlayOnColoredPrefabs = true; [Range(0,3)] public float dividerHeigth = 1; + public bool drawBranchTails = true; public Color baseLevelColor = Color.gray; [System.Serializable] diff --git a/Editor/HierarchyDrawer.cs b/Editor/HierarchyDrawer.cs index e07da01..b081342 100644 --- a/Editor/HierarchyDrawer.cs +++ b/Editor/HierarchyDrawer.cs @@ -110,24 +110,24 @@ public static void DrawHalfVerticalLineFrom(Rect originalRect, bool startsOnTop, ); } - public static void DrawHorizontalLineFrom(Rect originalRect, int nestLevel, bool hasChilds) + public static void DrawHorizontalLineFrom(Rect originalRect, int nestLevel, bool hasChilds, bool isLastChildInNestingLevel) { - if(currentBranch.colors.Length<=0) return; - + if (currentBranch.colors.Length <= 0) return; + //Vertical rect, starts from the very left and then proceeds to te right EditorGUI.DrawRect( new Rect( - GetStartX(originalRect, nestLevel), - originalRect.y + originalRect.height/2f, - originalRect.height + (hasChilds ? -5 : 2), + GetStartX(originalRect, nestLevel) + (isLastChildInNestingLevel ? 0 : barWidth), + originalRect.y + originalRect.height / 2f, + originalRect.height + (hasChilds ? -5 : 2), //originalRect.height - 5, barWidth - ), + ), GetNestColor(nestLevel) ); } } - + #region Types [Serializable] @@ -143,11 +143,14 @@ struct InstanceInfo public bool isGoActive; public bool isLastElement; + public bool isLastChildInNestingLevel; public bool hasChilds; public bool topParentHasChild; public int nestingGroup; public int nestingLevel; + + public int parentId; } #endregion @@ -351,7 +354,8 @@ static void RetrieveDataFromScene() nestingLevel: 0, sceneRoots[j].transform.childCount > 0, nestingGroup: j, - isLastChild: j == sceneRoots.Length - 1 + isLastChild: j == sceneRoots.Length - 1, + -1 ); } @@ -360,7 +364,7 @@ static void RetrieveDataFromScene() } } - static void AnalyzeGoWithChildren(GameObject go, int nestingLevel, bool topParentHasChild, int nestingGroup, bool isLastChild) + static void AnalyzeGoWithChildren(GameObject go, int nestingLevel, bool topParentHasChild, int nestingGroup, bool isLastChild, int parentId) { int instanceID = go.GetInstanceID(); @@ -369,12 +373,14 @@ static void AnalyzeGoWithChildren(GameObject go, int nestingLevel, bool topParen InstanceInfo newInfo = new InstanceInfo(); newInfo.iconIndexes = new List(); newInfo.isLastElement = isLastChild && go.transform.childCount == 0; + newInfo.isLastChildInNestingLevel = isLastChild; newInfo.nestingLevel = nestingLevel; newInfo.nestingGroup = nestingGroup; newInfo.hasChilds = go.transform.childCount > 0; newInfo.isGoActive = go.activeInHierarchy; newInfo.topParentHasChild = topParentHasChild; newInfo.goName = go.name; + newInfo.parentId = parentId; if (data.prefabsData.enabled) { @@ -451,7 +457,8 @@ static void AnalyzeGoWithChildren(GameObject go, int nestingLevel, bool topParen nestingLevel + 1, topParentHasChild, nestingGroup, - j == childCount - 1 + j == childCount - 1, + instanceID ); } @@ -534,16 +541,37 @@ static void DrawCore(int instanceID, Rect selectionRect) } else { + var nestedItem = currentItem; //Draws a vertical line for each previous nesting level - for (int i = 0; i <= currentItem.nestingLevel; i++) + for (int i = currentItem.nestingLevel; i >= 0; i--) { - HierarchyRenderer.DrawVerticalLineFrom(selectionRect, i); + if (data.tree.drawBranchTails) + { + HierarchyRenderer.DrawVerticalLineFrom(selectionRect, i); + } + else + { + if (!nestedItem.isLastChildInNestingLevel) + { + HierarchyRenderer.DrawVerticalLineFrom(selectionRect, i); + } + else if (i == currentItem.nestingLevel) + { + HierarchyRenderer.DrawHalfVerticalLineFrom(selectionRect, true, i); + } + + if (!sceneGameObjects.ContainsKey(nestedItem.parentId)) + { + break; + } + nestedItem = sceneGameObjects[nestedItem.parentId]; + } } - - HierarchyRenderer.DrawHorizontalLineFrom( - selectionRect, currentItem.nestingLevel, currentItem.hasChilds - ); - + + HierarchyRenderer.DrawHorizontalLineFrom( + selectionRect, currentItem.nestingLevel, currentItem.hasChilds, currentItem.isLastChildInNestingLevel + ); + } }