Game.Prefabs.Modes.PostFacilityMode
Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Modes
Type: class
Base: LocalModePrefab
Summary:
PostFacilityMode is a LocalModePrefab that lets a prefab author configure mode-specific adjustments for postal facility prefabs (post offices / post facilities and their mailboxes). It contains an array of ModeData entries that reference a target prefab and three multipliers (mail storage, mailbox capacity, sorting rate). At runtime it can record the required components, apply multiplier-based changes to ECS component data (PostFacilityData and optionally MailBoxData) and restore defaults from the original prefab component values. The class uses EntityManager and PrefabSystem to read and write component data on the prefab entity.
Fields
public ModeData[] m_ModeDatas
Array of ModeData entries. Each entry points to a Prefab (PrefabBase) that contains a PostFacility component and provides three multipliers:- m_MailStorageCapacityMultifier — multiplies PostFacilityData.m_MailCapacity
- m_MailBoxCapacityMultifier — multiplies MailBoxData.m_MailCapacity (if MailBoxData exists)
-
m_SortingRateMultifier — multiplies PostFacilityData.m_SortingRate Note: the code spells "Multifier" (matching the source). Multipliers are applied as floats and results cast to int when writing component fields.
-
public class ModeData
Nested serializable class describing a single target prefab and its multipliers: PrefabBase m_Prefab
— reference to the target prefab containing a PostFacility componentfloat m_MailStorageCapacityMultifier
— multiplier for facility storage capacityfloat m_MailBoxCapacityMultifier
— multiplier for mailbox capacityfloat m_SortingRateMultifier
— multiplier for sorting rate
Properties
- None (no public properties are declared in the class)
Constructors
public PostFacilityMode()
Default parameterless constructor (implicit). The component is intended to be configured in the prefab inspector (m_ModeDatas) and used by the prefab/mode system at runtime.
Methods
public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry:- Gets the PostFacility component from the referenced prefab (modeData.m_Prefab.GetComponent
()). - If the component is missing logs a critical error (ComponentBase.baseLog.Critical) and continues.
- Uses prefabSystem.GetEntity(component.prefab) to get the entity for the prefab.
- Calls entityManager.GetComponentData
(entity) to read the PostFacilityData. -
If the entity has a MailBoxData component, reads it as well. Purpose: ensure the relevant components are accessed/registered so that the prefab/mode system knows which components will be altered. This method does not change values.
-
public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
Applies the configured multipliers to the target prefab entities: - For each ModeData, finds the PostFacility component on the referenced prefab. If missing, logs and skips.
- Gets the entity from prefabSystem.
- Reads PostFacilityData, multiplies m_MailCapacity by m_MailStorageCapacityMultifier and m_SortingRate by m_SortingRateMultifier, casts results to int and writes back with entityManager.SetComponentData.
- If MailBoxData exists on the entity, reads it, multiplies m_MailCapacity by m_MailBoxCapacityMultifier (casts to int) and writes it back. Notes:
- Multipliers are applied multiplicatively to the current component values.
- Casting float -> int truncates; fractional results are lost.
-
No clamping or validation is performed; negative or zero multipliers may produce undesirable results.
-
public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
Restores the original values from the PostFacility component on the referenced prefab: - For each ModeData, finds the PostFacility component on the referenced prefab. If missing, logs and skips.
- Gets the entity and reads PostFacilityData; sets m_MailCapacity and m_SortingRate back to the default values from the PostFacility component (component.m_MailStorageCapacity and component.m_SortingRate) and writes them back.
- If MailBoxData exists, restores m_MailCapacity to component.m_MailBoxCapacity from the prefab. Notes:
- This uses the prefab component values as the source of truth for defaults.
Usage Example
// Example usage in code: set up a ModeData entry and apply it to the prefab entity.
var mode = /* obtain PostFacilityMode instance from your prefab or inspector */;
mode.m_ModeDatas = new []
{
new PostFacilityMode.ModeData
{
m_Prefab = somePrefabReference,
m_MailStorageCapacityMultifier = 1.5f, // increase facility storage by 50%
m_MailBoxCapacityMultifier = 1.2f, // increase mailbox capacity by 20%
m_SortingRateMultifier = 0.9f // slightly reduce sorting rate
}
};
// Later, when the mode system calls ApplyModeData (or you invoke it directly):
mode.ApplyModeData(entityManager, prefabSystem);
// To restore defaults from the original prefab component values:
mode.RestoreDefaultData(entityManager, prefabSystem);
Additional notes and tips: - The class expects the referenced prefab to contain a PostFacility component; otherwise it logs and skips that entry. - PrefabSystem.GetEntity(component.prefab) is used to locate the ECS entity for the prefab; ensure the PrefabSystem is initialized and contains the entity mapping. - Because component values are cast to int after multiplication, consider using rounded multipliers or handling rounding externally if precise results are required. - Types referenced by this class (PostFacility, PostFacilityData, MailBoxData, PrefabBase, PrefabSystem, ComponentBase.baseLog) come from the game's codebase / modding API; ensure your mod references the same assemblies.