Skip to content

Game.Buildings.AttractivenessProvider

Assembly: Assembly-CSharp
Namespace: Game.Buildings

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: AttractivenessProvider is a lightweight ECS component that stores a single integer attractiveness value for a building. It implements ISerializable to allow the value to be written/read during serialization and implements IQueryTypeParameter so it can be used as a query parameter in ECS queries. This component is intended for use in Cities: Skylines 2 mod code that uses Unity.Entities to track or expose building attractiveness to systems or save/load code.


Fields

  • public int m_Attractiveness Holds the attractiveness value for the entity (building). This integer is serialized/deserialized by the component's ISerializable implementation. Typical uses: influence calculation, UI display, or passing as data in entity queries.

Properties

  • This type defines no properties. It exposes a single public field (m_Attractiveness).

Constructors

  • Implicit parameterless constructor (public AttractivenessProvider()) As a struct, AttractivenessProvider has the default parameterless constructor automatically; you can also initialize it with an object initializer or a custom constructor if you add one. Example: new AttractivenessProvider { m_Attractiveness = 42 }.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_Attractiveness integer to the provided writer. Used during save/serialization flows to persist the component value.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads an integer from the provided reader into m_Attractiveness. Used when loading/deserializing the component value.

Both methods are generic and constrained to the writer/reader interfaces used by the game's serialization system. They perform simple value read/write operations and do not perform validation — validation should be done by callers/systems if needed.

Usage Example

// Add the component to an entity with a specific attractiveness value
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = entityManager.CreateEntity();
entityManager.AddComponentData(entity, new Game.Buildings.AttractivenessProvider { m_Attractiveness = 75 });

// Example pseudo-serialization (writer/reader types depend on the game's serialization API)
void SaveComponent<TWriter>(ref TWriter writer, in Game.Buildings.AttractivenessProvider comp) where TWriter : IWriter
{
    comp.Serialize(writer);
}

void LoadComponent<TReader>(ref TReader reader, out Game.Buildings.AttractivenessProvider comp) where TReader : IReader
{
    comp = new Game.Buildings.AttractivenessProvider();
    comp.Deserialize(reader);
}

Notes: - Because this is a plain struct component, it is safe and efficient to use in ECS systems and jobs. - The serialization methods rely on the game's IWriter/IReader implementations; ensure compatible writer/reader types are used during save/load.