ChatInput.cs 943 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(UIInput))]
  4. [AddComponentMenu("NGUI/Examples/Chat Input")]
  5. public class ChatInput : MonoBehaviour
  6. {
  7. private void Start()
  8. {
  9. this.mInput = base.GetComponent<UIInput>();
  10. this.mInput.label.maxLineCount = 1;
  11. if (this.fillWithDummyData && this.textList != null)
  12. {
  13. for (int i = 0; i < 30; i++)
  14. {
  15. this.textList.Add(string.Concat(new object[]
  16. {
  17. (i % 2 != 0) ? "[AAAAAA]" : "[FFFFFF]",
  18. "This is an example paragraph for the text list, testing line ",
  19. i,
  20. "[-]"
  21. }));
  22. }
  23. }
  24. }
  25. public void OnSubmit()
  26. {
  27. if (this.textList != null)
  28. {
  29. string text = NGUIText.StripSymbols(this.mInput.value);
  30. if (!string.IsNullOrEmpty(text))
  31. {
  32. this.textList.Add(text);
  33. this.mInput.value = string.Empty;
  34. this.mInput.isSelected = false;
  35. }
  36. }
  37. }
  38. public UITextList textList;
  39. public bool fillWithDummyData;
  40. private UIInput mInput;
  41. }