Skip to content

Game.Net.Density

Assembly:
Assembly-CSharp (game) — best-effort; actual assembly may vary between game builds.

Namespace: Game.Net

Type: struct

Base: System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable

Summary: Density is a small ECS component/serializable struct that holds a single floating-point density value. It is intended to be used with Unity.Entities (as an IComponentData / query parameter) and with the game's serialization system (Colossal.Serialization.Entities) for writing/reading the value across network or persistence boundaries. The semantic meaning (scale, units, valid range) is determined by the system that consumes this component.


Fields

  • public System.Single m_Density
    Holds the density value. Stored as a single-precision float. No additional validation is performed by this type; consumers decide expected ranges and interpretation.

Properties

  • None.
    This type exposes a public field rather than properties for direct read/write access.

Constructors

  • Implicit default constructor (public)
    No explicit constructors are defined in the source; create instances via object/collection initialization, e.g. new Density { m_Density = 0.5f }.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_Density float to the provided writer. Used by the game's serialization pipeline to persist or network the value.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads a float from the provided reader into m_Density. Used by the game's deserialization pipeline.

Usage Example

// Create and assign the component to an entity (Unity.Entities)
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = em.CreateEntity(typeof(Game.Net.Density));
em.SetComponentData(entity, new Game.Net.Density { m_Density = 0.75f });

// Example of manual serialization (writer/reader types come from the mod/game API)
void SaveDensity<TWriter>(ref Game.Net.Density d, TWriter writer) where TWriter : IWriter
{
    d.Serialize(writer);
}

void LoadDensity<TReader>(out Game.Net.Density d, TReader reader) where TReader : IReader
{
    d = new Game.Net.Density();
    d.Deserialize(reader);
}

Notes: - Because this type implements IComponentData it is intended for use with Unity's ECS; IQueryTypeParameter allows it to be used as a query parameter in relevant API calls. - ISerializable (Colossal.Serialization.Entities) integration makes this struct suitable for the game's network/persistence systems — the implementation simply forwards a single float to/from the provided reader/writer.