namespace UIWidgets { using UIWidgets.Styles; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; /// /// InputField adapter to work with both Unity text and TMPro text. /// public class InputFieldExtendedAdapter : MonoBehaviour, IInputFieldExtended { IInputFieldExtended proxy; /// /// Proxy. /// protected IInputFieldExtended Proxy { get { if (proxy == null) { proxy = GetProxy(); } return proxy; } } /// /// Proxy gameobject. /// public GameObject GameObject { get { return Proxy.gameObject; } } /// /// Proxy value. /// public string Value { get { return Proxy.text; } set { Proxy.text = (value == null) ? string.Empty : value; } } /// /// Proxy value. /// Alias for Value. /// public string text { get { return Proxy.text; } set { Proxy.text = value; } } /// /// The Unity Event to call when edit. /// /// The OnValueChange. public UnityEvent onValueChanged { get { return Proxy.onValueChanged; } } /// /// The Unity Event to call when editing has ended. /// /// The OnEndEdit. public UnityEvent onEndEdit { get { return Proxy.onEndEdit; } } /// /// Current InputField caret position (also selection tail). /// /// The caret position. public int caretPosition { get { return Proxy.caretPosition; } set { Proxy.caretPosition = value; } } /// /// Is the InputField eligible for interaction (excludes canvas groups). /// /// true if interactable; otherwise, false. public bool interactable { get { return Proxy.interactable; } set { Proxy.interactable = value; } } /// /// Text component. /// public Graphic textComponent { get { return Proxy.textComponent; } set { Proxy.textComponent = value; } } /// /// Placeholder. /// public Graphic placeholder { get { return Proxy.placeholder; } set { Proxy.placeholder = value; } } /// /// If the proxy was canceled and will revert back to the original text. /// public bool wasCanceled { get { return Proxy.wasCanceled; } } /// /// Get text proxy. /// /// Proxy instance. protected virtual IInputFieldExtended GetProxy() { var input = GetComponent(); if (input != null) { return input; } #if UIWIDGETS_TMPRO_SUPPORT && (UNITY_5_2 || UNITY_5_3 || UNITY_5_3_OR_NEWER) var tmpro = GetComponent(); if (tmpro != null) { return tmpro; } #endif Debug.LogWarning("Not found any InputFieldExtended component.", this); return new InputFieldExtendedNull(); } /// /// Determines whether InputField instance is null. /// /// true if InputField instance is null; otherwise, false. public bool IsNull() { return Proxy.IsNull(); } /// /// Determines whether this lineType is LineType.MultiLineNewline. /// /// true if lineType is LineType.MultiLineNewline; otherwise, false. public bool IsMultiLineNewline() { return Proxy.IsMultiLineNewline(); } /// /// Function to activate the InputField to begin processing Events. /// public void ActivateInputField() { Proxy.ActivateInputField(); } #if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 /// /// Move caret to end. /// public void MoveToEnd() { Proxy.MoveToEnd(); } #endif /// /// Set focus to InputField. /// public void Focus() { Proxy.Focus(); } /// /// Set focus to InputField. /// public void Select() { Proxy.Select(); } /// /// Function to validate input. /// public InputField.OnValidateInput Validation { get { return Proxy.Validation; } set { Proxy.Validation = value; } } /// /// Function to process changed value. /// public UnityAction ValueChanged { get { return Proxy.ValueChanged; } set { Proxy.ValueChanged = value; } } /// /// The Unity Event to call when edit. /// /// The OnValueChange. UnityEvent IInputFieldProxy.onValueChanged { get { return Proxy.onValueChanged; } } /// /// Function to process end edit. /// public UnityAction ValueEndEdit { get { return Proxy.ValueEndEdit; } set { Proxy.ValueEndEdit = value; } } /// /// The Unity Event to call when editing has ended. /// /// The OnEndEdit. UnityEvent IInputFieldProxy.onEndEdit { get { return Proxy.onEndEdit; } } /// /// Start selection position. /// public int SelectionStart { get { return Proxy.SelectionStart; } } /// /// End selection position. /// public int SelectionEnd { get { return Proxy.SelectionEnd; } } /// public virtual void SetStyle(StyleSpinner styleSpinner, Style style) { Proxy.SetStyle(styleSpinner, style); } /// public virtual void GetStyle(StyleSpinner styleSpinner, Style style) { Proxy.GetStyle(styleSpinner, style); } #if UNITY_EDITOR /// /// Validate this instance. /// protected virtual void OnValidate() { GetProxy(); } #endif } }