Game.Prefabs.Modes.AttractionMode
Assembly:
Assembly-CSharp (game)
Namespace:
Game.Prefabs.Modes
Type:
class
Base:
LocalModePrefab
Summary:
AttractionMode is a LocalModePrefab used to modify the runtime AttractionData for attraction building prefabs. It contains an array of ModeData entries (each pointing to a BuildingPrefab and a multiplier) and provides logic to record which components will be affected, apply a multiplier to the attraction value at runtime, and restore the original attraction values from the prefab. The class logs a critical error if a referenced BuildingPrefab does not contain the expected Attraction component.
Fields
-
public ModeData[] m_ModeDatas
Array of ModeData entries. Each entry pairs a BuildingPrefab with a float multiplier that the mode will use to alter that prefab's AttractionData at runtime. This field is serialized and editable in the prefab inspector. -
(inner)
public class ModeData
public BuildingPrefab m_Prefab
Reference to the building prefab that contains an Attraction component.public float m_AttractivenessMultifier
Multiplier applied to the prefab's attractiveness value when ApplyModeData is executed. Note the original spelling "Multifier" follows the source.
Properties
- (This class does not expose public C# properties beyond the serialized fields above.)
Constructors
public AttractionMode()
Default parameterless constructor (generated by the runtime). No special initialization is performed in source.
Methods
public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates over m_ModeDatas and, for each entry:- Retrieves the Attraction component from the referenced BuildingPrefab.
- If the component is missing, logs a critical error and skips the entry.
-
Otherwise gets the Entity for the prefab via prefabSystem.GetEntity(component.prefab) and calls entityManager.GetComponentData
(entity). Purpose: to touch/record the AttractionData component so the prefab/EC system knows this component will be changed by this mode (often used in systems that batch or track modified components). -
public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
For each ModeData entry: - Retrieves the Attraction component from the prefab; logs and continues if missing.
- Resolves the Entity for that prefab and reads its AttractionData component.
- Modifies componentData.m_Attractiveness using the entry's multiplier and writes the modified component back to the EntityManager. Note: the current source code uses the expression componentData.m_Attractiveness *= (int)((float)componentData.m_Attractiveness * modeData.m_AttractivenessMultifier); This looks incorrect/buggy: it multiplies the current attractiveness by an integer cast of (currentAttractiveness * multiplier), which produces a value much larger than intended and discards fractional precision. The likely correct implementations are either:
- componentData.m_Attractiveness = (int)(componentData.m_Attractiveness * modeData.m_AttractivenessMultifier); or
-
componentData.m_Attractiveness = (int)(componentData.m_Attractiveness * modeData.m_AttractivenessMultifier + 0.5f); depending on desired rounding. Review and fix if you expect multiplier semantics.
-
public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
For each ModeData entry: - Retrieves the Attraction component from the prefab; logs and continues if missing.
- Resolves the Entity and sets AttractionData.m_Attractiveness back to the prefab's original value stored on the Attraction component (component.m_Attractiveness). This restores the attraction values to their defaults as defined on the prefab.
Additional behavior: - The class uses ComponentBase.baseLog.Critical(...) to report missing targets — useful to diagnose misconfigured ModeData entries. - This class operates on the ECS component AttractionData, so it requires that the PrefabSystem can resolve the prefab Entity referenced by the Attraction component.
Usage Example
// Example: set up m_ModeDatas in code (or assign in prefab inspector)
public class ExampleModeSetup : MonoBehaviour
{
public AttractionMode modePrefab; // reference to the AttractionMode prefab instance
public BuildingPrefab exampleAttractionPrefab;
void Start()
{
// Create a single ModeData entry that increases attractiveness by 50%
modePrefab.m_ModeDatas = new AttractionMode.ModeData[1];
modePrefab.m_ModeDatas[0] = new AttractionMode.ModeData
{
m_Prefab = exampleAttractionPrefab,
m_AttractivenessMultifier = 1.5f
};
}
}
Notes and tips: - Verify the BuildingPrefab referenced actually contains an Attraction component (otherwise the entry will be skipped and a critical log emitted). - Double-check and correct the multiplier application in ApplyModeData if you need expected multiplier semantics (see the comment in Methods). - Because this class modifies ECS components, ensure you call these methods at a safe time during initialization or mode switching so other systems observe consistent data.