Skip to content

Game.Prefabs.Modes.GarbagePoweredMode

Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Modes

Type: class

Base: LocalModePrefab

Summary:
Modifies GarbagePoweredData on entity prefabs referenced by ModeData entries when a mode is applied, restored or recorded. Each ModeData links to a Prefab (PrefabBase) and provides multipliers for production-per-unit and capacity. The class uses EntityManager and PrefabSystem to locate the entity for a prefab and read/write GarbagePoweredData. If the target prefab lacks a GarbagePowered component the code logs a critical error and skips that entry.


Fields

  • public ModeData[] m_ModeDatas
    Holds the list of ModeData entries (serializable inner class) that define which prefabs to affect and the multipliers to apply. Typically set in the prefab inspector.

Inner class ModeData (serializable) - public PrefabBase m_Prefab
Prefab reference whose GarbagePowered component/entity will be modified. - public float m_ProductionPerUnitMultiplier
Multiplier applied to the prefab's m_ProductionPerUnit value in GarbagePoweredData. - public float m_CapacityMultiplier
Multiplier applied to the prefab's m_Capacity value in GarbagePoweredData.

Properties

  • (none)

Constructors

  • public GarbagePoweredMode()
    Default constructor (implicit). Instances are typically created/initialized by the Unity prefab system / inspector.

Methods

  • public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
    Iterates all m_ModeDatas and for each:
  • Retrieves the GarbagePowered component from the referenced PrefabBase.
  • If missing, logs a critical error and continues.
  • Resolves the corresponding Entity via prefabSystem.GetEntity(component.prefab).
  • Calls entityManager.GetComponentData(entity) to read the data (the return value is not stored). This appears intended to ensure the component exists / to register that this entity's component is relevant for mode changes.

Notes: May throw if the entity does not have GarbagePoweredData; the intent is to force the entity/components to be considered by change tracking.

  • public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
    For each ModeData entry:
  • Retrieves GarbagePowered from the referenced prefab; logs and skips if missing.
  • Resolves the target Entity.
  • Reads existing GarbagePoweredData via entityManager.GetComponentData(entity).
  • Multiplies m_ProductionPerUnit by m_ProductionPerUnitMultiplier and casts to int.
  • Multiplies m_Capacity by m_CapacityMultiplier and casts to int.
  • Writes the modified GarbagePoweredData back with entityManager.SetComponentData(entity, componentData).

Warnings: - Multiplication results are cast to int, truncating fractional values. - Applying the same mode multiple times without restoring defaults will repeatedly multiply already-modified values.

  • public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
    For each ModeData entry:
  • Retrieves GarbagePowered from the referenced prefab; logs and skips if missing.
  • Resolves the target Entity.
  • Reads the current GarbagePoweredData.
  • Restores m_ProductionPerUnit and m_Capacity to the original values taken from the GarbagePowered component instance on the Prefab (component.m_ProductionPerUnit, component.m_Capacity).
  • Writes restored values back with entityManager.SetComponentData(entity, componentData).

Notes: - This relies on the prefab's GarbagePowered component to contain the original/default values.

Usage Example

// Example: apply mode multipliers at runtime (requires valid EntityManager and PrefabSystem)
GarbagePoweredMode mode = /* obtain from prefab or created instance */;
mode.m_ModeDatas = new GarbagePoweredMode.ModeData[]
{
    new GarbagePoweredMode.ModeData
    {
        m_Prefab = somePrefabReference,
        m_ProductionPerUnitMultiplier = 0.75f,
        m_CapacityMultiplier = 1.2f
    }
};

// Apply changes (e.g. when enabling the mode)
mode.ApplyModeData(entityManager, prefabSystem);

// Restore defaults (e.g. when disabling the mode)
mode.RestoreDefaultData(entityManager, prefabSystem);

Additional notes: - The class expects target prefabs to include a GarbagePowered component and that the ECS entity linked to the prefab contains a GarbagePoweredData component. - Missing components are logged via ComponentBase.baseLog.Critical and that ModeData entry is skipped. - Since ApplyModeData mutates component data in-place, be careful to avoid reapplying without a prior RestoreDefaultData if you want consistent results.