Game.Prefabs.PolicySliderPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: PolicyPrefab
Summary:
Prefab component used to define a policy slider. When this prefab is initialized it supplies a PolicySliderData component to the Entity containing slider configuration: allowed range, default value, step increment and unit type. The prefab is annotated with a ComponentMenu attribute so it can be selected/created from the editor menus.
Fields
-
public Bounds1 m_SliderRange = new Bounds1(0f, 1f)
Defines the inclusive numeric range for the slider. Bounds1 is from Colossal.Mathematics and holds the minimum and maximum allowed values (default 0.0 — 1.0). -
public float m_SliderDefault = 0.5f
Default slider value applied when the PolicySliderData component is initialized. -
public float m_SliderStep = 0.1f
Increment/step size used by the slider. Consumers should use this to quantize slider values (e.g., 0.1 steps). -
public PolicySliderUnit m_Unit = PolicySliderUnit.integer
Unit type for the slider values. This enum controls how values are interpreted (for example integer vs. fractional). The prefab stores this in the PolicySliderData as an int.
Properties
- None declared on this class. (All configuration is exposed via public fields and applied to PolicySliderData.)
Constructors
public PolicySliderPrefab()
No explicit constructor is defined in the source; the C# compiler provides the default parameterless constructor. Initialization of component state is performed in the overridden Initialize method rather than a constructor.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Calls base.GetPrefabComponents(components) and then adds ComponentType.ReadWrite() to the provided set. This ensures that entities created from this prefab will include a writable PolicySliderData component.
Parameters:
- components: HashSet
public override void Initialize(EntityManager entityManager, Entity entity)
Calls base.Initialize(entityManager, entity) and then creates/populates a PolicySliderData struct with this prefab's configuration, assigning its fields:- m_Range <- m_SliderRange
- m_Default <- m_SliderDefault
- m_Step <- m_SliderStep
- m_Unit <- (int)m_Unit
Finally the populated PolicySliderData is written to the entity using entityManager.SetComponentData(entity, componentData).
Notes: - The method depends on the PolicySliderData struct existing with fields m_Range (Bounds1), m_Default (float), m_Step (float) and m_Unit (int). - Casting the enum to int stores the unit representation in a packed/serializable form for the ECS component.
Usage Example
// The prefab itself sets PolicySliderData on initialization. You can override or modify it
// after base initialization to tweak values at runtime:
[Preserve]
protected override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
// Example: adjust the default slider value before the entity is used
var data = entityManager.GetComponentData<PolicySliderData>(entity);
data.m_Default = 0.8f;
entityManager.SetComponentData(entity, data);
}
{{ Additional info: - Attribute: [ComponentMenu("Policies/", new Type[] { })] places this prefab under the "Policies" category in editor menus. - Typical workflow: prefabs like this are created/edited in the game's prefab system; when an entity is instantiated from the prefab the PolicySliderData component is guaranteed to be present and populated. - Be mindful of the m_SliderStep and m_Unit when reading or setting values elsewhere — UI or systems should quantize values according to m_SliderStep and interpret them according to m_Unit (integer vs. continuous). - Types referenced: Bounds1 (Colossal.Mathematics), PolicySliderData (ECS component struct), PolicySliderUnit (enum), EntityManager/Entity/ComponentType (Unity.Entities). }}