Game.Prefabs.Battery
Assembly:
Game (prefab/component code for the game; may be compiled into the main game assembly)
Namespace: Game.Prefabs
Type:
class
Base:
ComponentBase, IServiceUpgrade
Summary:
Represents a battery building prefab component used by the game's ECS-prefab system. Exposes tuning fields for power output and storage capacity, registers the required ECS components for the prefab and its archetype(s), and initializes the runtime BatteryData component on an entity with the configured values. The class also supplies extra components used when the building is part of a city service building or when an upgrade is applied.
Fields
-
public int m_PowerOutput
Power output value for the battery prefab. This value is copied into the BatteryData component during Initialize and used by the runtime systems that simulate/distribute power. -
public int m_Capacity
Energy storage capacity for the battery prefab. This value is copied into the BatteryData component during Initialize and used by runtime systems that track stored energy.
Properties
- This class declares no public properties.
Constructors
public Battery()
No explicit constructor is declared in source; the default parameterless constructor is used. Initialization of battery runtime data happens in Initialize(EntityManager, Entity) rather than a constructor.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the component types the prefab requires on all instances. Specifically it adds ComponentType.ReadWrite(), so every entity created from this prefab will include BatteryData. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds component types required by the archetype depending on other components present on the prefab GameObject: -
If there is no ServiceUpgrade component on the prefab, the method:
- Adds Efficiency when the prefab has a CityServiceBuilding component.
- Adds Game.Buildings.Battery for runtime battery logic. This method tailors the archetype components based on whether the prefab participates in service-upgrade logic or is a city service building.
-
public void GetUpgradeComponents(HashSet<ComponentType> components)
Implements IServiceUpgrade to declare which components should be present when an upgrade is applied. Adds Game.Buildings.Battery and Efficiency component types to the upgrade archetype. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is instantiated into an entity. Writes a BatteryData instance to the entity using the current m_Capacity and m_PowerOutput values: entityManager.SetComponentData(entity, new BatteryData { m_Capacity = m_Capacity, m_PowerOutput = m_PowerOutput });
This binds the designer-configured prefab values into the ECS data used by simulation systems.
Usage Example
// Example: configure a Battery prefab and initialize an entity with it.
// In practice Battery is used as a component on a prefab GameObject and
// the engine calls GetPrefabComponents/GetArchetypeComponents/Initialize automatically.
Battery myBatteryPrefab = new Battery
{
m_PowerOutput = 120,
m_Capacity = 2000
};
// Later, when creating the entity (pseudo-code; in-engine flow differs):
// myBatteryPrefab.Initialize(entityManager, createdEntity);