Game.Citizens.PetTrip
Assembly: Assembly-CSharp
Namespace: Game.Citizens
Type: struct (value type)
Base: IBufferElementData, ISerializable
Summary:
PetTrip is a small ECS buffer element used to represent a "pet trip" by storing a pair of Unity.Entities.Entity references: the source and the target. It is annotated with [InternalBufferCapacity(1)] to reserve a small inline buffer capacity and implements Colossal.Serialization.Entities.ISerializable so the two Entity references are written and read by the game's custom serializer. Typical usage is as a DynamicBuffer
Fields
-
public Unity.Entities.Entity m_Source
The source entity for the pet trip (e.g., origin node or owner). This is the first Entity written during serialization. -
public Unity.Entities.Entity m_Target
The target entity for the pet trip (e.g., destination or target object). This is the second Entity written during serialization.
Properties
- This type defines no properties. It is a plain struct implementing IBufferElementData and ISerializable.
Constructors
public PetTrip()
The default parameterless struct constructor (implicitly provided). Both m_Source and m_Target default to Entity.Null if not set.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the two Entity references to the provided writer in order: m_Source, then m_Target. This allows the game's serializer to persist and restore the entity references for this buffer element. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads two Entity references from the provided reader into m_Source and m_Target (in that order). This restores the saved entity references when deserializing.
Usage Example
// Example: attaching and using a PetTrip buffer on an entity
using Unity.Entities;
using Game.Citizens;
public void AddPetTrip(EntityManager em, Entity owner, Entity source, Entity target)
{
// Ensure the entity has a dynamic buffer of PetTrip (adds component if missing)
if (!em.HasComponent<PetTrip>(owner))
{
em.AddBuffer<PetTrip>(owner);
}
DynamicBuffer<PetTrip> buffer = em.GetBuffer<PetTrip>(owner);
buffer.Add(new PetTrip { m_Source = source, m_Target = target });
}
// Iterating the buffer
public void ProcessTrips(EntityManager em, Entity owner)
{
if (!em.HasComponent<PetTrip>(owner)) return;
DynamicBuffer<PetTrip> buffer = em.GetBuffer<PetTrip>(owner);
foreach (var trip in buffer)
{
Entity src = trip.m_Source;
Entity dst = trip.m_Target;
// handle trip...
}
}
Notes: - The [InternalBufferCapacity(1)] attribute reserves inline space for one element to reduce heap allocations for small buffers. - Because PetTrip implements ISerializable (Colossal serializer interfaces), the two Entity fields will be written and read by the game's save/load system automatically.