namespace UIWidgets
{
using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
///
/// Proxy for InputField.
///
public class InputFieldProxy : IInputFieldProxy
{
///
/// The InputField.
///
readonly InputField inputField;
///
/// Initializes a new instance of the class.
///
/// Input.
public InputFieldProxy(InputField input)
{
inputField = input;
}
#region IInputFieldProxy implementation
///
/// The current value of the input field.
///
/// The text.
public string text
{
get
{
return inputField.text;
}
set
{
inputField.text = value;
}
}
///
/// The Unity Event to call when edit.
///
/// The OnValueChange.
public UnityEvent onValueChanged
{
get
{
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
return inputField.onValueChanged;
#else
return inputField.onValueChange;
#endif
}
}
///
/// The Unity Event to call when editing has ended.
///
/// The OnEndEdit.
public UnityEvent onEndEdit
{
get
{
return inputField.onEndEdit;
}
}
///
/// Current InputField caret position (also selection tail).
///
/// The caret position.
public int caretPosition
{
get
{
#if UNITY_5_1 || UNITY_5_2 || UNITY_5_3 || UNITY_5_3_OR_NEWER
return inputField.caretPosition;
#else
return inputField.text.Length;
#endif
}
set
{
#if UNITY_5_1 || UNITY_5_2 || UNITY_5_3 || UNITY_5_3_OR_NEWER
inputField.caretPosition = value;
#else
// inputField.ActivateInputField();
#endif
}
}
///
/// Is the InputField eligible for interaction (excludes canvas groups).
///
/// true
/// false
public bool interactable
{
get
{
return inputField.interactable;
}
set
{
inputField.interactable = value;
}
}
///
/// Determines whether InputField instance is null.
///
/// true
/// false
public bool IsNull()
{
return inputField == null;
}
///
/// Gets the gameobject.
///
/// The gameobject.
public GameObject gameObject
{
get
{
return (inputField != null) ? inputField.gameObject : null;
}
}
///
/// Text component.
///
public Graphic textComponent
{
get
{
return inputField.textComponent;
}
set
{
inputField.textComponent = value as Text;
}
}
///
/// Placeholder.
///
public Graphic placeholder
{
get
{
return inputField.placeholder;
}
set
{
inputField.placeholder = value;
}
}
///
/// If the proxy was canceled and will revert back to the original text.
///
public bool wasCanceled
{
get
{
return inputField.wasCanceled;
}
}
///
/// Determines whether this lineType is LineType.MultiLineNewline.
///
/// true
/// false
public bool IsMultiLineNewline()
{
return inputField.lineType == InputField.LineType.MultiLineNewline;
}
///
/// Function to activate the InputField to begin processing Events.
///
public void ActivateInputField()
{
inputField.ActivateInputField();
}
#if UNITY_4_6 || UNITY_4_7 || UNITY_5_0
///
/// Move caret to end.
///
public void MoveToEnd()
{
inputField.MoveTextStart(false);
inputField.MoveTextEnd(false);
}
#endif
///
/// Set focus to InputField.
///
public void Focus()
{
ActivateInputField();
inputField.Select();
}
///
/// Set focus to InputField.
///
public void Select()
{
ActivateInputField();
inputField.Select();
}
#endregion
}
}