EchoTrio
 
Loading...
Searching...
No Matches
Chatbox.cs
Go to the documentation of this file.
1using System.Collections;
2using UnityEngine;
3
4namespace EchoTrio.UI {
5 public class Chatbox : MonoBehaviour {
6 [SerializeField] private UnityEngine.UI.ScrollRect scrollView = null;
7 [SerializeField] private TMPro.TMP_Text textArea = null;
8
9 // Public Interfaces.
10 public void AddMessage(string speaker, string message) {
11 textArea.text += speaker + ": " + message + "\n\n";
13 }
14
15 public void AddMessage(string message) {
16 textArea.text += message + "\n\n";
18 }
19
20 public void ScrollToBottom() {
21 if (gameObject.activeSelf) {
22 StartCoroutine(ScrollToBottomCoroutine());
23 }
24 }
25
26 // Internal Functions
27 private void Start() { }
28
29 private void Update() { }
30
31 private IEnumerator ScrollToBottomCoroutine() {
32 yield return null; // Wait for 1 frame so that the ScrollRect can resize and stuff.
33 scrollView.verticalNormalizedPosition = 0.0f; // Just scroll it all the way to the very bottom for now. Do this 1 frame later once the ScrollRect has resized.
34 }
35 }
36}
void ScrollToBottom()
Definition: Chatbox.cs:20
UnityEngine.UI.ScrollRect scrollView
Definition: Chatbox.cs:6
IEnumerator ScrollToBottomCoroutine()
Definition: Chatbox.cs:31
void AddMessage(string speaker, string message)
Definition: Chatbox.cs:10
TMPro.TMP_Text textArea
Definition: Chatbox.cs:7
void AddMessage(string message)
Definition: Chatbox.cs:15