Game.Prefabs.AmbulanceData
Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs
Type: struct
Base: System.ValueType; Interfaces: Unity.Entities.IComponentData, IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary:
A small ECS component that stores the patient capacity for an ambulance prefab. This value-type component is used by ambulance-related systems to determine how many patients a given ambulance entity can carry and is serializable for save/load operations. It is intended to be attached to ambulance entities or prefabs in the Unity Entities (DOTS) world.
Fields
public int m_PatientCapacity
Stores the maximum number of patients the ambulance can carry. Default (uninitialized) is 0. Typical values are small integers (e.g., 1–4). If you change this value at runtime, update the component on the entity (EntityManager.SetComponentData) so systems see the change.
Properties
- None.
This struct exposes a public field rather than properties for simplicity and direct use with Unity.Entities' component APIs.
Constructors
public AmbulanceData(int patientCapacity)
Initializes the AmbulanceData component with the specified patient capacity. Note that, as a struct, a parameterless default (all-zero) instance also exists; use this constructor to set a non-zero capacity when creating the component.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the integer patient capacity into the provided writer. Used by the game's serialization system when saving. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the integer patient capacity from the provided reader. Used by the game's deserialization system when loading.
Both methods are straightforward (read/write a single int) so custom versioning or additional fields would require updating these implementations.
Usage Example
using Unity.Entities;
using Game.Prefabs;
// create or obtain an EntityManager (example uses default world)
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
// Suppose you have an archetype that includes AmbulanceData:
var archetype = entityManager.CreateArchetype(typeof(AmbulanceData));
// Create an ambulance entity with capacity 2
Entity ambulanceEntity = entityManager.CreateEntity(archetype);
entityManager.SetComponentData(ambulanceEntity, new AmbulanceData(2));
// Alternatively, add or replace on an existing entity
entityManager.AddComponentData(existingEntity, new AmbulanceData(3));
// or
entityManager.SetComponentData(existingEntity, new AmbulanceData(4));
Notes for modders: - Because this is an IComponentData struct, use EntityManager or DOTS systems to add/update it on entities. - Serialization methods integrate with the game's save/load pipeline; if you extend the struct with new fields, update Serialize/Deserialize accordingly and consider versioning.