Game.PostVanData
Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs
Type: struct
Base: System.ValueType (implements Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable)
Summary:
Represents a small value-type ECS component that stores the mail capacity for a post/van prefab. Intended for use with Unity DOTS (Entities) in Cities: Skylines 2 mod code. Implements ISerializable to allow the value to be written/read by the game's custom serializer.
Fields
public System.Int32 m_MailCapacity
Stores the number of mail units this post/van can carry. Uses the common "m_" naming convention. This is the only data carried by the component and is serialized/deserialized by the ISerializable implementation.
Properties
- This type has no properties. It exposes a single public field for compactness and compatibility with ECS value semantics.
Constructors
-
public PostVanData(int mailCapacity)
Creates a new PostVanData with the specified mail capacity. Example: new PostVanData(50) sets m_MailCapacity to 50. -
(implicit)
public PostVanData()
Default parameterless struct constructor exists and initializes m_MailCapacity to 0.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_MailCapacity field to the provided writer. Used by the game's serialization system to persist component data. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads an Int32 from the reader into m_MailCapacity. Used by the game's serialization system when loading.
Notes: - The Serialize/Deserialize methods are generic over IWriter/IReader from Colossal.Serialization.Entities and simply forward the integer value. Ensure the same read/write order and types when extending this struct. - As an IComponentData, this struct is intended to be stored on Entities via the EntityManager or within systems using component access patterns.
Usage Example
// Create and attach to an entity using EntityManager
var postVan = new PostVanData(30); // capacity 30
entityManager.AddComponentData(entity, postVan);
// Or set/replace on an existing entity
entityManager.SetComponentData(entity, new PostVanData { m_MailCapacity = 45 });
// Serialization is handled by the game's serializer, but conceptually:
// writer.Write(postVan.m_MailCapacity);
// Deserialization similarly reads the value back into the struct:
// reader.Read(out postVan.m_MailCapacity);
{{ Additional info: - Since this is a plain struct component, prefer direct field access in performance-sensitive code. - When modifying component values in jobs, follow Unity.Entities best practices (use SetComponent and use proper job-safe component access). - The IQueryTypeParameter implementation allows the type to be used when building queries for entity iteration. - Keep the serialized layout stable (field order and types) to maintain save/load compatibility across versions. }}