Skip to content

Game.Prefabs.HouseholdPetPrefab

Assembly: Game
Namespace: Game.Prefabs

Type: class

Base: ArchetypePrefab

Summary:
Prefab component that defines a household pet archetype used by the game to create pet entities. Exposes a configurable PetType (m_Type) which is stored into the HouseholdPetData component when the prefab is initialized. The prefab registers the runtime component types needed on the entity: a data component (HouseholdPetData) and, for the archetype, runtime components HouseholdPet and UpdateFrame. The class is exposed to the Unity inspector menu "Citizens/" via the ComponentMenu attribute.


Fields

  • public PetType m_Type
    The pet type selected in the prefab (an enum describing the species/breed/category). During Initialize(), this value is copied into the HouseholdPetData component on the entity so systems can read the pet type at runtime.

Properties

  • None

Constructors

  • public HouseholdPetPrefab()
    Default constructor (Unity/serialization compatible). Instances are typically created and populated in the editor; Unity/engine code constructs and uses prefabs at runtime.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Collects component types that should be present on the prefab asset (data components). This implementation calls the base method and then adds ComponentType.ReadWrite<HouseholdPetData>() indicating the prefab supplies HouseholdPetData to created entities.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Collects component types that must be present on the entity archetype at creation. This implementation calls the base method and then adds ComponentType.ReadWrite<HouseholdPet>() and ComponentType.ReadWrite<UpdateFrame>() so runtime entities include these components.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Initializes the entity instance from this prefab. Creates a default HouseholdPetData, sets its m_Type field from this prefab's m_Type, and writes it to the entity with entityManager.SetComponentData(entity, componentData). This binds the designer-selected pet type to the entity's component data for systems to consume.

Usage Example

// Example: what Initialize does internally. The game engine calls this
// when instantiating the prefab for an entity.
public override void Initialize(EntityManager entityManager, Entity entity)
{
    base.Initialize(entityManager, entity);

    // Create the data component and copy the pet type from the prefab.
    HouseholdPetData componentData = default(HouseholdPetData);
    componentData.m_Type = m_Type;

    // Write the data to the entity so systems can read the pet type.
    entityManager.SetComponentData(entity, componentData);
}

Additional notes: - Requires Unity.Entities and the game's Citizens/Simulation types (HouseholdPetData, HouseholdPet, UpdateFrame, PetType). - The ComponentMenu attribute places this prefab in the Unity editor under "Citizens/" for designer use. - The prefab pattern here separates prefab-level configuration (m_Type) from runtime archetype components (HouseholdPet, UpdateFrame) and instance data (HouseholdPetData).