赞
踩
输入文字,回车即可输入输入聊天内容。
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
-
- public class ControlChatRoom : MonoBehaviour
- {
-
- public InputField chatInput;
- public Text chatText;
- public ScrollRect scrollRect;
- string username = "DHX";
- // Use this for initialization
- void Start()
- {
-
- }
-
- // Update is called once per frame
- void Update()
- {
-
- if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
- {
- if (chatInput.text != "")
- {
- string addText = "\n " + "<color=red>" + username + "</color>:\u00A0" + chatInput.text;
- chatText.text += addText;
- chatInput.text = "";
- chatInput.ActivateInputField();
- Canvas.ForceUpdateCanvases();
- scrollRect.verticalNormalizedPosition = 0f;
- Canvas.ForceUpdateCanvases();
- }
- }
-
- }
- }
Content Size Fitter 组件:自适应
mask:遮罩
scrollRect:动态滑动+scrollbar 动态滑块
InputField:输入组件
如果出了空格换行的问题可以用:Unicode编码为/u00A0。
链接:https://pan.baidu.com/s/12A-57rNIXKLK6I4ToZ_MuA
提取码:xy69
参考:
Text组件自动换行: https://www.jianshu.com/p/2960f30b3bca?from=singlemessage
制作聊天室界面:https://blog.csdn.net/sajiazaici/article/details/78312887
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。