Game.Prefabs.Wildlife
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Component used by a wildlife/animal prefab to expose configuration for the ECS component data the prefab will write to entities. The component serializes runtime parameters (trip length, idle time, group size bounds) that are copied into a WildlifeData component on the created entity. The class also registers the required component types for prefab instantiation and sets an UpdateFrameData value so the created entity will be updated on a specific frame slot.
Fields
-
public Colossal.Mathematics.Bounds1 m_TripLength
Bounds (min, max) describing how far a wildlife group will travel on a trip. Defaults to 20f..200f in the source. -
public Colossal.Mathematics.Bounds1 m_IdleTime
Bounds (min, max) describing idle time between trips for the animals. Defaults to 10f..60f in the source. -
public int m_MinGroupMemberCount
Minimum number of members in a wildlife group. Defaults to 1. -
public int m_MaxGroupMemberCount
Maximum number of members in a wildlife group. Defaults to 4.
Notes: - These fields are public and intended to be set on the prefab (e.g. in the inspector). They are copied into the runtime WildlifeData component during initialization.
Properties
- (none)
Constructors
public Wildlife()
Default parameterless constructor (no custom initialization in source). The instance fields shown above will be used as serialized values on the prefab.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds prefab-level component types required by this prefab. Implementation adds:ComponentType.ReadWrite<WildlifeData>()
-
ComponentType.ReadWrite<UpdateFrameData>()
This informs the prefab builder which component data will be set on entities created from this prefab. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds archetype component types required for the entity archetype. Implementation adds: -
ComponentType.ReadWrite<Game.Creatures.Wildlife>()
This tells the archetype to include the runtime Game.Creatures.Wildlife component. -
public override void Initialize(EntityManager entityManager, Entity entity)
Copies the serialized prefab fields into the runtime ECS component data: - Constructs a WildlifeData instance and assigns:
- m_TripLength <- m_TripLength (from prefab)
- m_IdleTime <- m_IdleTime (from prefab)
- m_GroupMemberCount.x <- m_MinGroupMemberCount
- m_GroupMemberCount.y <- m_MaxGroupMemberCount
- Calls entityManager.SetComponentData(entity, componentData) to write WildlifeData.
- Writes an UpdateFrameData with value 13 to the entity (entityManager.SetComponentData(entity, new UpdateFrameData(13))).
- Calls base.Initialize(entityManager, entity) at the start.
Additional attribute:
- [ComponentMenu("Creatures/", new Type[] { typeof(AnimalPrefab) })]
— places this component in the "Creatures/" menu in the prefab/component menu and associates it with AnimalPrefab in editor tooling.
Usage Example
// Example: configuring a prefab instance in code before creating the ECS entity.
// (In practice this component is set up on the prefab in the editor.)
Wildlife prefab = /* get prefab component reference from prefab */;
prefab.m_TripLength = new Bounds1(30f, 150f);
prefab.m_IdleTime = new Bounds1(5f, 40f);
prefab.m_MinGroupMemberCount = 2;
prefab.m_MaxGroupMemberCount = 6;
// When the prefab system creates an Entity for this prefab it will call:
prefab.Initialize(entityManager, createdEntity);
// After Initialize, the created entity will have WildlifeData and UpdateFrameData(13)
// set according to the prefab's fields.