Game.Buildings.ModifiedServiceCoverage
Assembly: Game (likely Game.dll)
Namespace: Game.Buildings
Type: struct
Base: System.ValueType
Implements: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary: Small value-type ECS component that holds modified service coverage parameters for a building. This struct is used to override or store custom CoverageData values (capacity, range, magnitude) for buildings in the ECS world. It also supports binary serialization so modified values can be saved/loaded with the game's entity serialization system.
Fields
-
public System.Single m_Range
Holds the coverage range (float) for the service. Represents how far the effect of the building reaches. Serialized as the second value when writing this struct. -
public System.Single m_Capacity
Holds the service capacity (float). Represents how much service the building provides. Serialized as the first value when writing this struct. -
public System.Single m_Magnitude
Holds the magnitude (float) of the service effect. Serialized as the third value when writing this struct.
Properties
- This type does not declare any C# properties. It exposes three public fields (m_Capacity, m_Range, m_Magnitude) used directly.
Constructors
public ModifiedServiceCoverage(CoverageData coverage)
Constructs an instance by copying values from a CoverageData instance. Use this when you want to create a component from an existing prefab or runtime CoverageData structure so it can be attached to an entity.
Methods
-
public void ReplaceData(ref CoverageData coverage) : System.Void
Copies this struct's values into the provided CoverageData instance (coverage.m_Capacity, coverage.m_Range, coverage.m_Magnitude). Useful when applying the modified values back to a prefab or a runtime coverage structure before using it for calculations. -
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the three floats to the provided writer in the order: capacity, range, magnitude. Important: the reader must use the same order when deserializing. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads three floats from the provided reader and assigns them to m_Capacity, m_Range, and m_Magnitude respectively. Expects the same ordering used by Serialize.
Usage Example
// Example: create from an existing CoverageData, attach to an entity, and later apply it back.
CoverageData prefabCoverage = GetPrefabCoverage(); // however you obtain a CoverageData
var modified = new ModifiedServiceCoverage(prefabCoverage);
// Modify values as needed
modified.m_Capacity *= 1.2f;
modified.m_Range += 5f;
modified.m_Magnitude = 0.8f;
// Attach to an entity using the ECS EntityManager
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = em.CreateEntity();
em.AddComponentData(e, modified);
// Later: apply to a CoverageData instance
CoverageData runtimeCoverage = default;
modified.ReplaceData(ref runtimeCoverage);
// runtimeCoverage now contains the modified values
// Note on serialization: serialization writes capacity, then range, then magnitude.
// Ensure any custom reader/writer used in mod code follows the same order.
Additional notes for modders: - Because this is a struct and implements IComponentData, store and manipulate it via the ECS API (EntityManager / Systems) rather than trying to treat it as a managed reference type. - When creating persistent changes to building coverage, ensure you coordinate with game save/load serialization; the struct implements ISerializable and will be serialized by the game's entity serializer if attached to an entity that gets saved. - If temporarily overriding values, consider restoring original values when your mod is unloaded or when the override should end to avoid unintended persistent behavior.