summaryrefslogtreecommitdiff
path: root/ChatController.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-03-13 11:00:58 +0800
committerchai <215380520@qq.com>2024-03-13 11:00:58 +0800
commit6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch)
treeb38119d2acf0a982cb67e381f146924b9bfc3b3f /ChatController.cs
+init
Diffstat (limited to 'ChatController.cs')
-rw-r--r--ChatController.cs34
1 files changed, 34 insertions, 0 deletions
diff --git a/ChatController.cs b/ChatController.cs
new file mode 100644
index 0000000..d98a965
--- /dev/null
+++ b/ChatController.cs
@@ -0,0 +1,34 @@
+using System;
+using TMPro;
+using UnityEngine;
+using UnityEngine.UI;
+
+public class ChatController : MonoBehaviour
+{
+ public TMP_InputField TMP_ChatInput;
+
+ public TMP_Text TMP_ChatOutput;
+
+ public Scrollbar ChatScrollbar;
+
+ private void OnEnable()
+ {
+ TMP_ChatInput.onSubmit.AddListener(AddToChatOutput);
+ }
+
+ private void OnDisable()
+ {
+ TMP_ChatInput.onSubmit.RemoveListener(AddToChatOutput);
+ }
+
+ private void AddToChatOutput(string newText)
+ {
+ TMP_ChatInput.text = string.Empty;
+ DateTime now = DateTime.Now;
+ TMP_Text tMP_ChatOutput = TMP_ChatOutput;
+ string text = tMP_ChatOutput.text;
+ tMP_ChatOutput.text = text + "[<#FFFF80>" + now.Hour.ToString("d2") + ":" + now.Minute.ToString("d2") + ":" + now.Second.ToString("d2") + "</color>] " + newText + "\n";
+ TMP_ChatInput.ActivateInputField();
+ ChatScrollbar.value = 0f;
+ }
+}