Game.Creatures.Wildlife
Assembly:
Assembly-CSharp (game assembly that contains gameplay types)
Namespace:
Game.Creatures
Type:
struct
Base:
System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents the component data for a wildlife (creature) entity in the game's ECS. Stores flag/state bits and simple timing counters used by the wildlife simulation and supports serialization/deserialization for save/load. This struct is intended to be attached to entities (IComponentData) and used as a query parameter (IQueryTypeParameter).
Fields
-
public WildlifeFlags m_Flags
Stores bit flags describing the wildlife's state (movement, visibility, alive/dead, etc.). Serialized as a uint. -
public ushort m_StateTime
A short counter/timer representing how long the creature has been in its current state (used for behavior transitions and timing). -
public ushort m_LifeTime
A short counter representing the creature's remaining or elapsed life time (used for lifetime-based behavior or despawn).
Properties
- This type defines no public properties. It exposes raw public fields and implements behavior via methods.
Constructors
public Wildlife()
As a struct, Wildlife has the implicit default constructor (all fields defaulted). Initialize fields directly when creating a new instance, e.g.: Wildlife w = new Wildlife { m_Flags = 0, m_StateTime = 0, m_LifeTime = 0 };
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component data to the provided writer in the following order: m_Flags (as uint), m_StateTime (ushort), m_LifeTime (ushort). This ordering must match Deserialize to maintain compatibility with saved data. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component data from the provided reader in the same order as Serialize: flags (read into a uint local), state time (ushort), life time (ushort). After reading the numeric flag value it is cast back to WildlifeFlags and assigned to m_Flags.
Notes: - Serialize/Deserialize use generic writer/reader interfaces (IWriter/IReader) provided by the game's Colossal.Serialization.Entities system. - The serialization format is compact (ints/ushorts) and relies on the same ordering in both methods.
Usage Example
// Create and initialize a Wildlife component and add it to an entity
var wildlife = new Wildlife {
m_Flags = WildlifeFlags.Active | WildlifeFlags.Visible,
m_StateTime = 0,
m_LifeTime = 300 // example lifetime in ticks
};
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity creatureEntity = entityManager.CreateEntity();
entityManager.AddComponentData(creatureEntity, wildlife);
// Example skeleton showing serialization usage with a writer/reader provided by the game:
// (IWriter/IReader implementations are provided by the game's serialization system)
void SaveWildlife<TWriter>(TWriter writer, in Wildlife w) where TWriter : IWriter
{
w.Serialize(writer);
}
void LoadWildlife<TReader>(TReader reader, out Wildlife w) where TReader : IReader
{
w = new Wildlife();
w.Deserialize(reader);
}