Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Colors. Colors. and MORE colors. PLEASE

Discussion in 'Editor & General Support' started by MurcsRoyce, Oct 7, 2017.

?

Do we need our hierarchy to be colorful ?

  1. yes

    77.8%
  2. no

    22.2%
  1. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    36
    This is a problem. I cant be the only one. after extensive development in a single project, my eyes are in a disarray with the hierarchy. Projects tend to get big fast with many many objects in the hierarchy. Black and white will no longer be acceptable to me. As a developer I cant waste time attempting to find 1 object out of 300 within a black and white format, and searching is not good enough. I'm simply suggesting to add colors to the hierarchy please. Its not that hard and the community will love it. Also adding a (Quick function) to change any label within the entire unity interface would be great. If unity cares about its users and cares about bigger projects being released by people then this is going to be necessary for extreme developers. I hope this message finds the person who can make change.

    Thanks You
     
  2. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    2,987
    Check the assetstore, I'm pretty sure there is an asset that does most of what you want.
     
    MurcsRoyce and zombiegorilla like this.
  3. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    6,306
    MurcsRoyce and Martin_H like this.
  4. AntoineDesbiens

    AntoineDesbiens

    Joined:
    Jun 9, 2014
    Posts:
    522
    On top of that, splitting things like this actually helped me quite a bit and it makes me feel fancy. Got the idea from a #UnityTips tweet but I forgot the author's name. So, sorry whoever came up with this first!

    Oh, and please no laughing at my naming inconsistency :oops:

    Screen Shot 2017-10-07 at 9.51.18 PM.png
     
    MurcsRoyce and trappist-1 like this.
  5. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    146
    How do you do that? Are just empty GO's you name like that?
     
    MurcsRoyce likes this.
  6. AntoineDesbiens

    AntoineDesbiens

    Joined:
    Jun 9, 2014
    Posts:
    522
    Yea, and set their tag to EditorOnly so they aren't included in the build.
     
    Polymo, MurcsRoyce and dmennenoh like this.
  7. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    146
    great tip, thanks!
     
    MurcsRoyce likes this.
  8. trappist-1

    trappist-1

    Joined:
    Mar 26, 2017
    Posts:
    121
    I like the idea of adding color convention to the hierarchy, this would be awesome!

    Or even hierarchy layers...
     
    MurcsRoyce likes this.
  9. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    36
    And my hierarchy continues to grow bigger and bigger. sigh... .. . The bigger it gets the more time it takes to find things.
     
  10. trappist-1

    trappist-1

    Joined:
    Mar 26, 2017
    Posts:
    121
    Had an interesting time learning how to use the EditorApplication.hierarchyWindowItemOnGUI() delegate to manipulate the hierarchy visuals. I came up with a working concept that adds colored boxes to the left of the items list in the hierarchy.



    Note there is some bug that causes the rootObjs array to contain extra root objects each time the editor reloads a script. So any time a script is saved and the editor reloads it, then the rootObjs array will contain some new (additional) element. This does not appear to cause any significant issue other than the array possibly growing large. I am not sure exactly why it is happening though whenever the scene is (re)loaded, or when the game starts/stops that array will once again be set to the correct and expected values, so it only appears to be a minor memory leak in the editor.

    I was hoping someone out there might look over this line and possibly explain why extra root objects get added:
    Code (csharp):
    1. //This line doesn't always generate the expected results after reloading (any) script in the editor.
    2. rootObjs = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
    Another related topic.

    Please read the code comments for more info regarding the issue. Keep in mind that this was only a concept.

    HierarchyColoredMarker.cs | Place this script in a directory somewhere in your project:
    Code (csharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.Collections.Generic;
    4.  
    5. [InitializeOnLoad]
    6. public class HierarchyColoredMarker {
    7.     /*
    8.          * A script for creating a colord square to the left of the heiarchy line item.
    9.          * This script merely resides in a directory somewhere in your project.
    10.          * It is not required to add this to the scene or be attached to a gameobject.
    11.          *
    12.          * IMPORTANT!!! There is currently a bug regarding the rootObjs variable not being
    13.          * reset properly after unity re-imports a modified scrip (aka, after saving any .cs file then returning to the editor).
    14.          * However if the Scene is reloaded then the markers are aligned properly once again.
    15.          * So this script is merely a concept.
    16.          *
    17.          * Please see the function "hierarchyChanged()" to investigate why rootObjs is being set erroniously.
    18.          * Tip: after saving a .cs, notice how rootObjs grows by 1 stating that there is one extra
    19.          * root gameobject. But the heiarchy does not reflect this additional root item..??
    20.          */
    21.     #if (UNITY_EDITOR)
    22.     private static int i = 0;
    23.     private static GameObject[] rootObjs; // Array of the heiarchy root gameobjects
    24.  
    25.     public static Color recentlyUsedFontColor = Color.yellow;
    26.     public static Color recentlyUsedBackgroundColor = Color.white;
    27.  
    28.     static HierarchyColoredMarker () {
    29.         EditorApplication.hierarchyWindowItemOnGUI += hierarchyWindowOnGUI;
    30.         EditorApplication.hierarchyWindowChanged += hierarchyChanged;
    31.     }
    32.  
    33.     static void hierarchyChanged () {
    34.         // Reset the root objects with any roots objs that have been added or removed.
    35.         rootObjs = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
    36.         /*
    37.              * For some reason the rootObjs array keeps growing in size by one anytime after modifying and saving then returning to the editor.
    38.              * Which causes the final check (g.Equals(rootObjs [rootObjs.Length-1])) to evaluate incorrectly.
    39.              * And the index (i) never gets reset causing it to increase to a large value.
    40.              * For reliable usage of this script the reason for the extra hidden root gameobjects will need to be addressed.
    41.              */
    42.     }
    43.  
    44.     static void hierarchyWindowOnGUI (int instanceID, Rect selectionRect) {
    45.         GameObject g = EditorUtility.InstanceIDToObject (instanceID) as GameObject;
    46.         if (g == null) { //The first root "scene" hierarchy object.
    47.             i = 0; // Reset index because "scene" is the first root element.
    48.             return; // Return because there is no need to add marker to this unique element.
    49.         }
    50.  
    51.         i++; // Add one to the index so we have the absolute row position in the hierarchy list.
    52.  
    53.         var colors = g.GetComponent<HierarchyColorPicker> ();
    54.  
    55.         if (colors != null) { // If the current gameobject has a hiearchy colors parameters component.
    56.             GUI.contentColor = colors.fontColor;
    57.             Rect rect = new Rect (0, 16 * i, 16, 16); // The colored square.
    58.             GUI.Box (rect, "");
    59.         }
    60.         // Don't want this to highlight other parts of the heiarchy list, so set the colors back to defaults.
    61.         //if (colors == null || !colors.highlightOnSelection) { // This line didn't work correctly, and instead of highlighting the current go, it affects the subsequent one.
    62.         GUI.contentColor = Color.black;
    63.         GUI.contentColor = Color.black;
    64.  
    65.         if (rootObjs == null) return; // The scene was loading..??
    66.         //TODO check if the finalRootObj has children with colored markers, and if so, don't reset the index until the children have been updated.
    67.         var finalRootObj = rootObjs [rootObjs.Length-1]; // The absolute last root gameobject in the hierarchy.
    68.         if (g.Equals (finalRootObj)) { // Check to see if the current g    o is the last root in the hierarchy list.
    69.             i = 0; // It was the last one, now reset the index so when running through all go's again it will start from 0.
    70.         }
    71.     }
    72.     #endif
    73. }
    HierarchyColorPicker.cs | Add to any gameobject you would like accompanied by a colored marker in the hierarchy window:
    Code (csharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. public class HierarchyColorPicker : MonoBehaviour {
    5.     /*
    6.      * The color parameters for the heiarchy colord square.
    7.      * This script should be attached to any gameobject which you wish to
    8.      * have a colored marker next to it's name in the heiarchy list.
    9.      */
    10.     #if (UNITY_EDITOR)
    11.     [SerializeField]
    12.     public bool highlightOnSelection = false; // Make the heiarchy row take on the background and font colors.
    13.  
    14.     [SerializeField]
    15.     public Color fontColor = HierarchyColoredMarker.recentlyUsedFontColor;
    16.     private Color m_fontColor;
    17.  
    18.     [SerializeField]
    19.     public Color backgroundColor = HierarchyColoredMarker.recentlyUsedBackgroundColor;
    20.     private Color m_backgroundColor;
    21.  
    22.     // The following is simply for keeping track of the recently used colors.
    23.     // Allows adding new components of this type to objects with pre-set colors.
    24.     void OnValidate() {
    25.         if (fontColor != m_fontColor) {
    26.             HierarchyColoredMarker.recentlyUsedFontColor = fontColor;
    27.             m_fontColor = fontColor;
    28.         }
    29.         if (backgroundColor != m_backgroundColor) {
    30.             HierarchyColoredMarker.recentlyUsedBackgroundColor = backgroundColor;
    31.             m_backgroundColor = backgroundColor;
    32.         }
    33.     }
    34.     #endif
    35. }
    [​IMG]

    Lastly, you may notice there are two color selectors (fontColor and backgroundColor) and a boolean for highlighting when selected.
    However only the backgroundColor selector works. I left the other options for future improvements or if someone else can figure out how to make them apply to the hierarchy items.

    [UPDATE]
    I added a line to hierarchyWindowOnGUI which helps reset the index "i" and prevents the markers from "running away" and seems to have made the example much more reliable.
    Code (csharp):
    1. if (g == null) { //The first root "scene" hierarchy object.
    2.     i = 0; // Reset index because "scene" is the first root element. <<< THIS WAS ADDED
    3.     return; // Return because there is no need to add marker to this unique element.
    4. }
    The changes have been added to the example ;)
     
    Last edited: Oct 15, 2017
    MurcsRoyce likes this.
  11. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    6,306
    My tool I very creatively call "Highlighter". It highlights objects in the hierarchy and project as well with a few options. I built it to be very lightweight and easy to disable/enable and uses internal assets. I opted to store everything in a scriptable object vs. editor prefs because I wanted the settings to follow the project regardless of the machine I am on and be unique to the project and not the editor.

    Highlighter.jpg

    It's basically 2 scripts, the editor one, and the SO. When it starts up if it can't find a Settings Asset, it will create one. There is a menu item (and key command) that basically selects the Scriptable object, which has a custom inspector on it. All edits are by modifying the Settings Assets. An earlier version I made used icons and had a few other options like regular expressions, but I kept trimming it down to the stuff I actually use and doesn't impact performance.
    bigger image:
    Highlighter_big.jpg
     
    MurcsRoyce and Martin_H like this.
  12. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    36
    Thanks for the interest and help guys. Hey zombie is this in the asset store for free ? I see your screen shots and id like to test it and try its functionality. Thanks