Skip to content

Game.IndustrialProperty

Assembly: Game
Namespace: Game.Buildings

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: Represents an industrial building's resource type for the ECS (Entity Component System). This lightweight value-type component stores which resource(s) an industrial property produces or uses and implements serialization so it can be saved/loaded with the game's serialization system. It is intended to be attached to building entities in the game's ECS world and used in queries and systems that operate on industrial properties.


Fields

  • public Resource m_Resources Stores the resource identifier(s) associated with this industrial property. The Resource type is an enum defined in Game.Economy. The value is serialized as a uint when saved.

Properties

  • This type defines no CLR properties. It is a plain data component (IComponentData) with a public field for data access.

Constructors

  • public IndustrialProperty() Default parameterless constructor provided by the struct. m_Resources will have the default value of the Resource enum (typically zero) unless explicitly assigned.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter Writes the component's contents to the provided writer. Implementation writes the m_Resources field as a uint: writer.Write((uint)m_Resources);

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader Reads the component's contents from the provided reader. Implementation reads a uint and casts it back to the Resource enum: reader.Read(out uint value); m_Resources = (Resource)value;

Notes: - Serialization uses the numeric representation of the Resource enum. Ensure enum values remain stable across versions or implement versioning/mapping if values change. - Because this is a struct component, it should be used with ECS patterns (EntityManager/Systems) rather than as a MonoBehaviour.

Usage Example

// Example: adding the IndustrialProperty component to an entity
using Unity.Entities;
using Game.Economy;
using Game.Buildings;

public void AddIndustrialProperty(EntityManager entityManager, Entity buildingEntity)
{
    var industrial = new IndustrialProperty
    {
        m_Resources = Resource.Iron // example enum value
    };
    entityManager.AddComponentData(buildingEntity, industrial);
}

// Example: manual serialization (pseudocode - actual writer obtained from game save system)
void SaveIndustrialProperty(IndustrialProperty prop, IWriter writer)
{
    // The component itself implements ISerializable, so the save system typically
    // calls its Serialize method. Shown here for clarity:
    prop.Serialize(writer);
}

// Example: manual deserialization (pseudocode)
IndustrialProperty LoadIndustrialProperty(IReader reader)
{
    var prop = new IndustrialProperty();
    prop.Deserialize(reader);
    return prop;
}