Game.Zones.VacantLot
Assembly: Game (assembly not specified)
Namespace: Game.Zones
Type: struct
Base: IBufferElementData, IEquatable
Summary:
VacantLot is an ECS buffer element used to represent a vacant lot region for zoning/lot placement in the game. It stores the rectangular area, zone type, an optional height value and flags. It is annotated with InternalBufferCapacity(1) so small numbers of lots can be stored inline in an entity's chunk before overflow to dynamic memory. The struct also implements custom binary serialization compatible with the game's versioned save format and implements equality/hash behavior used by ECS logic.
Fields
-
public int4 m_Area
Stores the lot rectangle as an int4 packed as (minX, maxX, minY, maxY). This encodes the bounds of the vacant lot in tile/coordinate space (uses Unity.Mathematics.int4). -
public ZoneType m_Type
The zone type assigned to the lot (e.g., Residential, Commercial, Industrial). ZoneType is a game enum representing zoning categories. -
public short m_Height
Height of the lot (stored as a short). Note: older save versions may not contain this field; Deserialize will set it to short.MaxValue when the saved version predates the height feature. -
public LotFlags m_Flags
Flags for the lot (bitmask stored in LotFlags). In the serialized form this is stored as a single byte when the save version supports corner buildings/flags.
Properties
- None. This struct exposes only public fields and implements IBufferElementData; there are no C# properties.
Constructors
public VacantLot(int2 min, int2 max, ZoneType type, int height, LotFlags flags)
Creates a VacantLot by packing min/max into m_Area, setting m_Type, converting height to short, and storing m_Flags. Use int2 from Unity.Mathematics for min and max coordinates.
Example: - min = (minX, minY) - max = (maxX, maxY) The constructor stores them in m_Area as (minX, maxX, minY, maxY).
Methods
-
public bool Equals(VacantLot other)
Equality implementation from IEquatable. It compares only m_Area (the rectangle). Note: it intentionally ignores type, height and flags when deciding equality. -
public override int GetHashCode()
Computes a hash code using m_Area and m_Type: (17 * 31 + m_Area.GetHashCode()) * 31 + m_Type.GetHashCode(). Warning: Equals compares only m_Area while the hash includes m_Type — this can lead to hash/equality inconsistencies if lots with same area but different type are used in hash-based collections. -
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the fields in order: m_Area (int4), m_Type (ZoneType), m_Height (short) and m_Flags (as a single byte). This is the write path for saving data to the game's binary format. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads fields with backward-compatibility checks: - Reads m_Area and m_Type unconditionally.
- If reader.context.version >= Version.zoneHeightLimit then reads m_Height; otherwise sets m_Height = short.MaxValue (meaning height data not present / unknown for older versions).
- If reader.context.version >= Version.cornerBuildings then reads a byte and casts it to LotFlags into m_Flags; otherwise m_Flags is left at the default value (zero). This method relies on reader.context.version and game-specific Version constants to handle multiple save-schema versions.
Usage Example
using Unity.Mathematics;
using Unity.Entities;
// create a VacantLot and add it to an entity's dynamic buffer
var lot = new VacantLot(new int2(0,0), new int2(10,12), ZoneType.Residential, 3, LotFlags.None);
// assuming 'entityManager' and 'entity' exist and the entity has a DynamicBuffer<VacantLot>
var buffer = entityManager.GetBuffer<VacantLot>(entity);
buffer.Add(lot);
// Serialization is handled by game save/load using the IWriter/IReader implementations.
// The struct's Deserialize method will handle older save versions for height and flags.