Game.Prefabs.SpawnableBuildingData
Assembly:
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents a small ECS component used to mark/describe a spawnable building prefab. Contains a reference to the zone prefab (Unity.Entities.Entity) and a building level (byte). Implements Colossal.Serialization's ISerializable so it can be (de)serialized by the game's serialization system (e.g., for saving/loading or prefab persistence). Intended to be used as a lightweight component in Unity.Entities world queries and archetypes.
Fields
-
public Unity.Entities.Entity m_ZonePrefab
Reference to the zone prefab entity associated with this spawnable building. Stored as a Unity.Entities.Entity so it can reference other prefab entities inside the ECS world or prefab database. -
public byte m_Level
Small integer (0–255) representing the building level of this spawnable building. Compact storage using a byte.
Properties
- This type defines no managed properties. It is a plain value-type ECS component with public fields.
Constructors
public SpawnableBuildingData()
No explicit constructor is defined in the source; the default parameterless struct constructor is used. Instances are typically constructed with an object initializer or by the ECS/serialization systems.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Implements ISerializable.Serialize. Writes the component data in order (zone prefab Entity, then level) using the provided writer. This is used by the Colossal.Serialization system to persist or transmit component data.
Behavior details: - Calls writer.Write(m_ZonePrefab) followed by writer.Write(m_Level). - The generic writer must implement IWriter from Colossal.Serialization.Entities (or compatible interface).
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Implements ISerializable.Deserialize. Reads the component data in the same order as Serialize. The method reads into the component's fields by reference.
Behavior details: - Calls reader.Read(out m_ZonePrefab) then reader.Read(out m_Level). - The generic reader must implement IReader from Colossal.Serialization.Entities (or compatible interface). - Ensure reader/writer ordering matches to avoid corrupted data.
Notes: - Because this is an ECS component and a value type, prefer passing or storing copies rather than expecting reference semantics. - When used with the game's serialization pipeline, the ISerializable implementation ensures correct persistence of prefab references and level data.
Usage Example
// Create and assign the component (typical ECS usage)
var spawnData = new SpawnableBuildingData {
m_ZonePrefab = zonePrefabEntity, // previously obtained Entity reference
m_Level = 3
};
// Add to an entity via EntityManager
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = entityManager.CreateEntity();
entityManager.AddComponentData(e, spawnData);
// The game's serialization system will call Serialize/Deserialize automatically
// when persisting/loading prefabs or save data.
{{ Additional info: - Common use: tagging building prefab entities so spawning systems or editors can query for available spawnable building prefabs and their levels. - Because m_ZonePrefab is an Entity, ensure referenced entity exists in the same context (world/prefab container) when deserializing. - The struct implements IQueryTypeParameter, allowing it to be used conveniently in ECS queries or as parameter types in query utilities used by the game. }}