Game.Prefabs.Modes.SolarPoweredMode
Assembly:
Assembly-CSharp
Namespace:
Game.Prefabs.Modes
Type:
class
Base:
LocalModePrefab
Summary:
SolarPoweredMode is a LocalModePrefab component used to modify SolarPoweredData for one or more prefabs when a mode is applied. The component holds an array of ModeData entries, each pointing to a prefab and a production multiplier. When ApplyModeData is invoked, the component multiplies the current SolarPoweredData.m_Production by the specified multiplier. RecordChanges queries the component data to ensure it is loaded/cached by the EntityManager/PrefabSystem, and RestoreDefaultData resets the entity's production back to the prefab's original value stored on the SolarPowered component. If a target PrefabBase does not contain a SolarPowered component, a critical log entry is written.
Fields
-
public ModeData[] m_ModeDatas
Holds the list of ModeData entries for this mode. Each entry specifies a PrefabBase target and a production multiplier to apply. -
(Nested)
public class ModeData
Serializable data holder used by the inspector and serialization. Contains: public PrefabBase m_Prefab
— reference to the target prefab that should have a SolarPowered component.public float m_ProductionMultiplier
— multiplier to apply to the target's production when the mode is applied.
Properties
- (None)
Constructors
- (Implicit)
public SolarPoweredMode()
No explicit constructor is defined; default parameterless constructor is provided by the runtime.
Methods
public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry:- Gets the SolarPowered component from the referenced PrefabBase (m_Prefab).
- If missing, logs a critical error and continues.
-
Otherwise obtains the Entity for the SolarPowered.component.prefab via PrefabSystem and calls entityManager.GetComponentData
(entity). Purpose: forces reading/loading of the component data (ensures it is tracked for change recording). -
public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
For each ModeData entry: - Resolves the SolarPowered component from the referenced PrefabBase.
- If missing, logs a critical error and continues.
- Gets the entity and reads its SolarPoweredData via entityManager.GetComponentData
(entity). - Multiplies componentData.m_Production by modeData.m_ProductionMultiplier (casts to int after multiplication).
-
Writes the modified component data back via entityManager.SetComponentData(entity, componentData). Effect: scales production on the targeted entity according to the multiplier.
-
public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
For each ModeData entry: - Resolves the SolarPowered component from the referenced PrefabBase.
- If missing, logs a critical error and continues.
- Gets the entity and its SolarPoweredData.
- Restores componentData.m_Production to the original production value stored on the SolarPowered component (component.m_Production).
- Writes the restored value back to the entity via entityManager.SetComponentData(entity, componentData). Purpose: revert changes made by ApplyModeData back to the prefab's default production.
Notes / Behavior details: - All methods expect that the referenced PrefabBase has a SolarPowered component; otherwise they log via ComponentBase.baseLog.Critical. - ApplyModeData casts the multiplied production to int: componentData.m_Production = (int)((float)componentData.m_Production * multiplier). - RecordChanges does not modify data; it calls GetComponentData likely to register the component for change tracking before applying mode changes.
Usage Example
// Example: construct ModeData in code (in editor this is normally set in the inspector)
var mode = new SolarPoweredMode();
mode.m_ModeDatas = new SolarPoweredMode.ModeData[] {
new SolarPoweredMode.ModeData {
m_Prefab = somePrefabBase, // PrefabBase that has a SolarPowered component
m_ProductionMultiplier = 1.25f // Increase production by 25%
}
};
// At runtime the game or mode system will call:
// mode.RecordChanges(entityManager, prefabSystem);
// mode.ApplyModeData(entityManager, prefabSystem);
// and later to revert:
// mode.RestoreDefaultData(entityManager, prefabSystem);