Skip to content

Game.Prefabs.BatteryData

Assembly:
Likely Assembly-CSharp (game code); exact assembly not present in source file.

Namespace: Game.Prefabs

Type:
struct

Base:
Implements: IComponentData, IQueryTypeParameter, ICombineData, ISerializable

Summary:
Represents battery prefab data used by the game's ECS. Stores battery capacity and power output, provides a derived "capacityTicks" value (85 ticks per capacity unit), supports combining multiple BatteryData instances (summing capacity and power output), and supports binary serialization/deserialization via generic IWriter/IReader.


Fields

  • public int m_Capacity
    Holds the battery capacity (units are game-specific). Used to compute capacityTicks (capacity * 85).

  • public int m_PowerOutput
    Holds the battery's power output value (units are game-specific). Summed when combining BatteryData.

Properties

  • public long capacityTicks { get; }
    Read-only computed property returning 85 * m_Capacity. Represents the capacity expressed in "ticks" (internal time/step units used by the game).

Constructors

  • public BatteryData()
    Implicit default constructor (value-type). Fields default to zero. No explicit constructors are defined in the source.

Methods

  • public void Combine(BatteryData otherData)
    Combines another BatteryData into this one by adding their m_Capacity and m_PowerOutput values:
  • m_Capacity += otherData.m_Capacity
  • m_PowerOutput += otherData.m_PowerOutput This implements ICombineData and is used when multiple components of the same type need to be merged.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the struct to a writer. Writes two int values in order:

  • m_Capacity
  • m_PowerOutput

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes the struct from a reader. Reads two int values (in the same order they were written) into:

  • m_Capacity
  • m_PowerOutput Uses ref locals to assign directly into the struct fields.

Usage Example

// Create two BatteryData instances
var b1 = new Game.Prefabs.BatteryData { m_Capacity = 10, m_PowerOutput = 5 };
var b2 = new Game.Prefabs.BatteryData { m_Capacity = 4,  m_PowerOutput = 2 };

// Combine b2 into b1
b1.Combine(b2); // b1.m_Capacity == 14, b1.m_PowerOutput == 7

// Read derived value
long ticks = b1.capacityTicks; // 14 * 85 = 1190

// Example serialization (pseudo-code; depends on concrete IWriter/IReader)
using (var streamWriter = /* obtain writer */)
{
    b1.Serialize(streamWriter);
}

using (var streamReader = /* obtain reader */)
{
    var loaded = new Game.Prefabs.BatteryData();
    loaded.Deserialize(streamReader);
    // loaded now has m_Capacity and m_PowerOutput populated from stream
}

Notes: - The struct is intended for use as an ECS component (IComponentData) and for queries (IQueryTypeParameter). - Serialization methods are generic and rely on the provided writer/reader implementations from the game's serialization system.