Skip to content

Game.Prefabs.Modes.GarbageFacilityMode

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

Type: class

Base: LocalModePrefab

Summary:
GarbageFacilityMode is a mode component (serializable and usable on prefabs) that allows per-prefab configuration of garbage facility behavior by applying multipliers to existing GarbageFacilityData values. It defines one or more ModeData entries that reference target prefabs and contain multipliers for garbage capacity and processing speed. When the mode is applied, the component reads the target prefab's entity and adjusts its GarbageFacilityData fields (m_GarbageCapacity and m_ProcessingSpeed). It also provides methods to record, apply, and restore default data for the referenced prefab entities. The component logs a critical message if a referenced prefab does not have the expected GarbageFacility component.


Fields

  • public ModeData[] m_ModeDatas
    Array of ModeData entries to apply for this mode. Each element references a prefab (PrefabBase) and two multipliers used to modify the prefab's GarbageFacilityData. This array is serialized and typically populated in the editor.

Inner class ModeData (serializable):

  • public PrefabBase m_Prefab
    Reference to the prefab whose GarbageFacilityData will be modified.

  • public float m_GarbageCapacityMultiplier
    Multiplier applied to the prefab's m_GarbageCapacity when ApplyModeData is called. The existing capacity is multiplied by this value and then cast to int.

  • public float m_ProcessingSpeedMultiplier
    Multiplier applied to the prefab's m_ProcessingSpeed when ApplyModeData is called. The existing processing speed is multiplied by this value and then cast to int.

Properties

  • (none)

Constructors

  • public GarbageFacilityMode()
    Default parameterless constructor (implicit if not defined). No special initialization is performed in the source; the component is configured via serialized fields in the editor.

Methods

  • public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
    Iterates over m_ModeDatas and for each referenced prefab:
  • Obtains the GarbageFacility component from the PrefabBase (via m_Prefab.GetComponent()).
  • If the component is missing, logs a critical error and skips that entry.
  • Otherwise fetches the Entity for the prefab (prefabSystem.GetEntity(component.prefab)) and calls entityManager.GetComponentData(entity). Purpose: ensures the entity/component exist and reads the current GarbageFacilityData. This can be used by the modding system to record baseline values before modifications. Note: this method reads the component data but does not modify it.

  • public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
    For each entry in m_ModeDatas:

  • Resolves the target GarbageFacility component and entity.
  • Reads current GarbageFacilityData from the entity.
  • Applies multipliers:
    • m_GarbageCapacity := (int)(m_GarbageCapacity * m_GarbageCapacityMultiplier)
    • m_ProcessingSpeed := (int)(m_ProcessingSpeed * m_ProcessingSpeedMultiplier)
  • Writes the modified GarbageFacilityData back to the entity via entityManager.SetComponentData. Notes:
  • Multiplication uses float arithmetic then casts to int (truncation toward zero).
  • If the referenced prefab/component is missing, a critical log is written and the entry is skipped.

  • public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
    For each entry in m_ModeDatas:

  • Resolves the GarbageFacility component and entity.
  • Restores the entity's GarbageFacilityData fields to the values stored on the GarbageFacility MonoBehaviour (component.m_GarbageCapacity and component.m_ProcessingSpeed).
  • Writes the restored data back to the entity. This method is intended to revert changes made by ApplyModeData back to the prefab's original defaults.

Additional behavior: - Error handling: when a ModeData entry references a Prefab that does not contain a GarbageFacility component, the code uses ComponentBase.baseLog.Critical to report "Target not found {this}" and continues processing other entries. - The class assumes the existence of the component types GarbageFacility and the ECS component struct GarbageFacilityData with fields m_GarbageCapacity and m_ProcessingSpeed.

Usage Example

// Example: applying a GarbageFacilityMode at runtime (pseudo-usage).
// Assume `mode` is a GarbageFacilityMode instance (configured in editor or created by code),
// entityManager and prefabSystem are available from the game's ECS context.

public void ApplyMode(GarbageFacilityMode mode, EntityManager entityManager, PrefabSystem prefabSystem)
{
    // Record baseline values (optional, depending on how the mod system uses it)
    mode.RecordChanges(entityManager, prefabSystem);

    // Apply multipliers to referenced prefabs/entities
    mode.ApplyModeData(entityManager, prefabSystem);

    // ... later, to revert:
    // mode.RestoreDefaultData(entityManager, prefabSystem);
}

Notes and tips for modders: - Multipliers are applied per entry in m_ModeDatas; if you want to change several prefabs include multiple ModeData entries. - Be aware of integer truncation when multipliers produce non-integer results — consider using multipliers that produce sensible integer outputs or adjust logic to round if needed. - Ensure the referenced PrefabBase actually contains a GarbageFacility MonoBehaviour; otherwise the entry will be skipped and a critical log will be emitted. - This component operates directly on ECS component data (GarbageFacilityData), so using it requires proper access to the game's EntityManager and PrefabSystem.