Game.Prefabs.BuildingEfficiency
Assembly:
Unknown (likely the game's main assembly, e.g., Assembly-CSharp or Game.dll)
Namespace: Game.Prefabs
Type: class
Base: ComponentBase, implements IServiceUpgrade
Summary:
BuildingEfficiency is a prefab component used by building prefabs to ensure an Efficiency component (Unity.Entities component type Efficiency) is added to the entity archetype or to the upgrade archetype depending on whether the prefab exposes a ServiceUpgrade. The class registers no prefab runtime data itself (GetPrefabComponents is intentionally empty) and controls only which ECS components are included on the building entity or its upgrade entities.
Fields
- This class declares no instance or static fields.
The behavior is entirely implemented via overrides and interface implementation; it does not store data on the Mono/Component side.
Properties
- This class declares no public or private properties.
Constructors
public BuildingEfficiency()
The class has the implicit default parameterless constructor. No special construction logic is defined.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
This override is intentionally empty. BuildingEfficiency does not add components at the "prefab components" collection stage. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
If the associated prefab does NOT have a ServiceUpgrade (checked via base.prefab.Has()), this method adds a read/write Efficiency component to the building's archetype: components.Add(ComponentType.ReadWrite ());
This means non-upgradable prefabs will include Efficiency on the main entity. -
public void GetUpgradeComponents(HashSet<ComponentType> components)
Implementation of IServiceUpgrade. Always adds a read/write Efficiency component to the upgrade archetype: components.Add(ComponentType.ReadWrite());
When a prefab supports service/upgrades (i.e., has ServiceUpgrade), Efficiency will instead be added to the upgrade entity via this method.
Notes:
- ComponentType.ReadWrite
Usage Example
// Example: how BuildingEfficiency affects component composition for a BuildingPrefab
// If prefab does NOT have ServiceUpgrade:
var prefab = /* building prefab without ServiceUpgrade */;
var components = new HashSet<ComponentType>();
// During archetype setup the prefab system calls:
buildingEfficiency.GetArchetypeComponents(components);
// Result: components contains ComponentType.ReadWrite<Efficiency>()
// Efficiency will be part of the building entity's archetype.
// If prefab DOES have ServiceUpgrade:
var prefabWithUpgrade = /* building prefab with ServiceUpgrade */;
var archetypeComponents = new HashSet<ComponentType>();
buildingEfficiency.GetArchetypeComponents(archetypeComponents);
// Result: archetypeComponents does NOT contain Efficiency.
var upgradeComponents = new HashSet<ComponentType>();
// When constructing upgrade archetype the system calls:
buildingEfficiency.GetUpgradeComponents(upgradeComponents);
// Result: upgradeComponents contains ComponentType.ReadWrite<Efficiency>()
// Efficiency will be part of the upgrade entity instead.
{{ Additional info: - The class is exposed in the component menu by the attribute [ComponentMenu("Buildings/", new Type[] { typeof(BuildingPrefab) })], which places it under Buildings/ when adding components in editor tooling. - This pattern separates components that should exist on the base building versus only on upgrade/service variants, enabling flexible ECS archetype composition for building prefabs. }}