Game.Companies.ServiceAvailable
Assembly:
Namespace: Game.Companies
Type: struct
Base: System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents an ECS component that stores how many units of a given service are available to companies and the mean priority assigned to that service. This struct is used with Unity's Entities (DOTS) for per-entity company/service state and supports custom binary serialization via Colossal.Serialization.
Fields
-
public int m_ServiceAvailable
Stores the count of available service units (for the associated company/entity). Typically used to decide whether a company has capacity to provide its service. -
public float m_MeanPriority
Stores the mean priority value for the service. This can be used for weighted decision-making (e.g., determining which services are preferred or how urgent service requests are).
Properties
- This type exposes no properties. It only has public fields and implements interface members for serialization.
Constructors
public ServiceAvailable()
(default struct constructor)
As a value type, ServiceAvailable has the default parameterless constructor provided by C#. No custom constructors are declared in the source.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component data to a writer in the following order: m_ServiceAvailable (int), then m_MeanPriority (float). The method uses writer.Write(...) for each field. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component data from a reader into the fields in the same order: m_ServiceAvailable (int), then m_MeanPriority (float). The method uses reader.Read(out ...) to populate the fields by reference.
Notes on serialization: - The generic constraints require a writer/reader implementing Colossal.Serialization.Entities.IWriter / IReader (or compatible types) — these are provided by the game's serialization infrastructure. - The order and types written/read must match exactly to ensure correct deserialization and compatibility across versions/patches.
Usage Example
// Create and add the component to an Entity (example in a system or code that manipulates entities)
var serviceComp = new Game.Companies.ServiceAvailable
{
m_ServiceAvailable = 5,
m_MeanPriority = 2.3f
};
// Example: adding to an entity with an EntityManager (Unity.Entities)
entityManager.AddComponentData(someEntity, serviceComp);
// During save/load the game's serializer will call Serialize/Deserialize automatically.
// If you need to manually serialize using a writer/reader (rare), it would look like:
// writer.Write(serviceComp.m_ServiceAvailable);
// writer.Write(serviceComp.m_MeanPriority);
// And on load:
// reader.Read(out serviceComp.m_ServiceAvailable);
// reader.Read(out serviceComp.m_MeanPriority);
{{ Additional info: - Field naming uses the common m_ prefix found throughout the game's codebase. - Because this is an IComponentData struct, it should remain blittable and compact for ECS performance. - If you extend this type in future mods, keep serialization backward-compatible (append-only fields or versioning) to avoid breaking saves. }}