Skip to content

Game.UI.Editor.PrefabEdítorPanelSystem

Assembly: Assembly-CSharp (typical for game modding; replace with actual assembly name if different)
Namespace: Game.UI.Editor

Type: class PrefabEdítorPanelSystem

Base: EditorPanelSystemBase

Summary:
A UI editor panel system that implements the prefab editor panel. Handles building the editor UI (search, filters, categories, item picker), syncing available prefabs from the PrefabSystem, reacting to prefab modifications, creating new prefabs, and wiring selection events to the inspector panel. Intended to run as an ECS-managed system in the game's world and interacts with other editor systems (PrefabSystem, ToolSystem, EditorAssetCategorySystem, InspectorPanelSystem) and UI widget adapters (PrefabPickerAdapter, HierarchyMenu, ItemPicker).


Fields

  • private struct TypeHandle
    A small nested struct that holds an EntityTypeHandle used for efficient entity access in ECS contexts. It exposes __AssignHandles to set up the handle from a SystemState.

  • private PrefabSystem m_PrefabSystem
    Reference to the PrefabSystem used to enumerate, add, and manage PrefabBase instances.

  • private ToolSystem m_ToolSystem
    Reference to the game's ToolSystem (editor/tool-related logic).

  • private EditorAssetCategorySystem m_CategorySystem
    Reference to the system that manages editor asset categories (used to build category hierarchies).

  • private InspectorPanelSystem m_InspectorPanelSystem
    Reference to the inspector panel system; selection events forward prefabs to this inspector panel.

  • private EntityQuery m_PrefabQuery
    (Declared but unused in the shown code) An EntityQuery intended to match prefab-related entities; may be used elsewhere or reserved for future queries.

  • private EntityQuery m_ModifiedPrefabQuery
    Query to detect prefabs that have been created, updated or deleted. Used to mark the prefab list as dirty so UI can refresh.

  • private PrefabPickerAdapter m_Adapter
    Adapter that feeds the item picker widgets with prefab items, search/filter settings, favorites, and selection events.

  • private HierarchyMenu<EditorAssetCategory> m_CategoryMenu
    UI hierarchy menu that lists editor asset categories for filtering prefabs.

  • private EditorAssetCategory m_AllCategory
    A special category representing "All" prefabs (constructed in GenerateCategories).

  • private bool m_PrefabsDirty
    Flag indicating the adapter's prefab set needs to be refreshed (set when modified prefab entities are detected).

  • private TypeHandle __TypeHandle
    Instance of the nested TypeHandle struct used to cache an EntityTypeHandle for entity queries.

Properties

  • (none declared in this class)

Constructors

  • public PrefabEdítorPanelSystem()
    Default parameterless constructor with [Preserve] attribute in OnCreate/OnStartRunning methods to avoid stripping. The system follows the ECS lifecycle (OnCreate, OnStartRunning, OnUpdate).

