using UnityEngine; using TMPro; /// <summary> /// 按键盘Enter键发送输入消息 /// </summary> public class KeyEnterSend : MonoBehaviour { [SerializeField] private TMP_InputField m_InputField; private void Awake() { m_InputField.onEndEdit.AddListener(OnInputFieldEndEdit); } // 完成编辑时触发,也可理解为失去焦点时触发。 private void OnInputFieldEndEdit(string value) { //回车(KeyCode.Return) //小键盘回车(KeyCode.KeypadEnter) if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) { Debug.LogFormat("发送消息: {0}", value); } } }