Game.Prefabs.BuildingData
Assembly: Game (Assembly-CSharp)
Namespace: Game.Prefabs
Type: struct BuildingData
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Holds basic prefab-level building data used by the game's ECS. Contains the prefab lot size (int2) and a set of building flags (BuildingFlags). Implements ISerializable to read/write these values to the game's serialization streams and can be used as an ECS component (IComponentData) or in query type parameters (IQueryTypeParameter). Designed for lightweight storage and fast serialization for save/load and prefab instantiation.
Fields
-
public int2 m_LotSize
Represents the dimensions of the building lot (width, height) using Unity.Mathematics.int2. Typically interpreted as grid cells for the prefab's footprint. -
public BuildingFlags m_Flags
Bitmask/enum describing building attributes (e.g., residential/commercial, special behaviors). The BuildingFlags enum is defined elsewhere in the codebase; its numeric value is serialized as an unsigned int.
Properties
- None
Constructors
public BuildingData()
Default struct constructor (value-initialized). You can create and initialize instances with object initializer syntax: var data = new BuildingData { m_LotSize = new int2(2, 3), m_Flags = BuildingFlags.Residential };
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component's data into the provided writer. The method writes m_LotSize (int2) followed by m_Flags cast to uint. Ensure the writer matches the game's expected serialization format/version. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads data from the provided reader into the component. Reads an int2 into m_LotSize (by ref) then reads a uint which is cast to BuildingFlags and assigned to m_Flags. Be mindful of compatibility when reading older/newer save formats.
Usage Example
// Create and use as an ECS component
var data = new BuildingData {
m_LotSize = new int2(2, 3),
m_Flags = BuildingFlags.Residential | BuildingFlags.HasParking
};
entityManager.AddComponentData(entity, data);
// Manual serialization example (framework writer types required)
public void Save<TWriter>(TWriter writer) where TWriter : IWriter
{
var data = new BuildingData { m_LotSize = new int2(2, 3), m_Flags = BuildingFlags.Commercial };
data.Serialize(writer);
}
public void Load<TReader>(TReader reader) where TReader : IReader
{
var data = new BuildingData();
data.Deserialize(reader);
// use data.m_LotSize and data.m_Flags...
}
{{ Additional notes: - Designed as a plain-old-data struct for fast copying and minimal GC impact. - Because flags are serialized as uint, ensure the BuildingFlags underlying values fit into uint and any changes to the enum preserve backward compatibility. - As an IComponentData, this struct is intended to be accessed/modified via EntityManager or System APIs rather than via heavy managed object patterns. }}