Last active
April 28, 2022 14:52
-
-
Save baba-s/3daa1c0014813801cad3b681137cf294 to your computer and use it in GitHub Desktop.
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
using System.Collections.Generic; | |
using UnityEditor; | |
using UnityEngine; | |
[InitializeOnLoad] | |
public static class Example | |
{ | |
private const int WIDTH = 16; | |
private const int START_OFFSET_X = -22; | |
private const int OFFSET_X = -14; | |
private static readonly Color COLOR = new Color32( 104, 104, 104, 255 ); | |
private static readonly Dictionary<string, Texture> m_textureTable = new Dictionary<string, Texture>(); | |
static Example() | |
{ | |
EditorApplication.hierarchyWindowItemOnGUI += OnGUI; | |
} | |
private static void OnGUI( int instanceID, Rect selectionRect ) | |
{ | |
var gameObject = EditorUtility.InstanceIDToObject( instanceID ) as GameObject; | |
if ( gameObject == null ) return; | |
var parent = gameObject.transform.parent; | |
if ( parent == null ) return; | |
var position = selectionRect; | |
position.width = WIDTH; | |
position.x += START_OFFSET_X; | |
var oldColor = GUI.color; | |
GUI.color = COLOR; | |
if ( parent.childCount == 1 || | |
parent.GetChild( parent.childCount - 1 ) == gameObject.transform ) | |
{ | |
DrawTexture( position, "Assets/border003.png" ); | |
} | |
else | |
{ | |
DrawTexture( position, "Assets/border002.png" ); | |
} | |
while ( parent != null ) | |
{ | |
var parentParent = parent.parent; | |
if ( parentParent == null ) break; | |
if ( parent == parentParent.GetChild( parentParent.childCount - 1 ) ) | |
{ | |
parent = parentParent; | |
position.x += OFFSET_X; | |
continue; | |
} | |
position.x += OFFSET_X; | |
DrawTexture( position, "Assets/border001.png" ); | |
parent = parentParent; | |
} | |
GUI.color = oldColor; | |
} | |
private static void DrawTexture( Rect position, string path ) | |
{ | |
var image = LoadTexture( path ); | |
GUI.DrawTexture( position, image, ScaleMode.ScaleToFit ); | |
} | |
private static Texture LoadTexture( string path ) | |
{ | |
if ( m_textureTable.TryGetValue( path, out var result ) ) return result; | |
var texture = ( Texture ) EditorGUIUtility.Load( path ); | |
m_textureTable[ path ] = texture; | |
return texture; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Texture