I'm attempting to create a text-input panel for my game, and I implemented one solution with UILabel. I'm still learning NGUI, but the issue I'm running into is that backspace is only recognized one time after each press of return. My code is included below. Any help?
thanks,
fb
----
using System;
using System.Collections.Generic;
using UnityEngine;
public class DialogController : MonoBehaviour
{
public int MaxLines;
public int MaxLength;
private List<String> textFrame;
public DialogController()
{
}
// Use this for initialization
void Start()
{
if (textFrame == null)
{
textFrame = new List<string>();
for (int index = 0; index < MaxLines; ++index)
{
textFrame.Add(String.Empty);
}
}
}
// Update is called once per frame
private void Update()
{
String entered = Input.inputString;
int last = (textFrame.Count - 1);
textFrame[last] += entered;
if (textFrame[last].Length > MaxLength)
{
textFrame[last] = textFrame[last].Substring(0, MaxLength);
}
if (Input.GetKeyDown(KeyCode.Return))
{
textFrame.RemoveAt(0);
textFrame.Add(entered);
}
//TODO: only works for one backspace per line
if (Input.GetKeyDown(KeyCode.Backspace))
{
int currentLength = textFrame[last].Length;
textFrame[last] = textFrame[last].Substring(0, (currentLength - 1));
}
PopulateContents();
}
public void PopulateContents()
{
String content = String.Empty;
foreach (String line in textFrame)
{
content += (line + '\n');
}
GetComponent<UILabel>().text = content;
}
}