/// Credit David Gileadi /// Sourced from - https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/pull-requests/11 using System; using UnityEngine.Events; using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { // Stepper control [AddComponentMenu("UI/Extensions/Stepper")] [RequireComponent(typeof(RectTransform))] public class Stepper : UIBehaviour { public Button[] sides { get { if (_sides == null || _sides.Length == 0) { _sides = GetSides(); } return _sides; } } private Button[] _sides; [SerializeField] private int _value = 0; public int value { get { return _value; } set { _value = value; } } [SerializeField] private int _minimum = 0; public int minimum { get { return _minimum; } set { _minimum = value; } } [SerializeField] private int _maximum = 100; public int maximum { get { return _maximum; } set { _maximum = value; } } [SerializeField] private int _step = 1; public int step { get { return _step; } set { _step = value; } } [SerializeField] private bool _wrap = false; public bool wrap { get { return _wrap; } set { _wrap = value; } } [SerializeField] private Graphic _separator; public Graphic separator { get { return _separator; } set { _separator = value; _separatorWidth = 0; LayoutSides(sides); } } private float _separatorWidth = 0; private float separatorWidth { get { if (_separatorWidth == 0 && separator) { _separatorWidth = separator.rectTransform.rect.width; var image = separator.GetComponent(); if (image) _separatorWidth /= image.pixelsPerUnit; } return _separatorWidth; } } [Serializable] public class StepperValueChangedEvent : UnityEvent { } // Event delegates triggered on click. [SerializeField] private StepperValueChangedEvent _onValueChanged = new StepperValueChangedEvent(); public StepperValueChangedEvent onValueChanged { get { return _onValueChanged; } set { _onValueChanged = value; } } protected Stepper() { } #if UNITY_EDITOR protected override void OnValidate() { base.OnValidate(); if (separator) LayoutSides(); if (!wrap) { DisableAtExtremes(sides); } } #endif private Button[] GetSides() { var buttons = GetComponentsInChildren