Skip to content

Game.Prefabs.ChirpPrefab

Assembly:
Game

Namespace:
Game.Prefabs

Type:
class

Base:
PrefabBase

Summary:
ChirpPrefab is a prefab class used by the game's entity/component system to represent a "chirp" trigger. It declares which components belong to the prefab (via GetPrefabComponents), which components should be part of the runtime archetype (via GetArchetypeComponents), and it creates/assigns an ECS archetype for instantiated prefabs in LateInitialize / RefreshArchetype. The archetype includes trigger/runtime components such as Game.Triggers.Chirp, ChirpEntity, PrefabRef, and ensures Created/Updated tags are present. The prefab stores the created archetype inside ChirpData on the prefab entity.


Fields

  • This class declares no instance fields.
    ChirpPrefab relies on methods and the base PrefabBase implementation; all state it writes at runtime is stored into ECS components (e.g., ChirpData on the prefab entity).

Properties

  • This class declares no properties.
    All configuration is exposed by overriding the component/archetype provider methods and by writing component data into entities.

Constructors

  • public ChirpPrefab()
    Default parameterless constructor inherited from object/PrefabBase. The class does not provide any custom construction logic.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the component types that should exist on the prefab entity itself. This implementation calls base and then adds a read/write ChirpData component so the prefab entity can hold runtime data (m_Archetype, m_Flags).

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds component types that will go into the archetype used for spawned instances of this prefab. This implementation calls base and then adds Game.Triggers.Chirp, ChirpEntity, and PrefabRef (all as ReadWrite). These are the components that runtime chirp entities will possess.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Called after prefab creation/initialization. This implementation calls base.LateInitialize and then calls RefreshArchetype to build and store the runtime archetype on the prefab entity.

  • protected virtual void RefreshArchetype(EntityManager entityManager, Entity entity)
    Builds the archetype for this prefab and writes it into the prefab's ChirpData component. Steps:

  • Collects all ComponentBase entries attached to the prefab (via GetComponents).
  • Gathers archetype ComponentType entries from each collected ComponentBase (by calling GetArchetypeComponents).
  • Adds Created and Updated tag components to the archetype set.
  • Creates an ECS archetype from the collected ComponentType set and assigns it to ChirpData.m_Archetype on the prefab entity, setting ChirpData.m_Flags = ChirpDataFlags.None. Note: This creates a new archetype based on the current prefab configuration; avoid calling frequently at runtime.

Usage Example

// Example: extend the prefab to include an extra component in the instance archetype
public class CustomChirpPrefab : ChirpPrefab
{
    public override void GetArchetypeComponents(HashSet<ComponentType> components)
    {
        base.GetArchetypeComponents(components);
        // Add a custom runtime component to all spawned chirp entities
        components.Add(ComponentType.ReadWrite<MyCustomChirpComponent>());
    }

    // Optionally override RefreshArchetype to perform custom archetype logic,
    // but be careful: the base implementation creates and writes the ChirpData archetype.
    protected override void RefreshArchetype(EntityManager entityManager, Entity entity)
    {
        base.RefreshArchetype(entityManager, entity);
        // After base runs, ChirpData on 'entity' contains the created archetype.
        // You can read it if needed:
        // var chirpData = entityManager.GetComponentData<ChirpData>(entity);
        // Debug.Log($"Archetype created with type count: {entityManager.GetArchetypeChunkComponentCount(chirpData.m_Archetype)}");
    }
}