Skip to content

Game.Prefabs.ServiceUpgrade

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
ServiceUpgrade is a prefab component used by building/net/route prefabs to define an upgrade that can be applied to services/buildings. It carries data such as the list of target building prefabs that are part of the upgrade, the upgrade cost, XP reward, and placement constraints. At initialization it writes a ServiceUpgradeData component to the entity and, during LateInitialize, registers the target building prefabs with the entity's ServiceUpgradeBuilding buffer and notifies each referenced BuildingPrefab about the upgrade.


Fields

  • public BuildingPrefab[] m_Buildings
    Array of BuildingPrefab references that are included in this upgrade. During LateInitialize each non-null entry is resolved to an entity and a ServiceUpgradeBuilding entry is appended to the prefab entity's buffer. Also each referenced BuildingPrefab receives this ServiceUpgrade via its AddUpgrade method.

  • public uint m_UpgradeCost = 100u
    Cost (in game currency) required to perform the upgrade. This value is written into the ServiceUpgradeData component during Initialize.

  • public int m_XPReward
    Experience points awarded to the player when the upgrade is applied. Written into ServiceUpgradeData.

  • public int m_MaxPlacementOffset = -1
    Maximum allowed placement offset (in tiles/units as used by the game) for placing upgrade objects relative to the parent; default -1 typically means no special offset limit. Copied into ServiceUpgradeData.

  • public float m_MaxPlacementDistance
    Maximum placement distance for the upgrade (float). Copied into ServiceUpgradeData.

Properties

  • None. This component exposes no public C# properties; all configuration is done via public fields serialized on the prefab.

Constructors

  • public ServiceUpgrade()
    Default parameterless constructor (compiler-provided). The component relies on serialized field defaults and the prefab lifecycle methods (Initialize / LateInitialize) to populate ECS components and buffers.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds any referenced BuildingPrefab entries (m_Buildings) to the provided prefabs dependency list. Ensures those prefabs are loaded/considered before this prefab.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Registers ECS components that this prefab will require:

  • Always adds ServiceUpgradeData and ServiceUpgradeBuilding (read/write).
  • If the prefab also contains a BuildingPrefab component, it adds PlaceableObjectData and PlaceableInfoviewItem.
  • If the prefab's ServiceConsumption component exists and has m_Upkeep > 0, it also adds ServiceUpkeepData. This controls what component types are present on the created entity.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds the Game.Buildings.ServiceUpgrade component type to the prefab archetype components. This is used by the entity archetype system.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Writes a ServiceUpgradeData component to the entity with values taken from the prefab fields (m_UpgradeCost, m_XPReward, m_MaxPlacementOffset, m_MaxPlacementDistance). Called when the prefab entity is being created.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Performs post-initialization linking:

  • If m_Buildings is null, returns early.
  • Retrieves the PrefabSystem from the entityManager.World.
  • For each non-null BuildingPrefab in m_Buildings:
    • Resolves the BuildingPrefab to an Entity via PrefabSystem.GetEntity and appends a ServiceUpgradeBuilding entry referencing that entity into the entity's buffer.
    • Calls buildingPrefab.AddUpgrade(entityManager, this) to let the BuildingPrefab register the upgrade (so buildings know about available upgrades).

Notes / Side effects: - LateInitialize depends on PrefabSystem being present in the World. - GetPrefabComponents conditionally adds ServiceUpkeepData only when the prefab consumes upkeep (ServiceConsumption.m_Upkeep > 0).

Usage Example

// Example: programmatically configuring a ServiceUpgrade on a prefab (e.g. in an editor setup script)
var upgrade = new ServiceUpgrade();
upgrade.m_UpgradeCost = 500u;
upgrade.m_XPReward = 10;
upgrade.m_MaxPlacementOffset = 2;
upgrade.m_MaxPlacementDistance = 12.0f;
upgrade.m_Buildings = new BuildingPrefab[] { someBuildingPrefabA, someBuildingPrefabB };

// When the prefab is converted to an Entity, Initialize will write ServiceUpgradeData and
// LateInitialize will resolve m_Buildings into ServiceUpgradeBuilding buffer entries.

Further notes: - The component is decorated with [ComponentMenu("Buildings/", ...)] and is intended to be used on BuildingPrefab, BuildingExtensionPrefab, NetPrefab, and RoutePrefab prefabs. - The prefab/ecs component types involved: - ServiceUpgradeData (stores cost, XP, placement constraints) - ServiceUpgradeBuilding (buffer entries referencing building entities) - PlaceableObjectData / PlaceableInfoviewItem (for placeable building prefabs) - ServiceUpkeepData (conditionally added when consumption/upkeep > 0) - Archetype includes Game.Buildings.ServiceUpgrade for archetype-level data.