私密消息收发
向当前连接到应用程序的好友发送一对一私密消息。
调用信息
SendPrivateMessage(string friendUserId, string message) {}
调用详细信息
| 参数 | 说明 | 类型 |
|---|---|---|
| friendUserId | 好友用户 ID | string |
| message | 发送消息 | string |
回调方法信息
public void OnPrivateMessage(ChatInfoModel chatInfo, string message) {}
ChatInfoModel Class 详细信息
ChatInfoModel Class 中记录了发送消息的频道及用户信息。
| 数据键 | 说明 | 类型 |
|---|---|---|
| gameId | 游戏 ID | string |
| channelId | 频道 ID | string |
| userUniqueId | 用户 ID | string |
| 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 SendPrivateMessage()
{
string friendUserId = "string";
string message = "string";
chatClient.SendPrivateMessage(friendUserId, message);
}
public void OnPrivateMessage(ChatInfoModel chatInfo, string message)
{
Debug.Log(message);
}
}