You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
951 B

  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using TMPro;
  5. public class ChatController : MonoBehaviour {
  6. public TMP_InputField TMP_ChatInput;
  7. public TMP_Text TMP_ChatOutput;
  8. public Scrollbar ChatScrollbar;
  9. void OnEnable()
  10. {
  11. TMP_ChatInput.onSubmit.AddListener(AddToChatOutput);
  12. }
  13. void OnDisable()
  14. {
  15. TMP_ChatInput.onSubmit.RemoveListener(AddToChatOutput);
  16. }
  17. void AddToChatOutput(string newText)
  18. {
  19. // Clear Input Field
  20. TMP_ChatInput.text = string.Empty;
  21. var timeNow = System.DateTime.Now;
  22. TMP_ChatOutput.text += "[<#FFFF80>" + timeNow.Hour.ToString("d2") + ":" + timeNow.Minute.ToString("d2") + ":" + timeNow.Second.ToString("d2") + "</color>] " + newText + "\n";
  23. TMP_ChatInput.ActivateInputField();
  24. // Set the scrollbar to the bottom when next text is submitted.
  25. ChatScrollbar.value = 0;
  26. }
  27. }