using UnityEngine;
using System.Collections.Generic;
namespace PixelCrushers.DialogueSystem.UnityGUI
{
///
/// A GUI control that implements GUI.TextField for text input.
///
[AddComponentMenu("")] // Deprecated
public class GUITextField : GUIVisibleControl
{
///
/// The maximum number of characters the user can enter, or 0 for unlimited.
///
public int maxLength = 0;
///
/// Gets the default GUI style to use for this type of control. It can be overridden on a per-control
/// basis using guiStyleName.
///
/// The default GUI style.
protected override GUIStyle DefaultGUIStyle
{
get { return GUI.skin.textField; }
}
private bool takeFocus = false;
///
/// Makes this control take focus.
///
public void TakeFocus()
{
takeFocus = true;
}
///
/// Draws the control, but not its children.
///
/// Relative mouse position within the window containing this control.
public override void DrawSelf(Vector2 relativeMousePosition)
{
SetGUIStyle();
if (takeFocus) GUI.SetNextControlName(FullName);
if (text == null) text = string.Empty;
if (maxLength == 0)
{
text = GUI.TextField(rect, text, GuiStyle);
}
else
{
text = GUI.TextField(rect, text, maxLength, GuiStyle);
}
if (takeFocus)
{
GUI.FocusControl(FullName);
takeFocus = false;
}
}
}
}