广播聊天测试

This commit is contained in:
bob
2025-08-07 17:51:38 +08:00
parent abb211e0da
commit 3c39f4a3c9
6 changed files with 73 additions and 0 deletions

View File

@@ -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
}
}