Game.UI.Widgets.NumberStepAttribute
Assembly:
Assembly-CSharp (game code)
{{ A lightweight attribute class defined in the game's main assembly. If you use a different assembly layout for mods, the attribute may be present in the mod or game assembly. }}
Namespace:
Game.UI.Widgets
Type:
class
Base:
UnityEngine.PropertyAttribute
{{ Inherits UnityEngine.PropertyAttribute so it can be used with Unity's inspector and with custom property drawers/editors. }}
Summary:
{{ An attribute to specify a numeric step (increment) for a numeric field or property. Intended to be consumed by UI code or custom property drawers so numeric values can be stepped by a fixed amount (for example, when using step buttons, spinboxes, or snapping slider increments). The attribute targets fields and properties. }}
Fields
- (none)
{{ This class does not declare any explicit backing fields. The auto-implemented property Step will have a compiler-generated backing field (k__BackingField) but it's private and not used directly in source. }}
Properties
public float Step { get; set; }
{{ The step/increment value to use for the annotated numeric field or property. Consumers (custom editors or UI widgets) should read this value and apply it when performing step operations or snapping values. There is no validation in the attribute itself (e.g., for non-positive values), so consuming code may wish to enforce constraints (such as requiring Step > 0). }}
Constructors
public NumberStepAttribute(float step)
{{ Initializes the attribute with the specified step value. Usage typically passes a literal like 0.1f, 1f, etc. The constructor assigns the provided value to the Step property. }}
Methods
- (none)
{{ This attribute class contains no methods beyond the constructor and the auto-generated property accessors. Any behavior (snapping/stepping) must be implemented by the UI/editor code that reads this attribute. }}
Usage Example
using Game.UI.Widgets;
using UnityEngine;
public class ExampleComponent : MonoBehaviour
{
// In a property drawer or custom UI, this field would be stepped by 0.5 when step operations are requested
[NumberStep(0.5f)]
public float buildingHeight = 10f;
// Attributes can also be applied to properties
[NumberStep(1f)]
public int roadWidth { get; set; } = 6;
}
{{ Tips: - This attribute only provides metadata. To make stepping take effect in the inspector or in-game UI, implement a custom PropertyDrawer (editor) or read the attribute from reflection in runtime UI code and apply the Step value. - Consider validating the Step value in consumer code (e.g., ensure Step > 0) to avoid unexpected behavior. - Because it derives from PropertyAttribute, it is best used with Unity editor code, but it can equally be read at runtime for custom UI widgets. }}