Game.Prefabs.Modes.WaterPoweredMode
Assembly:
Namespace: Game.Prefabs.Modes
Type: class
Base: LocalModePrefab
Summary:
Component prefab used to apply mode-specific multipliers to water-powered building prefabs. WaterPoweredMode contains an array of ModeData entries that map a PrefabBase to production and capacity factors. At runtime the mod writes those values into the ECS component WaterPoweredData for the target prefab's Entity. The class also provides a method to restore the default values from the MonoBehaviour component.
This component is decorated with the Unity attribute [ComponentMenu("Modes/Mode Component/", new Type[] { })], so it can be added to prefabs via the Unity inspector.
Fields
-
public ModeData[] m_ModeDatas
Array of ModeData entries. Each entry references a PrefabBase and the production/capacity multipliers to apply for that mode. This array is iterated by the methods below to locate the relevant WaterPowered MonoBehaviour and write data into the corresponding ECS entity. -
public class ModeData
(nested) public PrefabBase m_Prefab
Reference to the target prefab (the building prefab whose WaterPowered component will be modified).public float m_ProductionFactor
Production multiplier to apply to the target's WaterPoweredData.public float m_CapacityFactor
Capacity multiplier to apply to the target's WaterPoweredData.
Notes: - If a ModeData entry's m_Prefab does not contain a WaterPowered component, the component logs a critical message and that entry is skipped. - The class expects m_ModeDatas to be non-null; if it is null, calling methods that iterate it will throw.
Properties
- This class does not declare any public properties.
Constructors
public WaterPoweredMode()
Default (parameterless) constructor. Not explicitly defined in source — provided by the compiler. No special initialization is performed by the class itself.
Methods
public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry:- Gets the WaterPowered MonoBehaviour from the referenced PrefabBase.
- If missing, logs a critical error and continues.
- Resolves the ECS Entity for the prefab via prefabSystem.GetEntity(component.prefab).
- Calls entityManager.GetComponentData
(entity) — reading the component data (likely to ensure existence/registration of the component or to mark that it is being tracked). -
Note: This method does not modify data; it simply accesses the component data for every target.
-
public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry: - Retrieves the WaterPowered MonoBehaviour from the referenced PrefabBase.
- If missing, logs a critical error and continues.
- Resolves the ECS Entity for the prefab.
- Reads the current WaterPoweredData from the Entity, overwrites its m_ProductionFactor and m_CapacityFactor with the values from the ModeData entry, and writes the updated component back to the Entity with SetComponentData.
-
Effect: applies the configured multipliers so the ECS representation reflects the selected mode.
-
public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry: - Retrieves the WaterPowered MonoBehaviour from the referenced PrefabBase.
- If missing, logs a critical error and continues.
- Resolves the ECS Entity for the prefab.
- Reads the current WaterPoweredData from the Entity, then sets its m_ProductionFactor and m_CapacityFactor to the default values read from the MonoBehaviour (component.m_ProductionFactor and component.m_CapacityFactor), and writes the updated component back to the Entity.
- Effect: restores the ECS component to the values defined on the MonoBehaviour (defaults).
Behavioral notes: - All methods rely on PrefabSystem.GetEntity to map a PrefabBase to an ECS Entity. If that mapping fails (for example the prefab is not registered), behavior will depend on PrefabSystem.GetEntity implementation (may throw or return an invalid entity). - Missing WaterPowered MonoBehaviour on the referenced PrefabBase results in a critical log and skipping that entry. - No null checks are present for m_ModeDatas itself in the code; callers should ensure it is assigned (or code could be modified to be defensive).
Usage Example
// Example: configuring the component in code (similar to what a prefab inspector would do)
var mode = gameObject.AddComponent<Game.Prefabs.Modes.WaterPoweredMode>();
mode.m_ModeDatas = new Game.Prefabs.Modes.WaterPoweredMode.ModeData[1];
mode.m_ModeDatas[0] = new Game.Prefabs.Modes.WaterPoweredMode.ModeData {
m_Prefab = somePrefabBaseReference,
m_ProductionFactor = 0.75f,
m_CapacityFactor = 1.10f
};
// At runtime the game will call ApplyModeData/RestoreDefaultData to push these values
// into the ECS WaterPoweredData for the prefab's entity.
Additional recommendations: - Validate m_ModeDatas != null before iterating to avoid NullReferenceException. - If you need to support dynamic changes at runtime, call ApplyModeData after changing entries to ensure ECS data is updated. - Ensure the referenced PrefabBase has a WaterPowered MonoBehaviour attached; otherwise the entry will be skipped and an error logged.