Skip to content

Game.Prefabs.Transformer

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase, IServiceUpgrade

Summary:
Transformer is a prefab component intended for transformer (power) buildings in the game. It registers the runtime data component TransformerData for the prefab and, when creating an entity archetype, conditionally adds the runtime building component Game.Buildings.Transformer and an Efficiency component for city service buildings. It also implements IServiceUpgrade to provide the components required when the building is upgraded (adds transformer runtime component and efficiency component). The class is decorated with a ComponentMenu attribute so it appears under Buildings/CityServices/ in the editor and is associated with BuildingPrefab and BuildingExtensionPrefab types.


Fields

  • This class does not declare any instance fields in the source file.
    Additional info: all state is provided via added ECS components (TransformerData, Game.Buildings.Transformer, Efficiency) rather than instance fields.

Properties

  • This class does not declare any properties.
    Additional info: it implements IServiceUpgrade (providing GetUpgradeComponents) but exposes no explicit properties.

Constructors

  • public Transformer()
    This class relies on the implicit parameterless constructor provided by the compiler. No explicit construction logic is defined in the source.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the prefab/runtime component types that should be present on any prefab that includes this Transformer component. Specifically, it always adds TransformerData (ComponentType.ReadWrite).

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    When the prefab is converted into an entity archetype this method is called to add the necessary runtime components: if the prefab does not already include a ServiceUpgrade component, it adds Game.Buildings.Transformer. If the prefab also has a CityServiceBuilding component, it additionally adds Efficiency. This conditional logic prevents duplicate/undesired components when upgrades are handled separately.

  • public void GetUpgradeComponents(HashSet<ComponentType> components)
    Implementation of IServiceUpgrade. Adds the components that should be present for an upgraded service: Game.Buildings.Transformer and Efficiency (both as read/write ComponentType). This is used when applying a service upgrade so the upgraded entity receives the correct runtime components.

Additional note: The class is marked with [ComponentMenu("Buildings/CityServices/", new Type[] { typeof(BuildingPrefab), typeof(BuildingExtensionPrefab) })] so it is exposed in the prefab component menu under that path.

Usage Example

// The Transformer component itself registers TransformerData for prefabs and
// provides the runtime components required for normal and upgraded transformer buildings.
// Example: how the component adds its prefab components (already implemented in Transformer):
public override void GetPrefabComponents(HashSet<ComponentType> components)
{
    components.Add(ComponentType.ReadWrite<TransformerData>());
}

// Example: how an upgrader system might consume IServiceUpgrade to add upgrade components:
var upgradeComponents = new HashSet<ComponentType>();
IServiceUpgrade upgradeComponent = /* get Transformer instance from prefab */;
upgradeComponent.GetUpgradeComponents(upgradeComponents);
// upgradeComponents now contains Game.Buildings.Transformer and Efficiency