Skip to content

Game.Prefabs.GarbagePoweredData

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: struct

Base: IComponentData, IQueryTypeParameter, ICombineData, ISerializable

Summary:
Represents data for a garbage-powered prefab in the ECS world. Stores the capacity (integer units) and the production per unit (float). Designed to be used as an IComponentData for entities, to be combined when multiple data instances need merging, and to be serialized/deserialized for save/load or prefab streaming.


Fields

  • public int m_Capacity
    Holds the capacity value for the garbage-powered entity (e.g., how many units it can process/store). Used in Combine to sum capacities when merging multiple data sources. Serialized first.

  • public float m_ProductionPerUnit
    Per-unit production value (for example power or resource generated per unit of garbage). When combining, the max of the two values is kept. Serialized second.

Properties

  • This type defines no properties.

Constructors

  • public GarbagePoweredData()
    Implicit default struct constructor. Initializes m_Capacity to 0 and m_ProductionPerUnit to 0f unless explicitly assigned.

Methods

  • public void Combine(GarbagePoweredData otherData)
    Merges another instance into this one. Implementation:
  • Adds otherData.m_Capacity to this.m_Capacity (accumulative).
  • Sets this.m_ProductionPerUnit to the maximum of the two production values (keeps the higher production-per-unit).

Use case: combining data from stacked prefabs or aggregated entity representations where capacities sum but production-per-unit should reflect the best/most efficient value.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the data members to the provided writer in a deterministic order:
  • m_Capacity (int)
  • m_ProductionPerUnit (float)

Important for save/load compatibility: maintain the same order and types when changing this struct.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads members from the reader into the struct fields in the same order used by Serialize:
  • m_Capacity (int)
  • m_ProductionPerUnit (float)

Note: uses by-ref reading into the struct fields.

Usage Example

// create and combine two data instances
var a = new Game.Prefabs.GarbagePoweredData { m_Capacity = 10, m_ProductionPerUnit = 1.5f };
var b = new Game.Prefabs.GarbagePoweredData { m_Capacity = 5, m_ProductionPerUnit = 2.0f };

a.Combine(b);
// a.m_Capacity == 15
// a.m_ProductionPerUnit == 2.0f

// example serialization (pseudo-API)
using (var writer = new SomeWriter())
{
    a.Serialize(writer);
}

// example deserialization (pseudo-API)
var c = new Game.Prefabs.GarbagePoweredData();
using (var reader = new SomeReader())
{
    c.Deserialize(reader);
}

Additional notes: - Because this type implements IComponentData it is suitable for use with Unity's ECS (Entities) as a component on entities that represent garbage-powered prefabs. - Combine is intended for deterministic aggregation logic; ensure callers expect capacity to accumulate and production-per-unit to be chosen as the maximum. - If the serialized layout changes in future versions, preserve backward compatibility by handling older formats during Deserialize.