Methods

  • protected override void OnCreate()
    Initializes references to required systems (PrefabSystem, ToolSystem, EditorAssetCategorySystem, InspectorPanelSystem), creates the modified-prefab EntityQuery, configures the PrefabPickerAdapter (including hooking EventPrefabSelected), sets up the panel's child widgets (search, filter, category hierarchy, item picker, footer, create-button), and calls GenerateCategories to create built-in categories.

  • protected override void OnGameLoaded(Context serializationContext)
    Called when a saved game is loaded; clears the adapter search query and selected prefab so the UI starts in a neutral state after load.

  • protected override void OnStartRunning()
    Called when the system starts running; loads adapter settings, populates the category menu from GetHierarchy(), and refreshes prefab list via UpdatePrefabs().

  • protected override void OnUpdate()
    Per-frame update: checks the modified-prefab query to mark prefabs dirty; if the list is dirty and no subpanel is active, calls UpdatePrefabs(); always calls m_Adapter.Update() to process input/filters and UI updates.

  • private void OnPrefabSelected(PrefabBase prefab)
    Selection callback invoked by the adapter when the user picks a prefab. It instructs the InspectorPanelSystem to select the picked prefab and sets that inspector as the active subpanel.

  • private void UpdatePrefabs()
    Refreshes the adapter's prefab set from the currently selected category. Clears the dirty flag. Uses the selected category to query prefabs from the EntityManager/PrefabSystem; uses an EntityTypeHandle via InternalCompilerInterface and the stored __TypeHandle for entity-based queries.

  • private void GenerateCategories()
    Creates the built-in "All" category (m_AllCategory) which matches all PrefabData entities that do not have MeshData. The category is configured as defaultSelection = true and includeChildCategories = false.

  • private IEnumerable<HierarchyItem<EditorAssetCategory>> GetHierarchy()
    Yields the "All" category first, then enumerates categories provided by the EditorAssetCategorySystem.GetHierarchy(). Used to populate the hierarchy menu.

  • private void OnCreatePrefabSelected()
    Opens a TypePickerPanel listing concrete types derived from PrefabBase (title "Editor.CREATE_NEW_PREFAB", group "Editor.PREFAB_TYPES") and binds the selection callback to OnCreatePrefab; closes via base.CloseSubPanel on cancel.

  • private void OnCreatePrefab(Type type)
    Callback invoked when a user selects a prefab type to create. Creates a ScriptableObject instance of the selected type, sets its name to the type name, adds it to the PrefabSystem, and selects it in the inspector.

  • private IEnumerable<Item> GetPrefabTypeItems()
    Enumerates all concrete types derived from PrefabBase, derives a user-friendly name (via WidgetReflectionUtils.NicifyVariableName) and reads the optional ComponentMenu attribute to place types into parent directories for the TypePickerPanel.

  • private void __AssignQueries(ref SystemState state)
    Compiler-generated helper method that currently contains an EntityQueryBuilder(Allocator.Temp).Dispose(); present to satisfy generated-code requirements (may be extended by compiler). Marked with [MethodImpl(MethodImplOptions.AggressiveInlining)] in source.

  • protected override void OnCreateForCompiler()
    Compiler hook used to assign queries and entity handles at compile-time; calls __AssignQueries and the nested TypeHandle.__AssignHandles to set up EntityTypeHandle via the checked SystemState reference.

  • private void TypeHandle.__AssignHandles(ref SystemState state)
    Sets the nested __Unity_Entities_Entity_TypeHandle by calling state.GetEntityTypeHandle(); used by OnCreateForCompiler to initialize type handles used during runtime queries.

Usage Example

[Preserve]
protected override void OnStartRunning()
{
    base.OnStartRunning();
    // Load previously saved adapter settings (search, favorites...)
    m_Adapter.LoadSettings();

    // Populate the category hierarchy into the UI menu
    m_CategoryMenu.items = GetHierarchy();

    // Ensure the currently selected category's prefabs are shown
    UpdatePrefabs();
}

// Handling selection is automatic via the adapter's EventPrefabSelected.
// If you need to programmatically open the inspector for a prefab:
private void OpenInspectorForPrefab(PrefabBase prefab)
{
    m_InspectorPanelSystem.SelectPrefab(prefab);
    activeSubPanel = m_InspectorPanelSystem;
}

Notes / Tips for Modders: - This system depends on PrefabSystem, EditorAssetCategorySystem and InspectorPanelSystem; ensure those systems are available in the World before this panel is used. - To add custom prefab categories, extend EditorAssetCategorySystem so GetHierarchy() yields your categories; the panel will include them automatically. - The adapter contains search, filter, and favorites logic — you can extend PrefabPickerAdapter to change how prefabs are presented or filtered. - The class uses ECS EntityQuery to detect modified prefabs (Created/Updated/Deleted) and refreshes the UI when needed — if you programmatically modify prefabs, ensure appropriate entity components are set so the query catches changes.