Game.Prefabs.SolarPowered
Assembly:
Game (assembly inferred from file path)
Namespace:
Game.Prefabs
Type:
class
Base:
ComponentBase, implements IServiceUpgrade
Summary:
SolarPowered is a prefab component used to mark and configure a solar-powered building in the ECS-based game. It requires a PowerPlant component on the GameObject and is exposed in the Buildings/CityServices component menu. The component:
- Exposes an m_Production value (int) representing the solar production output used to populate the runtime SolarPoweredData component.
- Adds a SolarPoweredData component to the prefab.
- When no ServiceUpgrade component is present on the GameObject, it adds Efficiency and RenewableElectricityProduction components to the entity archetype so the building participates in renewable electricity systems and efficiency calculations.
- Implements IServiceUpgrade to provide upgrade-time component additions (adds Efficiency for upgrades).
Fields
public int m_Production
Holds the configured electricity production value for the solar prefab. This value is written into the runtime SolarPoweredData component during Initialize and represents how much electricity the solar building produces (units and scaling depend on game systems).
Properties
- This class does not declare any C# properties.
Constructors
public SolarPowered()
Implicit parameterless constructor (no explicit constructor is defined in the source).
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the runtime component type SolarPoweredData (ReadWrite) to the prefab’s component list so the ECS entity will include that component when the prefab is instantiated. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
If the GameObject does not have a ServiceUpgrade component, adds Efficiency and RenewableElectricityProduction (both ReadWrite) to the archetype component set. This ensures non-upgrade variants of the prefab get these components at entity creation. -
public void GetUpgradeComponents(HashSet<ComponentType> components)
(Implementation of IServiceUpgrade) Adds the Efficiency component (ReadWrite) to the set of components applied when the building is used as an upgrade. -
public override void Initialize(EntityManager entityManager, Entity entity)
Writes initial SolarPoweredData into the entity using the inspector-configured m_Production value: entityManager.SetComponentData(entity, new SolarPoweredData { m_Production = m_Production });
Remarks: The class relies on the existence of several data-component types (SolarPoweredData, Efficiency, RenewableElectricityProduction) and on Unity.Entities' ComponentType to declare which components to add. It also expects PowerPlant to be present as a Unity component (RequireComponent).
Usage Example
// The class already sets SolarPoweredData during Initialize using the inspector field m_Production.
// Example snippet showing the Initialize implementation from the prefab component:
public override void Initialize(EntityManager entityManager, Entity entity)
{
entityManager.SetComponentData(entity, new SolarPoweredData
{
m_Production = m_Production
});
}
Additional notes: - Attach this component to a building prefab (which must also have a PowerPlant component) to make it a solar-powered electricity producer in ECS. - If you want the prefab to act as an upgrade (and thus not automatically add RenewableElectricityProduction to the archetype), add a ServiceUpgrade component to the GameObject; otherwise archetype additions are applied.