Game.Prefabs.Domesticated
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Domesticated is a prefab component used for domesticated creature prefabs (animals). It exposes configuration properties used when converting the prefab to ECS components: idle time bounds and minimum/maximum group member counts. At initialization it populates the entity with DomesticatedData and an UpdateFrameData component (with frame index 9), and the archetype includes the runtime Game.Creatures.Domesticated component type.
Fields
-
public Bounds1 m_IdleTime = new Bounds1(20f, 120f)
Bounds controlling idle time for the domesticated creature. Default range is 20 to 120 seconds. -
public int m_MinGroupMemberCount = 1
Minimum number of members in a domestic group (default 1). -
public int m_MaxGroupMemberCount = 2
Maximum number of members in a domestic group (default 2).
Properties
- None declared on this class. (The class overrides methods from ComponentBase instead.)
Constructors
public Domesticated()
Implicit default constructor. The field defaults are: m_IdleTime = Bounds1(20f,120f), m_MinGroupMemberCount = 1, m_MaxGroupMemberCount = 2.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the component types that should be present on the entity created from the prefab. This implementation adds:- ComponentType.ReadWrite
() -
ComponentType.ReadWrite
() -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds runtime archetype components required for this prefab. This implementation adds: -
ComponentType.ReadWrite
() -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is converted to an ECS entity. This method: - Creates a DomesticatedData struct and sets:
- m_IdleTime = m_IdleTime (from the prefab instance)
- m_GroupMemberCount.x = m_MinGroupMemberCount
- m_GroupMemberCount.y = m_MaxGroupMemberCount
- Writes that DomesticatedData to the entity via entityManager.SetComponentData.
- Sets an UpdateFrameData component on the entity with the value 9 via entityManager.SetComponentData.
Usage Example
// Example: custom prefab-derived class could rely on the Domesticated component as-is.
// At runtime (during conversion), Domesticated.Initialize will populate the entity with
// DomesticatedData and an UpdateFrameData(9). No additional calls are required here.
[ComponentMenu("Creatures/", new Type[] { typeof(AnimalPrefab) })]
public class MyAnimalPrefab : Domesticated
{
// You can override values in the inspector or in code before conversion:
public void ConfigureForHerd()
{
m_IdleTime = new Bounds1(10f, 60f);
m_MinGroupMemberCount = 3;
m_MaxGroupMemberCount = 8;
}
}
// When the prefab is converted to an entity, the Domesticated.Initialize method will:
// - set DomesticatedData.m_IdleTime to the prefab m_IdleTime
// - set DomesticatedData.m_GroupMemberCount.x/y to m_MinGroupMemberCount/m_MaxGroupMemberCount
// - add UpdateFrameData(9)
Notes: - DomesticatedData and UpdateFrameData are ECS component structs expected by runtime systems that handle domesticated creatures. - The archetype addition of Game.Creatures.Domesticated ensures runtime systems that look for that managed component type will find it on entities created from this prefab.