Skip to content

Game.Prefabs.UIGroupPrefab

Assembly: Assembly-CSharp (game code / modding assembly)
Namespace: Game.Prefabs

Type: public abstract class

Base: PrefabBase

Summary:
UIGroupPrefab is an abstract prefab base class used to define UI groups in the game. It ensures the prefab contains the buffers and components needed to hold group elements and unlock requirements. The class provides helpers to add elements to the group prefab and performs late initialization for unlock requirements.


Fields

  • This class declares no explicit instance fields. All working data is handled via ECS buffers and components.

Properties

  • This class declares no public properties.

Constructors

  • public UIGroupPrefab()
    Implicit parameterless constructor (generated by the compiler). Because the class is abstract it cannot be instantiated directly; concrete subclasses inherit this constructor.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Ensures required component types are present on the prefab. Calls the base implementation and then adds:
  • UIGroupElement (read/write) — buffer element type used to list entities that belong to the UI group
  • UnlockRequirement (read/write) — buffer element type used to store unlock requirements linked to the group or its elements
  • Locked (read/write) — component used to mark that the UI group / element is locked by default

Typical use: the prefab system queries this to know which components/buffers to create for the prefab entity.

  • public void AddElement(EntityManager entityManager, Entity entity)
    Adds a new element entry to the prefab's UIGroupElement and UnlockRequirement buffers. Behavior:
  • Retrieves the prefab entity corresponding to this UIGroupPrefab via entityManager.World.GetExistingSystemManaged<PrefabSystem>().GetEntity(this).
  • Adds a UIGroupElement(entity) to the prefab entity's UIGroupElement buffer, referencing the provided element entity.
  • Adds a UnlockRequirement(entity, UnlockFlags.RequireAny) to the prefab entity's UnlockRequirement buffer, creating a default unlock requirement that requires any of the specified flags.

Notes: - This method modifies the prefab entity (the stored prefab representation), not the provided entity itself. - Useful when constructing the prefab so that the prefab has a list of its child UI elements and their unlock rules.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Called after initial prefab/entity setup. This implementation:
  • Adds a UnlockRequirement(entity, UnlockFlags.RequireAny) to the instance entity's UnlockRequirement buffer.
  • Calls base.LateInitialize(entityManager, entity) afterwards.

Purpose: - Ensures that instances of the prefab (the runtime entity) also receive a default unlock requirement entry, matching the prefab behavior.


Usage Example

// Example subclass that can add elements during prefab construction or initialization.
public class MyUIGroupPrefab : UIGroupPrefab
{
    // Optionally override to add more components.
    public override void GetPrefabComponents(HashSet<ComponentType> components)
    {
        base.GetPrefabComponents(components);
        // Add other component types required by your group prefab here.
    }

    // Example: add an element to the prefab during some initialization step.
    public void RegisterElement(EntityManager entityManager, Entity elementEntity)
    {
        // This adds the element to the prefab's element buffer and
        // attaches a default UnlockRequirement for that element on the prefab.
        AddElement(entityManager, elementEntity);
    }

    // Typical LateInitialize override (called when an instance is being finalized).
    public override void LateInitialize(EntityManager entityManager, Entity entity)
    {
        // Add or adjust instance-specific unlock requirements before base handling
        // (base implementation already adds an UnlockRequirement as shown in UIGroupPrefab).
        base.LateInitialize(entityManager, entity);
    }
}

Notes and tips: - The class is abstract — create a concrete subclass for each UI group prefab you need. - The code uses ECS buffers (DynamicBuffer<T>) for UIGroupElement and UnlockRequirement; ensure those buffer types exist and are registered. - UnlockFlags.RequireAny is used as the default unlock behavior when adding requirements; change it if you need different logic (e.g., RequireAll). - AddElement modifies the prefab entity retrieved via PrefabSystem — call it during prefab construction/registration rather than on arbitrary runtime entities unless you intend to mutate the prefab definition.