Game.Prefabs.Modes.SewageOutletMode
Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Modes
Type: class
Base: LocalModePrefab
Summary:
SewageOutletMode is a mode prefab component used to apply mode-specific data to SewageOutlet entities. It contains an array of ModeData entries (each pointing to a prefab and providing multiplier / purification values). At runtime the mode can record current ECS component values, apply modified values (capacity multiplier and purification), and restore defaults from the original SewageOutlet prefab values. The implementation uses the ECS EntityManager / PrefabSystem to fetch and set SewageOutletData on the corresponding entities and logs a critical error if the referenced prefab does not contain a SewageOutlet component.
Fields
public ModeData[] m_ModeDatas
Holds the list of ModeData entries. Each entry targets a prefab and provides parameters to alter the SewageOutletData on that prefab's entity.
Nested class ModeData fields:
- public PrefabBase m_Prefab
Reference to the target prefab (used to find the SewageOutlet component and its runtime entity).
-
public float m_CapacityMultifier
Multiplier applied to the SewageOutletData.m_Capacity when ApplyModeData runs. Note: name appears to have a minor typo ("Multifier" instead of "Multiplier"). -
public float m_Purification
Value to set on SewageOutletData.m_Purification when ApplyModeData runs.
Properties
- (No public properties declared on this class. Inherited properties may exist on LocalModePrefab.)
Constructors
public SewageOutletMode()
Default constructor (compiler-generated). No custom initialization present in the source.
Methods
public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry:- Gets the SewageOutlet component from the referenced prefab.
- Logs a critical error and continues if the component is missing.
- Uses prefabSystem.GetEntity(component.prefab) to get the runtime Entity.
- Calls entityManager.GetComponentData
(entity) — this reads the current component data from the entity (the method currently ignores returned value, presumably to ensure the data exists or to mark it for recording).
Notes: - This method may throw if the entity is invalid or the component is missing; callers should ensure prefabSystem returns a valid entity and that SewageOutletData exists on that entity.
public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry:- Resolves the SewageOutlet component from the prefab; logs and continues if missing.
- Retrieves the entity from the PrefabSystem.
- Reads SewageOutletData from the entity.
- Sets componentData.m_Capacity to (int)(originalCapacity * m_CapacityMultifier).
- Sets componentData.m_Purification to m_Purification.
- Writes the modified componentData back to the entity using SetComponentData.
Notes: - Changes are permanent until RestoreDefaultData is called or another change is applied. - If prefabSystem.GetEntity returns Entity.Null or the entity does not have SewageOutletData, GetComponentData will throw. Consider validating before calling.
public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry:- Resolves the SewageOutlet component from the prefab; logs and continues if missing.
- Gets the entity for the prefab.
- Reads current SewageOutletData from the entity.
- Restores componentData.m_Capacity and componentData.m_Purification from the values on the SewageOutlet component (the original prefab defaults).
- Writes the restored data back via SetComponentData.
Notes: - This restores values using the prefab's component fields rather than a previously saved snapshot. - If the prefab component values differ from what was originally used at runtime, the restored values will reflect the prefab's current values.
Usage Example
Basic safer pattern for applying mode data — includes entity and component existence checks:
// Example: call from a manager that has valid EntityManager and PrefabSystem references
foreach (var modeData in mySewageOutletMode.m_ModeDatas)
{
var outletPrefabComp = modeData.m_Prefab?.GetComponent<SewageOutlet>();
if (outletPrefabComp == null)
{
ComponentBase.baseLog.Critical($"Target not found {mySewageOutletMode}");
continue;
}
Entity entity = prefabSystem.GetEntity(outletPrefabComp.prefab);
if (entity == Entity.Null)
{
ComponentBase.baseLog.Critical($"Entity not found for prefab {outletPrefabComp.prefab}");
continue;
}
if (!entityManager.HasComponent<SewageOutletData>(entity))
{
ComponentBase.baseLog.Critical($"SewageOutletData missing on entity {entity}");
continue;
}
var data = entityManager.GetComponentData<SewageOutletData>(entity);
data.m_Capacity = (int)(data.m_Capacity * modeData.m_CapacityMultifier);
data.m_Purification = modeData.m_Purification;
entityManager.SetComponentData(entity, data);
}
Additional notes and tips: - Validate prefab references in the editor to avoid runtime errors. - Consider storing original values (snapshots) if prefabs can change at runtime and you need to reliably restore to pre-mode state. - Check for typos in field names (m_CapacityMultifier) to keep consistent naming across code and editor.