Skip to content

Game.Areas.DistrictModifier

Assembly:
Namespace: Game.Areas

Type: struct

Base: IBufferElementData, ISerializable

Summary:
DistrictModifier is an ECS buffer element used to store a 2D delta value (float2) that modifies district-related data. It is a value-type component intended to be stored in a DynamicBuffer on an entity. The type implements custom serialization/deserialization using Colossal.Serialization and contains a version-aware Deserialize implementation to maintain compatibility with older save formats (where only a single float component was stored).


Fields

  • public Unity.Mathematics.float2 m_Delta
    Stores the X/Y delta vector applied by this modifier. Uses Unity.Mathematics.float2 for compact numeric storage and math operations. The struct is annotated with [InternalBufferCapacity(0)], so buffer elements are stored in the dynamic buffer area (no inline capacity in entity chunks).

Properties

  • None. (This is a plain buffer element struct; no properties are defined.)

Constructors

  • public DistrictModifier()
    Default parameterless struct constructor (value-type). Typical usage is by assignment or Add on the DynamicBuffer.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the full float2 m_Delta to the provided writer. This ensures both X and Y components are saved for current versions.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads data from the provided reader. This method is version-aware:

  • If reader.context.version >= Version.modifierRefactoring, it reads the full float2 into m_Delta.
  • Otherwise (older versions), it only reads a single float into m_Delta.y (legacy layout), leaving the other component unaffected or defaulted. This preserves compatibility with older save data that stored only a single component.

Usage Example

// Add a buffer and push a modifier
var buffer = entityManager.AddBuffer<Game.Areas.DistrictModifier>(entity);
buffer.Add(new Game.Areas.DistrictModifier { m_Delta = new Unity.Mathematics.float2(1.0f, -0.5f) });

// Iterate modifiers
DynamicBuffer<Game.Areas.DistrictModifier> modifiers = entityManager.GetBuffer<Game.Areas.DistrictModifier>(entity);
foreach (var mod in modifiers)
{
    float2 d = mod.m_Delta;
    // apply d to district data...
}

// Serialization is handled by the ISerializable implementation when saving/loading.
// The Deserialize method handles older save versions (Version.modifierRefactoring) where only the Y component was stored.

Additional notes: - The Version.modifierRefactoring flag referenced in Deserialize is defined elsewhere in the game's versioning code; it controls the backwards-compatibility path. - Because this is an IBufferElementData, use dynamic buffers (EntityManager.AddBuffer, GetBuffer) to manage collections of these modifiers per entity.