Game.Creatures.Animal
Assembly: Game (Game.dll)
Namespace: Game.Creatures
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary: Represents an animal component used by the game's ECS. This struct stores a set of bitflags (AnimalFlags) describing the state/behavior of an animal entity. It is serializable for save/load and can be used as a query type parameter in Unity.Entities queries.
Fields
public AnimalFlags m_Flags
Holds the bitmask flags for this animal instance. The AnimalFlags enum encodes per-animal state and behavior bits (e.g., alive, hungry, aggressive — see the AnimalFlags definition in the codebase for exact values).
Properties
- None. This type exposes a single public field and no managed properties.
Constructors
public Animal(AnimalFlags flags)
Creates a new Animal component with the provided flags. Parameters:- flags: Initial AnimalFlags bitmask to store in m_Flags.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes this component to a writer. The implementation writes the m_Flags value as a uint. This method is used by the game's save system and serialization pipeline. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes this component from a reader. Reads a uint from the reader and casts it to AnimalFlags, restoring the m_Flags value. Called when loading saved data or receiving serialized component data.
Notes: - Both Serialize and Deserialize are generic to support the game's IWriter/IReader abstractions and conform to ISerializable expected patterns. - Because flags are written as a raw uint, changes to the AnimalFlags enum values/order should be done carefully to preserve save compatibility.
Usage Example
// Create an Animal component and add it to an entity
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = entityManager.CreateEntity();
// Set flags using the AnimalFlags enum (example flag names assumed)
AnimalFlags initialFlags = AnimalFlags.Alive | AnimalFlags.Passive;
var animal = new Animal(initialFlags);
entityManager.AddComponentData(entity, animal);
// Example of manual serialization usage (writer/reader types depend on engine)
void SaveAnimal(Animal a, IWriter writer)
{
a.Serialize(writer);
}
void LoadAnimal(Animal a, IReader reader)
{
a.Deserialize(reader);
}
{{ Additional info: - This struct is intended to be lightweight and blitable so it works well as a component in Unity's ECS. - Because it implements IQueryTypeParameter, Animal can be used directly in query parameter lists to filter or access entities with animal data. - If you add or remove flags in AnimalFlags, update any migration/compat code to handle saved games. }}