Game.Prefabs.AttractivenessParametersPrefab
Assembly:
Assembly-CSharp (typical for Cities: Skylines 2 mods; replace with your mod/assembly name if different)
Namespace:
Game.Prefabs
Type:
class
Base:
PrefabBase
Summary:
Prefab that exposes a set of parameters controlling how natural features and weather/temperature affect attractiveness (tourism/visitor desirability) in the game. Values are exposed as inspector fields (with Tooltips) and on initialization the prefab writes these values into an ECS component of type AttractivenessParameterData on the created entity. This prefab is used to configure global parameters that systems can read from the AttractivenessParameterData component.
Fields
-
public float m_ForestEffect
Default: 10f
Effect magnitude applied when near forests. Used to increase attractiveness based on proximity to forest tiles. -
public float m_ForestDistance
Default: 250f
Maximum distance (in meters) over which the forest effect is applied. -
public float m_ShoreEffect
Default: 20f
Effect magnitude applied when near shorelines (water). Increases attractiveness near shore. -
public float m_ShoreDistance
Default: 500f
Maximum distance (in meters) for the shore effect. -
public float3 m_HeightBonus
Default: float3(50f, 0.02f, 10f)
Tooltip: "zero level in m, effect % per m, max effect %"
Triplet likely encodes: base height reference (meters), percent effect per meter, and max percent effect. Used to modify attractiveness based on elevation. -
public float2 m_AttractiveTemperature
Default: float2(18f, 26f)
Tooltip: "Temperature that attract more tourists, between x and y, reach max effect when it's the middle of the temperature range"
Temperature range considered attractive (in degrees). Being inside this range increases attractiveness, with maximum at the midpoint. -
public float2 m_ExtremeTemperature
Default: float2(-10f, 30f)
Tooltip: "Extreme temperature that reduce the tourism, below x or above y, reach max effect when there are 10 degree difference"
Temperature ranges considered extreme; being outside these bounds reduces attractiveness, with stronger penalties the farther from the range (up to some cap). -
public float2 m_RainEffectRange
Default: float2(0.3f, 1f)
Tooltip: "Rain that affect tourism, precipitation x: start of punishment, y:max punishment to m_SnowRainExtremeAffect.y"
Defines precipitation thresholds for rain to start affecting tourism and the level at which the maximum rain punishment applies. -
public float2 m_SnowEffectRange
Default: float2(0.3f, 1f)
Tooltip: "Snow that affect tourism, precipitation x: start of positive effect, y:max effect to m_SnowRainExtremeAffect.x"
Defines precipitation thresholds for snow to start producing a (positive) effect on tourism and the level at which the maximum snow bonus applies. -
public float2 m_TemperatureAffect
Default: float2(0.2f, -0.3f)
Tooltip: "x:the attractiveness added to current when temperature inside of AttractiveTemperature, y:the attractiveness reduced from current when temperature inside of ExtremeTemperature"
Amounts to add/subtract from attractiveness when temperature is in attractive or extreme ranges. -
public float3 m_SnowRainExtremeAffect
Default: float3(0.3f, -0.1f, -0.3f)
Tooltip: "x:snowing weather affect, y:raining weather affect, z:extreme weather like storm,hail"
Per-weather multipliers/adjustments for attractiveness: snow (positive), rain (negative), and extreme weather (strong negative).
Properties
- None (this prefab class exposes public fields that are used to populate an ECS component; it does not define C# properties)
Constructors
public AttractivenessParametersPrefab()
Default parameterless constructor inherited from MonoBehaviour / PrefabBase. Instances are normally created/managed by the prefab system and initialized by the engine/editor.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds component(s) that this prefab will provide to the entity. Implementation details:- Calls base.GetPrefabComponents(components).
-
Adds ComponentType.ReadWrite
() to the provided set, indicating that entities created from this prefab should include the AttractivenessParameterData component (read/write). -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Called when building the archetype for entities of this prefab. This implementation calls the base method and does not add additional archetype components (method left intentionally empty beyond base call), meaning component types are handled via GetPrefabComponents in this class. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Writes the prefab field values into the entity's AttractivenessParameterData component. Implementation details: - Calls base.LateInitialize(entityManager, entity).
- Calls entityManager.SetComponentData(entity, new AttractivenessParameterData { ... }) and maps all m_* fields from the prefab into the AttractivenessParameterData struct fields:
- m_ForestDistance, m_ForestEffect, m_ShoreDistance, m_ShoreEffect, m_HeightBonus, m_AttractiveTemperature, m_ExtremeTemperature, m_TemperatureAffect, m_RainEffectRange, m_SnowEffectRange, m_SnowRainExtremeAffect.
- Note: The target entity must have an AttractivenessParameterData component (added earlier via GetPrefabComponents) for SetComponentData to succeed.
Usage Example
// The prefab exposes fields in the inspector. At runtime the prefab's LateInitialize
// populates the ECS component AttractivenessParameterData on the entity created for this prefab.
// Example: reading the data from an entity later in a system:
// Assume 'entityManager' and 'entity' refer to the entity created from this prefab:
var data = entityManager.GetComponentData<AttractivenessParameterData>(entity);
float forestEffect = data.m_ForestEffect;
float2 attractiveTemp = data.m_AttractiveTemperature;
// Example of the LateInitialize behavior (already implemented by the prefab):
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
entityManager.SetComponentData(entity, new AttractivenessParameterData
{
m_ForestDistance = m_ForestDistance,
m_ForestEffect = m_ForestEffect,
m_ShoreDistance = m_ShoreDistance,
m_ShoreEffect = m_ShoreEffect,
m_HeightBonus = m_HeightBonus,
m_AttractiveTemperature = m_AttractiveTemperature,
m_ExtremeTemperature = m_ExtremeTemperature,
m_TemperatureAffect = m_TemperatureAffect,
m_RainEffectRange = m_RainEffectRange,
m_SnowEffectRange = m_SnowEffectRange,
m_SnowRainExtremeAffect = m_SnowRainExtremeAffect
});
}
Additional notes: - The public m_* fields are decorated with Tooltip attributes to improve editor usability—tweak values in the prefab inspector to tune tourism/attractiveness behavior. - Ensure the AttractivenessParameterData struct exists in the mod/game code and has all corresponding fields with matching types (float, float2, float3) before using this prefab. - Because the prefab writes to an ECS component at initialization, this is the canonical place to centralize global attractiveness tuning for systems that process tourism/attraction.