广播聊天测试
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Assets.Scripts.Entity;
|
||||
using Assets.Scripts.Hotfix;
|
||||
using FairyGUI;
|
||||
@@ -12,6 +13,8 @@ namespace NBF
|
||||
{
|
||||
public partial class ChatTestPanel : UIPanel
|
||||
{
|
||||
private List<string> _messages = new List<string>();
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
this.AutoAddClick(OnClick);
|
||||
@@ -22,6 +25,18 @@ namespace NBF
|
||||
SetLoginState(false);
|
||||
}
|
||||
|
||||
private void RefreshList()
|
||||
{
|
||||
ChatList.RemoveChildrenToPool();
|
||||
foreach (var item in _messages)
|
||||
{
|
||||
if(ChatList.AddItemFromPool() is ChatItem chatItem)
|
||||
{
|
||||
chatItem.InitData(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClick(GComponent btn)
|
||||
{
|
||||
if (btn == BtnLogin)
|
||||
@@ -34,6 +49,10 @@ namespace NBF
|
||||
|
||||
OnLoginButtonClick(InputAccount.text).Coroutine();
|
||||
}
|
||||
else if (btn == BtnSendWorld)
|
||||
{
|
||||
OnSendMessage(InputMessage.title).Coroutine();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetLoginState(bool isLogin = false, string account = "")
|
||||
@@ -133,5 +152,27 @@ namespace NBF
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 发生消息测试
|
||||
|
||||
private async FTask OnSendMessage(string message)
|
||||
{
|
||||
var messageResponse = (Caht2C_SendMessageResponse)await _session.Call(new C2Chat_SendMessageRequest()
|
||||
{
|
||||
Message = message
|
||||
});
|
||||
if (messageResponse.ErrorCode != 0)
|
||||
{
|
||||
Notices.Info($"发送消息失败,code={messageResponse.ErrorCode}");
|
||||
}
|
||||
}
|
||||
|
||||
public void Message(string message)
|
||||
{
|
||||
_messages.Add(message);
|
||||
RefreshList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user