summaryrefslogtreecommitdiff
path: root/Pathfinding Visualizer/Assets/TextMesh Pro/Examples & Extras/Scripts/ChatController.cs
diff options
context:
space:
mode:
authordereelatwit <54997325+dereelatwit@users.noreply.github.com>2023-08-03 14:05:08 -0400
committerdereelatwit <54997325+dereelatwit@users.noreply.github.com>2023-08-03 14:05:08 -0400
commitb8aa2e0935f309b112648f0352f35f5f33da946b (patch)
tree9121ae1a65e483dddba8367cbbdd4991abfb3e26 /Pathfinding Visualizer/Assets/TextMesh Pro/Examples & Extras/Scripts/ChatController.cs
parent374125ba34e0366afb062578906877cfdf229bb9 (diff)
started implementing UI
Diffstat (limited to 'Pathfinding Visualizer/Assets/TextMesh Pro/Examples & Extras/Scripts/ChatController.cs')
-rw-r--r--Pathfinding Visualizer/Assets/TextMesh Pro/Examples & Extras/Scripts/ChatController.cs51
1 files changed, 51 insertions, 0 deletions
diff --git a/Pathfinding Visualizer/Assets/TextMesh Pro/Examples & Extras/Scripts/ChatController.cs b/Pathfinding Visualizer/Assets/TextMesh Pro/Examples & Extras/Scripts/ChatController.cs
new file mode 100644
index 0000000..2915c96
--- /dev/null
+++ b/Pathfinding Visualizer/Assets/TextMesh Pro/Examples & Extras/Scripts/ChatController.cs
@@ -0,0 +1,51 @@
+using UnityEngine;
+using UnityEngine.UI;
+using TMPro;
+
+public class ChatController : MonoBehaviour {
+
+
+ public TMP_InputField ChatInputField;
+
+ public TMP_Text ChatDisplayOutput;
+
+ public Scrollbar ChatScrollbar;
+
+ void OnEnable()
+ {
+ ChatInputField.onSubmit.AddListener(AddToChatOutput);
+ }
+
+ void OnDisable()
+ {
+ ChatInputField.onSubmit.RemoveListener(AddToChatOutput);
+ }
+
+
+ void AddToChatOutput(string newText)
+ {
+ // Clear Input Field
+ ChatInputField.text = string.Empty;
+
+ var timeNow = System.DateTime.Now;
+
+ string formattedInput = "[<#FFFF80>" + timeNow.Hour.ToString("d2") + ":" + timeNow.Minute.ToString("d2") + ":" + timeNow.Second.ToString("d2") + "</color>] " + newText;
+
+ if (ChatDisplayOutput != null)
+ {
+ // No special formatting for first entry
+ // Add line feed before each subsequent entries
+ if (ChatDisplayOutput.text == string.Empty)
+ ChatDisplayOutput.text = formattedInput;
+ else
+ ChatDisplayOutput.text += "\n" + formattedInput;
+ }
+
+ // Keep Chat input field active
+ ChatInputField.ActivateInputField();
+
+ // Set the scrollbar to the bottom when next text is submitted.
+ ChatScrollbar.value = 0;
+ }
+
+}