Skip to content

Game.Prefabs.Modes.WindPoweredMode

Assembly:
Namespace: Game.Prefabs.Modes

Type: class

Base: LocalModePrefab

Summary:
WindPoweredMode is a LocalModePrefab component used to modify runtime data for prefabs that use WindPowered behaviour. It contains an array of ModeData entries that reference target prefabs (PrefabBase) and specify multipliers for wind-related properties. At runtime the component can record entity references and apply or restore changes to the underlying ECS WindPoweredData components for those prefabs. The implementation logs a critical message when a referenced WindPowered component cannot be found on the target PrefabBase.


Fields

  • public ModeData[] m_ModeDatas
    An array of ModeData entries describing which prefabs to affect and which multipliers to apply. Each entry contains a PrefabBase reference and two multipliers (maximum wind and production).

  • (Nested) public class ModeData

  • public PrefabBase m_Prefab
    Reference to the prefab (PrefabBase) which is expected to contain a WindPowered component. Used to resolve the ECS entity via PrefabSystem.
  • public float m_MaximumWindMultiplier
    Multiplier to apply to the target prefab's m_MaximumWind (multiplies the current value).
  • public float m_ProductionMultiplier
    Multiplier applied to the target prefab's m_Production (the code multiplies then casts to int).

Properties

  • None declared in this class.

Constructors

  • public WindPoweredMode()
    Default constructor (not explicitly defined in source — implicit). The component is intended to be configured in the prefab (or via code) by setting the m_ModeDatas array.

Methods

  • public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem) : void
    Scans m_ModeDatas, resolves the WindPowered component on each referenced PrefabBase, gets the corresponding ECS Entity from prefabSystem, and reads the WindPoweredData component via entityManager.GetComponentData(entity). The read seems intended to ensure the component exists / is recorded, but no modifications are performed here. If the WindPowered component is missing on the referenced prefab, a critical log is emitted: ComponentBase.baseLog.Critical($"Target not found {this}");

  • public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem) : void
    Applies the configured multipliers for each ModeData entry:

  • Resolves the WindPowered component from the referenced PrefabBase.
  • Gets the associated ECS entity from PrefabSystem.
  • Reads the current WindPoweredData component, multiplies m_MaximumWind by m_MaximumWindMultiplier, multiplies m_Production by m_ProductionMultiplier and casts to int, then writes the modified component back with entityManager.SetComponentData(entity, componentData). If the target WindPowered component is missing, a critical log is emitted and that entry is skipped.

  • public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem) : void
    Restores the WindPoweredData component to defaults based on values from the referenced prefab's WindPowered component:

  • Resolves the WindPowered component from the PrefabBase.
  • Reads the entity's WindPoweredData and sets m_MaximumWind and m_Production to the values from the prefab component (component.m_MaximumWind and component.m_Production), then writes the restored component back to the entity. If the target WindPowered component is missing, a critical log is emitted and that entry is skipped.

Notes: - All three methods iterate over m_ModeDatas and rely on PrefabBase.GetComponent() to obtain the template values and PrefabSystem.GetEntity(component.prefab) to obtain the entity to operate on. - Logging on missing targets uses ComponentBase.baseLog.Critical, so missing or misconfigured PrefabBase references will generate visible critical logs.

Usage Example

// Example: configuring a WindPoweredMode in code (normally set up in prefab/inspector)
var windMode = new WindPoweredMode();
windMode.m_ModeDatas = new WindPoweredMode.ModeData[]
{
    new WindPoweredMode.ModeData
    {
        m_Prefab = somePrefabBaseReference,           // Prefab that has a WindPowered component
        m_MaximumWindMultiplier = 1.25f,              // Increase max wind by 25%
        m_ProductionMultiplier = 0.9f                 // Reduce production to 90%
    }
};

// At runtime, when you have an EntityManager and PrefabSystem, apply the mode:
windMode.ApplyModeData(entityManager, prefabSystem);

// To restore defaults later:
windMode.RestoreDefaultData(entityManager, prefabSystem);

{{ This component is designed to be used as part of a mode system that adjusts building/producer behavior based on game modes or settings. Ensure referenced PrefabBase objects actually contain a WindPowered component and that the ECS WindPoweredData exists on the prefab entity; otherwise entries will be skipped and a critical log emitted. }}