Game.Prefabs.PolicySliderData
Assembly:
(assembly not specified — typically part of the game's runtime assembly)
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter
Summary:
PolicySliderData is an ECS component struct used to describe a single-slider policy setting for the game (Cities: Skylines 2). It contains the slider's numeric range, a default value, the step/increment, and a unit identifier. As an IComponentData it can be attached to entities and queried by ECS systems; IQueryTypeParameter allows it to be used in certain query/type parameter contexts.
Fields
-
public Colossal.Mathematics.Bounds1 m_Range
Represents the allowed numeric range for the slider (a 1-dimensional bounds). Used to clamp and validate slider values (min and max). -
public float m_Default
The default value for the slider. Should lie within m_Range. -
public float m_Step
The increment/step for the slider. Controls how the value changes (e.g., 0.1, 1.0). -
public int m_Unit
Integer identifier for the unit or display type of the slider (for example, could map to an internal enum for percent, currency, population, etc.). Interpretation depends on the UI/engine code that consumes this component.
Properties
- This struct defines no properties.
Constructors
public PolicySliderData()
Structs have an implicit parameterless constructor; use object initializer or default(...) to create an instance. Example: new PolicySliderData { m_Range = ..., m_Default = ..., m_Step = ..., m_Unit = ... }.
Methods
- This struct defines no methods.
Usage Example
// Create and add the component to an entity (EntityManager usage)
var em = Unity.Entities.World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = em.CreateEntity(typeof(Game.Prefabs.PolicySliderData));
// Example: construct Bounds1 with min/max - adjust to actual Bounds1 API if different
var slider = new Game.Prefabs.PolicySliderData
{
m_Range = new Colossal.Mathematics.Bounds1(0f, 100f), // allowed range 0..100
m_Default = 50f, // default midpoint
m_Step = 1f, // increments of 1
m_Unit = 0 // interpret via consumer (e.g., 0 = percent)
};
em.SetComponentData(entity, slider);
// Reading/updating inside a SystemBase
public partial class PolicySystem : Unity.Entities.SystemBase
{
protected override void OnUpdate()
{
Entities.ForEach((ref Game.Prefabs.PolicySliderData slider) =>
{
// ensure default is clamped to range
var min = slider.m_Range.min; // adjust to actual Bounds1 members if different
var max = slider.m_Range.max;
slider.m_Default = System.MathF.Clamp(slider.m_Default, min, max);
// example: snap to step
if (slider.m_Step > 0f)
{
slider.m_Default = (float)System.Math.Round(slider.m_Default / slider.m_Step) * slider.m_Step;
}
}).ScheduleParallel();
}
}
Notes: - Adjust Bounds1 construction and member access to match the actual Colossal.Mathematics.Bounds1 API in the game's SDK if names differ (min/max fields or properties). - m_Unit is an integer index — consult the consuming UI/engine code for the mapping of unit IDs to display/formatting behavior.