当前位置:
首页 > Python基础教程 >
-
C#教程之UDP实现一个简易的聊天室(多个主机连接(2)
//显示消息
ChatLine line = new ChatLine()
{
//事件参数对象赋值????
Time = args.DateTime,
Message = args.Message.Content,
Type = ChatLineType.User,
UserName=args.Message.SenderName
};
chatview.DataSource.Add(line);
//滚动
chatview.ScrollRect.verticalNormalizedPosition = 0;
}
}
}
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Common; namespace NS { ///<summary> ///服务端显示面板 ///</summary> public class ChatServer : MonoBehaviour { private void Start() { text = transform.FindChildByName("Text").GetComponent<Text>(); UDPServerNetWorkService.Instance.MessageArrivedEventHandler += OnMessageArrived; } private Text text; //当服务端收到消息 显示在文本中 private void OnMessageArrived(MessageArrivedEventArgs obj) { Debug.Log(obj.Message.Type); text.text = string.Format("{0}---{1}", obj.Message.Type, obj.Message.Content); } } }
工程包链接: https://github.com/AnsssAS/Assect