Skip to content

Game.Buildings.ServiceUsage

Assembly:
Assembly-CSharp (typical for Cities: Skylines 2 mod code; this type is defined in the game's mod/game assembly)

Namespace: Game.Buildings

Type: struct

Base: Implements: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable

Summary: A lightweight ECS component that stores a single floating-point value representing a building's service usage. The struct is serializable via the Colossal Serialization interfaces (IReader/IWriter) so instances can be persisted and restored. It is suitable for use in Unity.Entities (DOTS) workflows and can be used as a query parameter in entity queries.


Fields

  • public float m_Usage This field holds the service usage value for a building. It is a simple float (units and valid range are determined by game logic that reads/writes this component). Default value for a new struct is 0.0f.

Properties

  • This type has no properties. The component exposes its data via the public field m_Usage.

Constructors

  • public ServiceUsage()
    As a value type (struct), ServiceUsage has the implicit parameterless constructor that initializes m_Usage to 0.0f. You can also construct it with an object initializer: new ServiceUsage { m_Usage = 1.0f }.

Methods

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the m_Usage value from the provided reader. Called by the Colossal.Serialization system when restoring component data.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_Usage value to the provided writer. Called by the Colossal.Serialization system when persisting component data.

Both methods are generic and constrained to the respective reader/writer interfaces used by the game's serialization framework.

Usage Example

// Add the component to an entity with an initial usage value
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = entityManager.CreateEntity();
entityManager.AddComponentData(e, new Game.Buildings.ServiceUsage { m_Usage = 0.75f });

// Read the usage in a system or outside
var usageComp = entityManager.GetComponentData<Game.Buildings.ServiceUsage>(e);
float currentUsage = usageComp.m_Usage;

// Update the value
usageComp.m_Usage = Mathf.Clamp01(currentUsage + 0.1f);
entityManager.SetComponentData(e, usageComp);

// Serialization is handled by the game's serialization pipeline via the Serialize/Deserialize methods.
// If you implement custom reader/writer usage for tests, it would look like:
// writer.Write(usageComp.m_Usage);
// reader.Read(out usageComp.m_Usage);

{{ This component is intended to be stored on building-related entities to track per-building service usage. Because it implements IComponentData it can be used inside Jobs and ECS systems; because it implements ISerializable it will participate in the game's save/load serialization flow. }}