Game.Prefabs.Pet
Assembly: Assembly-CSharp (Game)
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Represents a prefab component for "pet" creatures. This prefab component supplies the ECS components required to represent a pet in the entity system: it registers runtime component data (PetData) and an update-frame scheduling component (UpdateFrameData) and adds an archetype component (Game.Creatures.Pet). It also initializes the entity with the pet type and a default update interval.
Fields
public PetType m_Type
Holds the configured pet type for this prefab instance. During initialization, this value is copied into the PetData component stored on the entity.
Properties
- None declared on this class. (It overrides methods from ComponentBase but does not define any properties.)
Constructors
public Pet()
No explicit constructor is defined in the source; the default parameterless constructor is used.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds components that should be present on the runtime "prefab" entity. Implementation adds:ComponentType.ReadWrite<PetData>()
— stores pet-specific data (including pet type).-
ComponentType.ReadWrite<UpdateFrameData>()
— stores update scheduling info. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds components that should be part of the entity archetype for this prefab. Implementation adds: -
ComponentType.ReadWrite<Game.Creatures.Pet>()
— a marker or data component from the Game.Creatures namespace representing the creature archetype. -
public override void Initialize(EntityManager entityManager, Entity entity)
Initializes the entity when the prefab is instantiated. Behavior: - Calls
base.Initialize(entityManager, entity)
. - Creates a
PetData
instance, sets itsm_Type
to this prefab'sm_Type
, and writes it to the entity viaentityManager.SetComponentData
. - Adds an
UpdateFrameData
component initialized with5
as the update interval (or scheduling value), also viaentityManager.SetComponentData
.
Remarks: - The class relies on Unity.Entities types: EntityManager, Entity, ComponentType, and component data structs like PetData and UpdateFrameData. - UpdateFrameData(5) indicates this pet will use an update cadence/value of 5 (interpretation depends on game systems).
Usage Example
// Example: custom initialize override or manual entity setup
public class MyPetSpawner
{
public void CreatePetPrefab(EntityManager entityManager, Entity petEntity, Pet prefab)
{
// If using the prefab's Initialize method:
prefab.Initialize(entityManager, petEntity);
// Equivalent manual operations (what Pet.Initialize does):
var petData = new PetData { m_Type = prefab.m_Type };
entityManager.SetComponentData(petEntity, petData);
entityManager.SetComponentData(petEntity, new UpdateFrameData(5));
}
}
{{ Additional notes: - Dependencies: Game.Creatures (for PetData, PetType, Game.Creatures.Pet), Unity.Entities. - This prefab class is intended to be used as a Unity/CS prefab component (see ComponentMenu attribute in source). - If you want different update scheduling, change the value passed to UpdateFrameData in Initialize. }}