// // Auto-generated added to suppress names errors. namespace UIWidgets { using System; using System.Collections; using UIWidgets.Attributes; using UIWidgets.Styles; using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.Serialization; using UnityEngine.UI; /// /// Spinner validation. /// public enum SpinnerValidation { /// /// On key down. /// OnKeyDown = 0, /// /// On end input. /// OnEndInput = 1, } /// /// Spinner base class. /// /// Type of spinner value. [DataBindSupport] public abstract class SpinnerBase : UIWidgetsMonoBehaviour, IStylable, IUpgradeable, IValidateable where T : struct { #pragma warning disable 0649 [SerializeField] [HideInInspector] [Obsolete("Replaced with InputField.")] Text m_TextComponent; [SerializeField] [HideInInspector] [Obsolete("Replaced with InputField.")] Graphic m_Placeholder; [SerializeField] [HideInInspector] [Obsolete("Replaced with InputField.")] Graphic m_TargetGraphic; #pragma warning restore 0649 [FormerlySerializedAs("onSubmit")] [FormerlySerializedAs("m_OnSubmit")] [FormerlySerializedAs("m_EndEdit")] [SerializeField] [HideInInspector] #if UNITY_2021_1_OR_NEWER InputField.EndEditEvent m_OnEndEdit = new InputField.EndEditEvent(); #else InputField.SubmitEvent m_OnEndEdit = new InputField.SubmitEvent(); #endif [FormerlySerializedAs("onValueChange")] [FormerlySerializedAs("m_OnValueChange")] [SerializeField] [HideInInspector] private InputField.OnChangeEvent m_OnValueChanged = new InputField.OnChangeEvent(); /// /// InputField proxy. /// [Obsolete("Replaced with InputFieldAdapter.")] protected IInputFieldExtended InputField { get { return InputFieldAdapter; } } [SerializeField] InputFieldExtendedAdapter inputFieldAdapter; /// /// InputFieldAdapter. /// public InputFieldExtendedAdapter InputFieldAdapter { get { if (inputFieldAdapter == null) { InitInputField(); } return inputFieldAdapter; } } /// /// The min. /// [SerializeField] [FormerlySerializedAs("_min")] protected T ValueMin; /// /// The max. /// [SerializeField] [FormerlySerializedAs("_max")] protected T ValueMax; /// /// The step. /// [SerializeField] [FormerlySerializedAs("_step")] protected T ValueStep; /// /// The value. /// [SerializeField] [FormerlySerializedAs("_value")] protected T SpinnerValue; /// /// The validation type. /// [SerializeField] public SpinnerValidation Validation = SpinnerValidation.OnKeyDown; /// /// Allow changing value during hold. /// [SerializeField] public bool AllowHold = true; /// /// Delay of hold in seconds for permanent increase/decrease value. /// [SerializeField] public float HoldStartDelay = 0.5f; /// /// Delay of hold in seconds between increase/decrease value. /// [SerializeField] public float HoldChangeDelay = 0.1f; /// /// Gets or sets the minimum. /// /// The minimum. [DataBindField] public T Min { get { return ValueMin; } set { ValueMin = value; } } /// /// Gets or sets the maximum. /// /// The maximum. [DataBindField] public T Max { get { return ValueMax; } set { ValueMax = value; } } /// /// Gets or sets the step. /// /// The step. [DataBindField] public T Step { get { return ValueStep; } set { ValueStep = value; } } /// /// Gets or sets the value. /// /// The value. [DataBindField] public T Value { get { return SpinnerValue; } set { SetValue(value); } } /// /// The plus button. /// [SerializeField] [FormerlySerializedAs("_plusButton")] protected ButtonAdvanced plusButton; /// /// The minus button. /// [SerializeField] [FormerlySerializedAs("_minusButton")] protected ButtonAdvanced minusButton; /// /// Use unscaled time. /// [SerializeField] public bool UnscaledTime; /// /// Gets or sets the plus button. /// /// The plus button. public ButtonAdvanced PlusButton { get { return plusButton; } set { if (plusButton != null) { plusButton.onClick.RemoveListener(OnPlusClick); plusButton.onPointerDown.RemoveListener(OnPlusButtonDown); plusButton.onPointerUp.RemoveListener(OnPlusButtonUp); } plusButton = value; if (plusButton != null) { plusButton.onClick.AddListener(OnPlusClick); plusButton.onPointerDown.AddListener(OnPlusButtonDown); plusButton.onPointerUp.AddListener(OnPlusButtonUp); } } } /// /// Gets or sets the minus button. /// /// The minus button. public ButtonAdvanced MinusButton { get { return minusButton; } set { if (minusButton != null) { minusButton.onClick.RemoveListener(OnMinusClick); minusButton.onPointerDown.RemoveListener(OnMinusButtonDown); minusButton.onPointerUp.RemoveListener(OnMinusButtonUp); } minusButton = value; if (minusButton != null) { minusButton.onClick.AddListener(OnMinusClick); minusButton.onPointerDown.AddListener(OnMinusButtonDown); minusButton.onPointerUp.AddListener(OnMinusButtonUp); } } } /// /// onPlusClick event. /// public UnityEvent onPlusClick = new UnityEvent(); /// /// onMinusClick event. /// public UnityEvent onMinusClick = new UnityEvent(); /// /// Increase value on step. /// public abstract void Plus(); /// /// Decrease value on step. /// public abstract void Minus(); /// /// Sets the value. /// /// New value. /// Raise event. public abstract void SetValue(T newValue, bool raiseEvent); /// /// Sets the value. /// /// New value. public virtual void SetValue(T newValue) { SetValue(newValue, true); } /// /// Start this instance. /// protected virtual void Start() { Init(); } bool isInited; /// /// Init InputField. /// protected void InitInputField() { Upgrade(); } /// /// Check if target has any InputFieldExtended component. /// /// true if target has any InputFieldExtended component; otherwise false. protected virtual bool HasInputField(GameObject target) { var input = target.GetComponent(); if (input != null) { return true; } #if UIWIDGETS_TMPRO_SUPPORT && (UNITY_5_2 || UNITY_5_3 || UNITY_5_3_OR_NEWER) var tmpro = target.GetComponent(); if (tmpro != null) { return true; } #endif return false; } /// /// Init. /// public void Init() { if (isInited) { return; } isInited = true; InitInputField(); InputFieldAdapter.Validation = SpinnerValidate; InputFieldAdapter.ValueChanged = ValueChange; InputFieldAdapter.ValueEndEdit = ValueEndEdit; PlusButton = plusButton; MinusButton = minusButton; Value = SpinnerValue; SetTextValue(); } /// /// Set text value. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0102:Non-overridden virtual method call on value type", Justification = "Required.")] protected virtual void SetTextValue() { InputFieldAdapter.Value = SpinnerValue.ToString(); } /// /// Hold Plus coroutine. /// /// IEnumerator. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0401:Possible allocation of reference type enumerator", Justification = "Enumerator is reusable.")] protected virtual IEnumerator HoldPlus() { if (AllowHold) { yield return UtilitiesTime.Wait(HoldStartDelay, UnscaledTime); while (AllowHold) { Plus(); yield return UtilitiesTime.Wait(HoldChangeDelay, UnscaledTime); } } } /// /// Hold Minus coroutine. /// /// IEnumerator. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0401:Possible allocation of reference type enumerator", Justification = "Enumerator is reusable.")] protected virtual IEnumerator HoldMinus() { if (AllowHold) { yield return UtilitiesTime.Wait(HoldStartDelay, UnscaledTime); while (AllowHold) { Minus(); yield return UtilitiesTime.Wait(HoldChangeDelay, UnscaledTime); } } } /// /// Process the minus click event. /// public void OnMinusClick() { Minus(); onMinusClick.Invoke(); } /// /// Process the plus click event. /// public void OnPlusClick() { Plus(); onPlusClick.Invoke(); } IEnumerator coroutine; /// /// Process the plus button down event. /// /// Current event data. public void OnPlusButtonDown(PointerEventData eventData) { if (coroutine != null) { StopCoroutine(coroutine); } coroutine = HoldPlus(); StartCoroutine(coroutine); } /// /// Process the plus button up event. /// /// Current event data. public void OnPlusButtonUp(PointerEventData eventData) { StopCoroutine(coroutine); coroutine = null; } /// /// Process the minus button down event. /// /// Current event data. public void OnMinusButtonDown(PointerEventData eventData) { if (coroutine != null) { StopCoroutine(coroutine); } coroutine = HoldMinus(); StartCoroutine(coroutine); } /// /// Process the minus button up event. /// /// Current event data. public void OnMinusButtonUp(PointerEventData eventData) { StopCoroutine(coroutine); coroutine = null; } /// /// Process the destroy event. /// protected virtual void onDestroy() { PlusButton = null; MinusButton = null; } /// /// Called when value changed. /// /// Value. protected abstract void ValueChange(string value); /// /// Called when end edit. /// /// Value. protected abstract void ValueEndEdit(string value); char SpinnerValidate(string validateText, int charIndex, char addedChar) { if (Validation == SpinnerValidation.OnEndInput) { return ValidateShort(validateText, charIndex, addedChar); } else { return ValidateFull(validateText, charIndex, addedChar); } } /// /// Validate when key down for Validation=OnEndInput. /// /// The char. /// Validate text. /// Char index. /// Added char. protected abstract char ValidateShort(string validateText, int charIndex, char addedChar); /// /// Validates when key down for Validation=OnKeyDown. /// /// The char. /// Validate text. /// Char index. /// Added char. protected abstract char ValidateFull(string validateText, int charIndex, char addedChar); /// /// Clamps a value between a minimum and maximum value. /// /// The bounds. /// Value. protected abstract T InBounds(T value); #region IStylable implementation /// public virtual bool SetStyle(Style style) { SetStyle(style.Spinner, style); return true; } /// /// Set the specified style for specified spinner. /// /// Spinner style data. /// Style data. public virtual void SetStyle(StyleSpinner styleSpinner, Style style) { InputFieldAdapter.SetStyle(styleSpinner, style); styleSpinner.Background.ApplyTo(transform.parent); styleSpinner.InputBackground.ApplyTo(GetComponent()); if (minusButton != null) { styleSpinner.ButtonMinus.ApplyTo(minusButton.gameObject); } if (plusButton != null) { styleSpinner.ButtonPlus.ApplyTo(plusButton.gameObject); } } /// public virtual bool GetStyle(Style style) { GetStyle(style.Spinner, style); return true; } /// /// Set style options from widget properties. /// /// Spinner style data. /// Style data. public virtual void GetStyle(StyleSpinner styleSpinner, Style style) { InputFieldAdapter.GetStyle(styleSpinner, style); styleSpinner.Background.GetFrom(transform.parent); styleSpinner.InputBackground.GetFrom(GetComponent()); if (minusButton != null) { styleSpinner.ButtonMinus.GetFrom(minusButton.gameObject); } if (plusButton != null) { styleSpinner.ButtonPlus.GetFrom(plusButton.gameObject); } } #endregion /// /// Upgrade this instance. /// public virtual void Upgrade() { #pragma warning disable 0612, 0618 var target = (inputFieldAdapter != null) ? inputFieldAdapter.gameObject : gameObject; if (!HasInputField(target) && (m_TextComponent != null)) { var input = target.AddComponent(); input.textComponent = m_TextComponent; input.placeholder = m_Placeholder; input.targetGraphic = m_TargetGraphic; input.onEndEdit = m_OnEndEdit; #if UNITY_5_3 || UNITY_5_3_OR_NEWER input.onValueChanged = m_OnValueChanged; #else input.onValueChange = m_OnValueChanged; #endif } m_TextComponent = null; m_Placeholder = null; m_TargetGraphic = null; #pragma warning restore 0612, 0618 Utilities.GetOrAddComponent(this, ref inputFieldAdapter); } #if UNITY_EDITOR /// /// Validate instance. /// public virtual void Validate() { Compatibility.Upgrade(this); } #endif } }