Skip to content

Instantly share code, notes, and snippets.

@baba-s
Last active April 28, 2022 14:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baba-s/3daa1c0014813801cad3b681137cf294 to your computer and use it in GitHub Desktop.
Save baba-s/3daa1c0014813801cad3b681137cf294 to your computer and use it in GitHub Desktop.
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;
}
}
@baba-s
Copy link
Author

baba-s commented Jul 7, 2021

Texture

border001

border002

border003

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment