Search Unity

Get label color and icons for GameObjects and prefabs like the hierarchy window does?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Xarbrough, Jul 20, 2019.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    486
    How does Unity draw the hierarchy window labels and turns them blue for prefabs or red for missing prefabs? I know that I can get icons via AssetPreview.GetMiniThumbnail for example, but I'm wondering where to get the prefab blue from. Is there a builtin style or does Unity set GUI.contentColor? I've skimmed through the reference source for the hierarchy window, but didn't find anything related to blue labels.
     
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    486
    I've searched through the reference source quite a bit and I believe that there is no convenient method to simply get the same styling for different cases (regular GameObject, prefab, broken prefab, etc). Instead, we have to check for each object type/state and then can use builtin styles to get the same color.

    For example, prefab blue is a GUIStyle called "PR PrefabLabel".

    We can lookup other style names in the source for GameObjectTreeViewGUI.