Game.UI.Editor.PrefabToolPanelSystem
Assembly: Game
Namespace: Game.UI.Editor
Type: class
Base: EditorPanelSystemBase
Summary:
PrefabToolPanelSystem is an editor UI system that implements the Prefab tool panel used in the in-game editor. It wires together PrefabSystem, ToolSystem and EditorAssetCategorySystem to build a category-based prefab picker UI (search, filter, category hierarchy, item picker and footer). It watches for prefab data changes, updates the picker adapter, and activates/deactivates the game's prefab placement tool when the user selects or cancels a prefab selection. The system also generates a default "All" category and merges it with categories provided by the EditorAssetCategorySystem.
Fields
-
private PrefabSystem m_PrefabSystem
Reference to the game's PrefabSystem used to enumerate and look up available prefabs. Acquired from the World in OnCreate. -
private ToolSystem m_ToolSystem
Reference to the ToolSystem used to activate/deactivate the prefab placement tool based on picker selection. -
private EditorAssetCategorySystem m_CategorySystem
Reference to the editor asset category system used to obtain category hierarchy and associated queries. -
private EntityQuery m_PrefabQuery
(Declared but unused in the provided code.) Intended to be an EntityQuery for general prefab access; not initialized in the shown implementation. -
private EntityQuery m_ModifiedPrefabQuery
EntityQuery configured to detect prefabs whose PrefabData components have been Created/Deleted/Updated — used to trigger UI refresh when prefab assets change. -
private PrefabPickerAdapter m_Adapter
Adapter that backs the UI: handles the search field, filter menu, item picker, favorites, and stores the current selected prefab and search query. Listens for prefab selection events and persists settings. -
private HierarchyMenu<EditorAssetCategory> m_CategoryMenu
UI widget showing a hierarchy of EditorAssetCategory items. Used for category selection that filters prefabs shown in the picker. -
private EditorAssetCategory m_AllCategory
A generated default category ("All") that matches a broad set of prefab types. Added to the top of the categories hierarchy to allow viewing all prefabs. -
private TypeHandle __TypeHandle
Compiler-generated struct instance that contains an EntityTypeHandle for use when querying prefabs from the EntityManager in a safety-checked context. -
(nested)
private struct TypeHandle
Contains an EntityTypeHandle field used to cache entity type handle access. It exposes: public EntityTypeHandle __Unity_Entities_Entity_TypeHandle
— read-only handle used by GetPrefabs calls.public void __AssignHandles(ref SystemState state)
— assigns the EntityTypeHandle from the provided SystemState (called in OnCreateForCompiler).
Properties
- This class does not expose public properties.
Constructors
public PrefabToolPanelSystem()
Parameterless constructor. The class relies on [Preserve] attributes on lifecycle methods; the constructor itself is empty and the system initializes dependencies in OnCreate.
Methods
-
protected override void OnCreate()
Initializes the system: obtains PrefabSystem, ToolSystem and EditorAssetCategorySystem from the World; constructs the m_ModifiedPrefabQuery to watch prefab changes; creates and configures the PrefabPickerAdapter and UI widget tree (PopupSearchField, FilterMenu, category HierarchyMenu, ItemPicker and ItemPickerFooter); wires up selection event handling, sets the panel title and calls GenerateCategories to prepare the default "All" category. -
protected override void OnGameLoaded(Context serializationContext)
Called after game data has been loaded; clears the adapter's search query and selected prefab to reset UI state after loading a saved game. -
protected override void OnStartRunning()
Called when the system begins running in-play: loads adapter settings, populates the category menu from GetHierarchy(), updates the prefab list, and activates the current selected prefab tool in the ToolSystem (if any). -
protected override void OnUpdate()
Per-frame update: checks m_ModifiedPrefabQuery and refreshes prefabs if changed, updates the adapter, and synchronizes the adapter's selectedPrefab with the ToolSystem.activePrefab. -
protected override bool OnCancel()
Handles cancel/back action in the panel. If a prefab is currently selected in the adapter, clears the selection and deactivates the prefab tool (returns false to indicate the panel handled the cancel). Otherwise defers to base.OnCancel(). -
private void OnPrefabSelected(PrefabBase prefab)
Event handler invoked when the adapter reports a prefab selection; activates the ToolSystem prefab tool using the adapter's selected prefab. -
private void UpdatePrefabs()
If a category is selected in m_CategoryMenu, queries that category for matching prefabs using the EntityManager, m_PrefabSystem and the cached EntityTypeHandle, then sets the resulting prefab set into the adapter (m_Adapter.SetPrefabs). -
private void GenerateCategories()
Creates and configures the default m_AllCategory with an EntityQuery that broadly matches PrefabData and a set of common data types (ObjectData, EffectData, ActivityLocationData, NetData, NetLaneData, AreaData) while excluding brand and lane/connection-related types. Marks this category as defaultSelection. -
private IEnumerable<HierarchyItem<EditorAssetCategory>> GetHierarchy()
Returns an enumerable that yields the m_AllCategory as a HierarchyItem and then yields all items from m_CategorySystem.GetHierarchy(). Used to populate the category menu. -
private void __AssignQueries(ref SystemState state)
Compiler-assisted helper (inlined) used during OnCreateForCompiler to construct or assign queries — the shown implementation only creates and disposes an EntityQueryBuilder (likely placeholder for compiler flow). -
protected override void OnCreateForCompiler()
Compiler helper called during system creation: calls __AssignQueries and assigns handles in the nested TypeHandle by invoking __AssignHandles with the system's checked state reference.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_PrefabSystem = base.World.GetOrCreateSystemManaged<PrefabSystem>();
m_ToolSystem = base.World.GetOrCreateSystemManaged<ToolSystem>();
m_CategorySystem = base.World.GetOrCreateSystemManaged<EditorAssetCategorySystem>();
m_ModifiedPrefabQuery = GetEntityQuery(new EntityQueryDesc {
All = new[] { ComponentType.ReadOnly<PrefabData>() },
Any = new[] {
ComponentType.ReadOnly<Created>(),
ComponentType.ReadOnly<Deleted>(),
ComponentType.ReadOnly<Updated>()
}
});
m_Adapter = new PrefabPickerAdapter();
m_Adapter.EventPrefabSelected += OnPrefabSelected;
// Build UI children: search field, filter menu, categories, item picker and footer...
GenerateCategories();
}
Notes and tips: - The PrefabPickerAdapter persists user settings (LoadSettings) and manages favorites, search and selection state; ensure adapter settings are saved/restored as appropriate when extending behavior. - The m_ModifiedPrefabQuery is used to automatically refresh the UI when prefab assets change (created/updated/deleted). - Category queries are built using EntityQueryDesc and used to obtain prefabs via EditorAssetCategory.GetPrefabs — categories can include or exclude child categories and control which entity component combinations are matched.