-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace GUIContent-based tree lines with rect rextures; update defaul…
…t settings
- Loading branch information
Showing
5 changed files
with
136 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
Assets/Editor Toolbox/Editor/Hierarchy/HierarchyTreeUtility.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Toolbox.Editor.Hierarchy | ||
{ | ||
internal static class HierarchyTreeUtility | ||
{ | ||
private const float dashLength = 4.0f; | ||
private const float spaceLength = 1.0f; | ||
|
||
private static Rect GetLineRect(Rect rect, float thickness, float padding, bool horizontal) | ||
{ | ||
return horizontal | ||
? new Rect(rect.x, rect.y + padding / 2, rect.width, thickness) | ||
: new Rect(rect.x + padding / 2, rect.y, thickness, rect.height); | ||
} | ||
|
||
private static void DrawVerticalLine(Rect rect, bool isDashed, float tickness, Color color) | ||
{ | ||
DrawVerticalLine(rect, isDashed, tickness, color, 0.0f); | ||
} | ||
|
||
private static void DrawVerticalLine(Rect rect, bool isDashed, float tickness, Color color, float paddingOffset) | ||
{ | ||
rect = GetLineRect(rect, tickness, rect.width - paddingOffset, false); | ||
if (!isDashed) | ||
{ | ||
EditorGUI.DrawRect(rect, color); | ||
return; | ||
} | ||
|
||
var dashesCount = rect.height / (dashLength + spaceLength); | ||
var maxY = rect.yMax; | ||
|
||
rect.yMax = rect.yMin + dashLength; | ||
for (var i = 0; i < dashesCount; i++) | ||
{ | ||
EditorGUI.DrawRect(rect, color); | ||
rect.y += dashLength + spaceLength; | ||
if (rect.yMax > maxY) | ||
{ | ||
rect.yMax = maxY; | ||
} | ||
} | ||
} | ||
|
||
private static void DrawHorizontalLine(Rect rect, bool isDashed, float tickness, Color color) | ||
{ | ||
DrawHorizontalLine(rect, isDashed, tickness, color, 0.0f); | ||
} | ||
|
||
private static void DrawHorizontalLine(Rect rect, bool isDashed, float tickness, Color color, float paddingOffset) | ||
{ | ||
rect = GetLineRect(rect, tickness, rect.height - paddingOffset, true); | ||
if (!isDashed) | ||
{ | ||
EditorGUI.DrawRect(rect, color); | ||
return; | ||
} | ||
|
||
var dashesCount = rect.width / (dashLength + spaceLength); | ||
var maxX = rect.xMax; | ||
|
||
rect.xMax = rect.xMin + dashLength; | ||
for (var i = 0; i < dashesCount; i++) | ||
{ | ||
EditorGUI.DrawRect(rect, color); | ||
rect.x += dashLength + spaceLength; | ||
if (rect.xMax > maxX) | ||
{ | ||
rect.xMax = maxX; | ||
} | ||
} | ||
} | ||
|
||
public static void DrawPassingLine(Rect rect, bool isDashed, float tickness, Color color, Vector2 paddingOffset) | ||
{ | ||
DrawVerticalLine(rect, isDashed, tickness, color, paddingOffset.x); | ||
} | ||
|
||
public static void DrawCornerLine(Rect rect, bool isDashed, float tickness, Color color, Vector2 paddingOffset, float horizontalSizeOffset) | ||
{ | ||
//NOTE: -1 as a offset for halfs in corners | ||
var verticalRect = rect; | ||
verticalRect.yMax -= verticalRect.height / 2 - 1; | ||
DrawVerticalLine(verticalRect, isDashed, tickness, color, paddingOffset.x); | ||
|
||
var horizontalRect = rect; | ||
horizontalRect.xMin += horizontalRect.width / 2; | ||
horizontalRect.xMax += horizontalSizeOffset; | ||
DrawHorizontalLine(horizontalRect, isDashed, tickness, color, paddingOffset.y); | ||
} | ||
|
||
public static void DrawCrossLine(Rect rect, bool isDashed, float tickness, Color color, Vector2 paddingOffset, float horizontalSizeOffset) | ||
{ | ||
DrawVerticalLine(rect, isDashed, tickness, color, paddingOffset.x); | ||
|
||
rect.xMin += rect.width / 2; | ||
rect.xMax += horizontalSizeOffset; | ||
DrawHorizontalLine(rect, isDashed, tickness, color, paddingOffset.y); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Editor Toolbox/Editor/Hierarchy/HierarchyTreeUtility.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters