using Byn.Unity.Examples; using System; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; namespace SHINT.UI { public class UI_Chating : MonoBehaviour { InputField MessageInputField; MessageList uOutput; Button SendButton; public string message => MessageInputField.text; public event Action onClickSend; public event Action onInputEditEnd; public void Active() { uOutput = GetComponent(); if (uOutput != null) { uOutput.gameObject.SetActive(true); } SendButton.onClick.AddListener(() => onClickSend?.Invoke()); MessageInputField.onEndEdit.AddListener(InputOnEndEdit); } public void InputOnEndEdit(string msg) { if (Input.GetKey(KeyCode.Return)) { onInputEditEnd?.Invoke(MessageInputField.text); } } public void OnSendMessage() { MessageInputField.text = ""; //make sure the text box is in focus again so the user can continue typing without clicking it again //select another element first. without this the input field is in focus after return pressed SendButton.Select(); MessageInputField.Select(); } public void Append(string text) { Debug.Log(text); uOutput.AddTextEntry(text); } } }