1
NGUI 3 Support / Re: UILabel Max Lines Not working for UIInput
« on: March 23, 2015, 11:21:02 AM »
So I'm just going to assume this feature with NGUI is broken. I created a workaround. Set the Max Lines to 0, attach the script below to the object, and set the UIInput's OnChange event to trigger the OnTextChanged method. This does the trick.
- using UnityEngine;
- using System.Collections;
- public class LimitLines : MonoBehaviour
- {
- public int TotalLines = 2;
- private UILabel _label;
- private UIInput _input;
- void Start()
- {
- _label = this.GetComponent<UILabel>();
- _input = this.GetComponent<UIInput>();
- }
- public void OnTextChanged()
- {
- string[] lines = _input.value.Split('\n');
- string output = "";
- for (var i = 0; i < lines.Length && i < TotalLines; i++)
- {
- output += i > 0 ? '\n' + lines[i] : lines[i];
- }
- _label.text = output;
- _input.value = output;
- }
- }