跳转到主要内容

通知消息接收

PlayNANOO 聊天服务除了公开和私密消息外,还支持从控制台发送通知消息。 从控制台发送通知消息时,消息将发送给所有用户。

回调方法信息

public void OnNotifyMessage(ChatInfoModel chatInfo, string message) {}

ChatInfoModel Class 详细信息

ChatInfoModel Class 中记录了发送消息的频道及用户信息。

数据键说明类型
gameId游戏 IDstring
channelId频道 IDstring
userUniqueId用户 IDstring
userName用户名string

源代码

using UnityEngine;
using PlayNANOO.ChatServer;
using PlayNANOO.ChatServer.Models;

public class PlayNANOOChatExample : MonoBehaviour, IChatListener
{
ChatClient chatClient;

void Start()
{
chatClient = new ChatClient(this);
chatClient.SetPlayer("USER_ID", "USER_NAME");
chatClient.Connect();
}

void Update()
{
if (chatClient != null)
{
chatClient.Service();
}
}

public void OnConntected()
{
chatClient.Subscribe("CHANNEL_ID");
}

public void OnSubscribed(ChatInfoModel chatInfo)
{
Debug.Log("User Joined");
}

public void OnNotifyMessage(ChatInfoModel chatInfo, string message)
{
Debug.Log(message);
}
}