Skip to content

Instantly share code, notes, and snippets.

@rsaenzi
Created October 20, 2021 00:01
Show Gist options
  • Save rsaenzi/f60934b8d98f886d0f643e01032d099b to your computer and use it in GitHub Desktop.
Save rsaenzi/f60934b8d98f886d0f643e01032d099b to your computer and use it in GitHub Desktop.
Script for unity to highlight a game object in the hierarchy
//
// HierarchyHighlighter.cs
//
// Created by Rigoberto Sáenz Imbacuán (https://linkedin.com/in/rsaenzi/)
// Copyright © 2021. All rights reserved.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Scripts.Utility
{
public class HierarchyHighlighter : MonoBehaviour
{
// Constants
public static readonly Color DEFAULT_BACKGROUND_COLOR = new Color(0.76f, 0.76f, 0.76f, 1f);
public static readonly Color DEFAULT_BACKGROUND_COLOR_INACTIVE = new Color(0.306f, 0.396f, 0.612f, 1f);
public static readonly Color DEFAULT_TEXT_COLOR = Color.black;
// Constructors
public HierarchyHighlighter() { }
public HierarchyHighlighter(Color inBackgroundColor)
{
this.Background_Color = inBackgroundColor;
}
public HierarchyHighlighter(Color inBackgroundColor, Color inTextColor, FontStyle inFontStyle = FontStyle.Normal)
{
this.Background_Color = inBackgroundColor;
this.Text_Color = inTextColor;
this.TextStyle = inFontStyle;
}
// Properties
[Header("Active State")]
public Color Text_Color = DEFAULT_TEXT_COLOR;
public FontStyle TextStyle = FontStyle.Normal;
/// <summary>
/// Color of the background. Set alpha 0 to not draw a background period.
/// </summary>
public Color Background_Color = DEFAULT_BACKGROUND_COLOR;
[Header("Inactive State")]
public bool Custom_Inactive_Colors = false;
public Color Text_Color_Inactive = DEFAULT_TEXT_COLOR;
public FontStyle TextStyle_Inactive = FontStyle.Normal;
/// <summary>
/// Color of the background in an inactive state. Set alpha 0 to not draw a background period.
/// </summary>
public Color Background_Color_Inactive = DEFAULT_BACKGROUND_COLOR_INACTIVE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment