Skip to content

Game.Net.CoverageServiceType

Assembly: Assembly-CSharp
Namespace: Game.Net

Type: struct

Base: ISharedComponentData, IQueryTypeParameter, ISerializable

Summary:
CoverageServiceType is a lightweight shared ECS component that wraps a CoverageService enum value. It is used to store and query the coverage/service type (for example, electricity, water, etc.) on entities and supports custom binary serialization for network or persistent storage via the ISerializable interface. Because it implements ISharedComponentData it is intended to be attached as a shared component so entities with the same CoverageService value can be grouped efficiently.


Fields

  • public CoverageService m_Service
    This field holds the CoverageService enum value represented by this component. It is serialized as a single byte when using the provided Serialize/Deserialize methods. Default (uninitialized) value corresponds to the default of the CoverageService enum.

Properties

  • This type does not expose any properties.

Constructors

  • public CoverageServiceType(CoverageService service)
    Constructs a new CoverageServiceType and sets m_Service to the provided value. Useful when creating and attaching the shared component to an entity or when preparing the value for serialization.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the component by writing the underlying CoverageService enum value as a single byte. This compact representation is appropriate when the enum values fit into a byte.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes the component by reading a single byte from the reader and casting it back to CoverageService. After deserialization, m_Service holds the reconstructed enum value.

Notes: - The serialization uses a byte-sized representation; if CoverageService gains values beyond the byte range or its values change, ensure compatibility or update serialization accordingly. - The generic writer/reader types are constrained to IWriter/IReader from Colossal.Serialization.Entities, matching the game's serialization abstractions.

Usage Example

// Example: creating and adding a shared component to an entity
var coverageComponent = new CoverageServiceType(CoverageService.Electricity);
entityManager.AddSharedComponentData(entity, coverageComponent);

// Example: serializing the component
void SaveCoverage<TWriter>(TWriter writer, CoverageServiceType cov) where TWriter : IWriter
{
    cov.Serialize(writer);
}

// Example: deserializing the component
CoverageServiceType LoadCoverage<TReader>(TReader reader) where TReader : IReader
{
    var cov = new CoverageServiceType();
    cov.Deserialize(reader);
    return cov;
}

// After loading:
var loaded = LoadCoverage(reader);
Debug.Log($"Loaded coverage service: {loaded.m_Service}");

{{ Additional information: - Because CoverageServiceType implements IQueryTypeParameter it can be used in ECS query constructs that accept query-time type parameters. - Use shared components when you expect many entities to share the same CoverageService value; this improves chunk grouping and query performance. - When persisting over network or files, keep versioning in mind: changing enum values or adding new ones may require migration logic to avoid misinterpretation of stored byte values. }}