RowContainer
Gets the VisualElement that represents the entire row container of this HierarchyViewItem.
Read time 2 minutesLast updated 12 days ago
Definition
- Type: Property
- Namespace: Unity.Hierarchy
- Assembly: UnityEngine.HierarchyModule
public VisualElement RowContainer { get; }
Remarks
The following example changes the row background color of the Hierarchy window for GameObjects that have an component attached to them. It uses to apply a custom USS class to the entire row.
EnemyRowContainerThe example requires two USS files for theme-based styling: for the Dark theme, and for the Light theme.
ChangeRowColor_dark.ussChangeRowColor_light.ussIt also requires a custom MonoBehaviour script called .
Enemy.csTo use this example:
- Save the script in a folder called . Scripts in an
Assets/Editor/ChangeRowColorfolder can use the Hierarchy module API without additional setup. If you save the script outside of anEditorfolder, you must enable the Hierarchy built-in module in the Package Manager window, which also adds the module to your Player builds.Editor - Copy the styles from the USS examples on this page. Save them in USS files called and
ChangeRowColor_dark.ussin the sameChangeRowColor_light.ussfolder.Assets/Editor/ChangeRowColor - Save the script outside of an
Enemy.csfolder, because MonoBehaviour scripts in anEditorfolder can't be attached to GameObjects.Editor - Add the component to a GameObject. The background color of the row of that GameObject changes in the Hierarchy window.
Enemy
using Unity.Hierarchy;using Unity.Hierarchy.Editor;using UnityEditor;using UnityEngine;using UnityEngine.UIElements;namespace Unity.HierarchySamples.Editor{ class ChangeRowColor { const string k_RowColorUssClassName = "gameobject--enemy"; [InitializeOnLoadMethod] static void Initialize() { HierarchyWindow.BindView += OnBindView; HierarchyWindow.BindViewItem += OnBindViewItem; } static void OnBindView(HierarchyWindow window, HierarchyView view) { // Loads a theme-specific stylesheet for light or dark Editor skin. view.styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>($"Assets/Editor/ChangeRowColor/ChangeRowColor{(EditorGUIUtility.isProSkin ? "_dark" : "_light")}.uss")); } static void OnBindViewItem(HierarchyWindow window, HierarchyView view, HierarchyViewItem item) { if (item.Handler is not HierarchyGameObjectHandler handler) return; GameObject gameObject = handler.GetGameObject(item.Node); // Checks if the GameObject has an Enemy component attached to it. You can replace "Enemy" with your own MonoBehaviour class name. item.RowContainer.EnableInClassList(k_RowColorUssClassName, gameObject.TryGetComponent<Enemy>(out _)); } }}
The following example shows how to style .
ChangeRowColor_dark.uss.gameobject--enemy { background-color: #7a2d2d;}
The following example shows how to style .
ChangeRowColor_light.uss.gameobject--enemy { background-color: #8f6464;}
The following example shows the component that the ChangeRowColor example uses.
Enemyusing UnityEngine;namespace Unity.HierarchySamples{ public class Enemy : MonoBehaviour { // Marker component used by ChangeRowColor and CustomContextMenuAction samples. }}