Skip to content

Game.Prefabs.Modes.MailBoxMode

Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs.Modes

Type: class

Base: LocalModePrefab

Summary:
MailBoxMode is a prefab mode component that applies mode-specific adjustments to MailBox prefabs. It stores an array of ModeData entries (each referencing an ObjectPrefab) and, when applied, modifies the runtime ECS component data for the referenced prefab entities: it scales the mailbox capacity (MailBoxData.m_MailCapacity) and sets the comfort factor on transport stops (TransportStopData.m_ComfortFactor) when present. It also supports recording changes (to ensure the appropriate components are referenced) and restoring the original values from the prefab defaults.


Fields

  • public ModeData[] m_ModeDatas
    Holds the list of ModeData entries for this mode. Each ModeData points to an ObjectPrefab containing a MailBox component and contains the multipliers/values to apply at runtime.

Inner class ModeData: - public ObjectPrefab m_Prefab
Reference to the prefab that contains the MailBox component to modify.

  • public float m_MailCapacityMultifier
    Multiplier applied to the prefab's MailBoxData.m_MailCapacity when ApplyModeData is invoked.

  • public float m_ComfortFactor
    Value to set on TransportStopData.m_ComfortFactor (if the entity has a TransportStopData component).

Properties

  • None (no public properties are declared on MailBoxMode).

Constructors

  • public MailBoxMode()
    Default implicit constructor. The class relies on serialized fields (m_ModeDatas) populated via prefab/inspector or code.

Methods

  • public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
    Iterates over m_ModeDatas and validates the referenced prefab targets. For each ModeData it:
  • Gets the MailBox component from the referenced ObjectPrefab.
  • Logs a critical error if the MailBox component is not found (via ComponentBase.baseLog.Critical).
  • Obtains the ECS Entity for the prefab (prefabSystem.GetEntity(component.prefab)).
  • Reads MailBoxData from the entity (entityManager.GetComponentData).
  • If the entity has TransportStopData, reads that as well. Purpose: to ensure the relevant ECS components exist and to "touch" them so changes are recorded in any prefab mode workflow.

  • public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
    Applies the ModeData values to the runtime ECS components:

  • For each ModeData, finds the MailBox component on the referenced prefab; logs if missing.
  • Resolves the entity with prefabSystem.GetEntity(component.prefab).
  • Loads MailBoxData, multiplies its m_MailCapacity by m_MailCapacityMultifier and writes it back with SetComponentData.
  • If the entity has TransportStopData, it sets TransportStopData.m_ComfortFactor to the ModeData.m_ComfortFactor and writes it back. This is the main method to enact mode-specific mailbox behavior at runtime.

  • public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
    Restores component values to the prefab's original defaults:

  • For each ModeData, finds the MailBox component on the referenced prefab; logs if missing.
  • Resolves the entity and sets MailBoxData.m_MailCapacity back to the value from the MailBox MonoBehaviour (component.m_MailCapacity).
  • If the entity has TransportStopData, sets m_ComfortFactor back to component.m_ComfortFactor. Used to revert mode changes (for example when switching off the mode).

Usage Example

// Example: programmatically create/configure a MailBoxMode (normally configured in prefab/inspector)
var mode = new MailBoxMode();
mode.m_ModeDatas = new MailBoxMode.ModeData[1];
mode.m_ModeDatas[0] = new MailBoxMode.ModeData
{
    m_Prefab = someObjectPrefab,          // an ObjectPrefab that has a MailBox component
    m_MailCapacityMultifier = 1.5f,       // increase mailbox capacity by 50%
    m_ComfortFactor = 0.9f                // set transport stop comfort factor
};

// Later, when the PrefabSystem and EntityManager are available (game initialization/mod code):
mode.ApplyModeData(entityManager, prefabSystem);

// To restore original values:
mode.RestoreDefaultData(entityManager, prefabSystem);