Game.UI.Editor.EditorHierarchyUISystem
Assembly: Game
Namespace: Game.UI.Editor
Type: class
Base: UISystemBase
Summary:
Manages the Editor Hierarchy UI in Editor mode. Builds and updates a hierarchical list of editor panels and placed objects (and their sub-meshes), exposes viewport data and UI bindings, handles selection, expansion state, save/bulldoze actions and camera-mode switching. Uses Unity.Entities queries/jobs to populate and sort the hierarchy and maintains native collections (NativeList, NativeParallelHashSet) for performance. Integrates with PrefabSystem, ToolSystem, EditorPanelUISystem and CameraUpdateSystem.
Fields
-
private const string kGroup
Constant grouping key used for bindings ("editorHierarchy"). -
public Action<Entity> onSave
Callback invoked when the UI issues a "save" command for an entity. -
public Action<Entity> onBulldoze
Callback invoked when the UI issues a "bulldoze" command for an entity. -
private PrefabSystem m_PrefabSystem
Reference to the game's PrefabSystem used to resolve PrefabRefs to PrefabBase objects. -
private ToolSystem m_ToolSystem
Reference to the ToolSystem (used to set/get selected entity). -
private EditorToolUISystem m_EditorToolUISystem
Reference to the editor tool UI system used to communicate selections/submesh selections. -
private EditorPanelUISystem m_EditorPanelUISystem
Reference to the editor panel UI system used to show/hide active panels. -
private CameraUpdateSystem m_CameraUpdateSystem
Reference to the camera system used to switch camera controllers (orbit, first-person, default). -
private EntityQuery m_ObjectQuery
EntityQuery that matches placed objects (PrefabRef + Game.Objects.Object, excluding Deleted/Owner/Temp). -
private EntityQuery m_ModifiedQuery
EntityQuery that matches modified objects (Created/Updated/Deleted) used to detect hierarchy changes. -
private GetterValueBinding<Viewport> m_ViewportBinding
UI binding for the viewport object; triggers UI updates when viewport changes. -
private NativeList<HierarchyItem> m_Hierarchy
Native list used to store the current built hierarchy (panels, objects, sub-meshes). Allocated with Allocator.Persistent and disposed in OnDestroy. -
private NativeParallelHashSet<ItemId> m_ExpandedIds
Native hash set storing which ItemIds are expanded in the UI (e.g. object container or individual object entries). Allocated with Allocator.Persistent and disposed in OnDestroy. -
private int m_TotalCount
Cached total number of hierarchy items (m_Hierarchy.Length). -
private ItemId m_SelectedId
Currently selected ItemId in the hierarchy (panel, object, submesh). -
private Viewport m_Viewport
Managed Viewport instance that holds the visible range and the ViewportItem list exposed to the UI. -
private int m_NextViewportStartIndex
Next requested viewport start index (set by UI). -
private int m_NextViewportEndIndex
Next requested viewport end index (set by UI). -
private bool m_Dirty
Flag indicating the hierarchy needs a rebuild (e.g. when toggling expansion or loading). -
private ValueBinding<int> m_CameraMode
Binding storing the current camera mode value used by the UI. -
private TypeHandle __TypeHandle
Internal struct holding entity/component/buffer handles used when scheduling jobs (populated in OnCreateForCompiler). -
private const (compiler-generated job types and lambda job) ...
This class contains a Burst-compiled IJobChunk (ObjectHierarchyJob) and an inline Job that sorts the native list. The job types are private/nested and used to build/sort the hierarchy in a multi-threaded way.
Properties
-
public override GameMode gameMode => GameMode.Editor
Indicates this UI system runs only in Editor game mode. -
public List<PanelItem> panelItems { get; private set; }
List of builtin editor panels exposed in the hierarchy (Map, Climate, Water, Resources). Populated in OnCreate with their associated IEditorPanel systems.
Constructors
public EditorHierarchyUISystem()
Default constructor (compiler-preserved). Initialization of runtime-managed fields happens in OnCreate.
Methods
-
protected override void OnCreate()
Initializes system references (PrefabSystem, ToolSystem, Editor subsystems), sets up EntityQuery instances, registers UI bindings/triggers, creates panelItems, and allocates native collections (m_Hierarchy, m_ExpandedIds). Called when the system is created. -
protected override void OnGameLoaded(Context serializationContext)
Marks the hierarchy as dirty so it will be rebuilt after a saved game is loaded. -
protected override void OnStartRunning()
Clears m_ExpandedIds when the system starts running. -
protected override void OnDestroy()
Disposes native collections (m_Hierarchy, m_ExpandedIds) and calls base.OnDestroy. -
protected override void OnUpdate()
Main per-frame update: determines if hierarchy should be refreshed (m_Dirty or modified query non-empty), updates selection, updates viewport, and schedules a hierarchy rebuild job if necessary. -
private void UpdateSelection()
Synchronizes selected ItemId with EditorPanelUISystem and ToolSystem. If an object or submesh is selected sets ToolSystem.selected and instructs EditorToolUISystem to select the entity/submesh. Also refreshes camera controller to match selection and camera mode. -
private void UpdateViewport(bool force)
Clamps requested viewport range, compares to current viewport via ViewportChanged, and if different (or forced) builds the visible ViewportItem list and triggers the UI binding update. -
private bool ViewportChanged()
Compares the requested viewport range and the current ViewportItem contents against m_Hierarchy to detect whether the viewport actually changed. -
private ViewportItem BuildViewportItem(HierarchyItem item)
Converts a HierarchyItem into a ViewportItem for UI consumption. Resolves localized name and tooltip; determines whether an object entry is saveable (non-builtin prefab). -
private LocalizedString GetName(ItemId id)
Returns a localized display name for the given ItemId. For object entries it resolves the prefab name; for submeshes it resolves the submesh prefab name; otherwise returns a fallback key like "Editor.{TYPE}". -
private LocalizedString GetTooltip(ItemId id)
Returns tooltip key for the given ItemId ("Editor.{TYPE}_TOOLTIP"). -
private void UpdateHierarchy(NativeList<HierarchyItem> hierarchy)
Rebuilds the full hierarchy list. Adds the configured panelItems, then if there are placed objects and the ObjectContainer is expanded schedules ObjectHierarchyJob to append object and submesh entries. The job fills the native list and a subsequent lambda-job sorts it. -
private void SetViewportRange(int startIndex, int endIndex)
Called by UI trigger to update requested viewport start/end indexes. -
public void SetSelectedId(ItemId id)
Sets the selected item in the hierarchy. Updates ToolSystem.selected and EditorToolUISystem selection for objects/submeshes, or activates the appropriate editor panel for panel types. Also refreshes camera mode/controller. -
private void SetExpanded(ItemId id, bool expanded)
Marks the system dirty and adds/removes the ItemId from m_ExpandedIds to control what is expanded in the tree. -
private void ToggleCameraMode(CameraMode cameraMode)
Updates m_CameraMode binding and refreshes the camera controller to match the new mode. -
private void RefreshCameraController(CameraMode mode)
Switches the active camera controller on CameraUpdateSystem depending on mode and the current selection. If switching, preserves camera position by calling TryMatchPosition on the target controller. -
private int GetWidth()
Returns the stored editor hierarchy width from SharedSettings.instance?.editor?.hierarchyWidth (default fallback 350). -
private void SetWidth(int width)
Persists the supplied width into SharedSettings.instance.editor.hierarchyWidth (if settings exist). -
private void OnSave(Entity entity)
Saves the prefab of the given entity via EditorPrefabUtils.SavePrefab and unlocks a related achievement. Also invokes onSave callback if set. -
private void OnBulldoze(Entity entity)
Invokes onBulldoze callback with the given entity (UI trigger for deleting an object). -
private JobHandle EditorHierarchyUISystem_4E004959_LambdaJob_0_Execute(NativeList<HierarchyItem> hierarchy, JobHandle dependency)
Schedules a small job that sorts the hierarchy native list. (Compiler-generated helper for the inline lambda that calls hierarchy.Sort()). -
private void __AssignQueries(ref SystemState state)
Internal compiler helper used to initialize any queries for the generated code path. (Used by OnCreateForCompiler.) -
protected override void OnCreateForCompiler()
Compiler helper that assigns internal handles and queries; calls __AssignQueries and assigns TypeHandle handles. -
Nested types and jobs (summary):
- ObjectHierarchyJob (Burst-compiled IJobChunk) — iterates over object chunks, adds HierarchyItem entries for each object and optionally for its submesh children if expanded.
- EditorHierarchyUISystem_4E004959_LambdaJob_0_Job — IJob wrapper that sorts the NativeList
. - PanelItem — lightweight pairing of ItemType, level and IEditorPanel instance.
- Viewport / ViewportItem — serializable structures used as the UI viewport model.
- HierarchyItem / ItemId / ItemType — value types representing tree entries, identifiers and their kinds; ItemId supports JSON read/write and comparisons.
Usage Example
// Example usage from mod code: subscribe to onSave/onBulldoze and programmatically select an object.
var editorHierarchy = World.GetOrCreateSystemManaged<Game.UI.Editor.EditorHierarchyUISystem>();
editorHierarchy.onSave += (Entity e) => {
// Custom logic after save (e.g. show notification)
};
editorHierarchy.onBulldoze += (Entity e) => {
// Custom logic before/after bulldoze
};
// Programmatically select an object entity (matching a placed prefab entity)
var itemId = new Game.UI.Editor.EditorHierarchyUISystem.ItemId(Game.UI.Editor.EditorHierarchyUISystem.ItemType.Object, someEntity);
editorHierarchy.SetSelectedId(itemId);
// Expand the object container to see objects in the UI
var containerId = new Game.UI.Editor.EditorHierarchyUISystem.ItemId(Game.UI.Editor.EditorHierarchyUISystem.ItemType.ObjectContainer);
editorHierarchy.SetExpanded(containerId, true);
// Toggle camera mode to Orbit
editorHierarchy.ToggleCameraMode((Game.UI.Editor.EditorHierarchyUISystem.CameraMode)1); // or use named enum
Notes: - The system uses NativeList and NativeParallelHashSet; they are allocated in OnCreate and disposed in OnDestroy—do not duplicate or leak them. - The hierarchy rebuild uses Jobs/IJobChunk (Burst compiled) — changes to entity/component queries can mark the hierarchy dirty (m_ModifiedQuery).