Skip to content

Game.Routes.MailBox

Assembly:
Assembly-CSharp

Namespace:
Game.Routes

Type:
struct

Base:
IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents a mailbox component for the routing system. Holds a reference to an Entity that represents a collect request and an integer count of mail items. Implements ISerializable for binary (de)serialization using Colossal's reader/writer abstractions and is usable as an ECS component (IComponentData) and query parameter (IQueryTypeParameter).


Fields

  • public Unity.Entities.Entity m_CollectRequest
    Holds the Entity reference for the collect request associated with this mailbox. This value is written/read during serialization.

  • public int m_MailAmount
    The number of mail items currently in the mailbox. This value is written/read during serialization.

Properties

  • None

Constructors

  • public MailBox()
    Default value-type constructor (implicit). After construction, m_CollectRequest will be the default Entity (Entity.Null) and m_MailAmount will be 0 unless assigned explicitly.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the mailbox data in order: writes the m_CollectRequest Entity, then writes the m_MailAmount integer. Uses the provided writer abstraction from Colossal.Serialization.Entities.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes mailbox data in the same order as Serialize: reads into m_CollectRequest (by ref) and then reads into m_MailAmount (by ref). Uses the provided reader abstraction from Colossal.Serialization.Entities.

Usage Example

using Unity.Entities;
using Colossal.Serialization.Entities;
using Game.Routes;

// Create and assign a MailBox to an entity
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity mailboxEntity = em.CreateEntity();
Entity collectRequestEntity = /* obtain or create request entity */ Entity.Null;

MailBox mailbox = new MailBox
{
    m_CollectRequest = collectRequestEntity,
    m_MailAmount = 5
};

em.AddComponentData(mailboxEntity, mailbox);

// Serialization example (conceptual)
var writer = /* obtain an IWriter implementation */;
mailbox.Serialize(writer);

// Deserialization example (conceptual)
var reader = /* obtain an IReader implementation */;
MailBox loaded = new MailBox();
loaded.Deserialize(reader);

Notes: - The struct is intended to be used as an ECS component (IComponentData) and supports Colossal's serialization pipeline via ISerializable. - When deserializing, fields are read by reference into the existing struct fields, which matches the write order used in Serialize. Ensure reader/writer implementations match this order.