游戏创意与功能

你的下一项功能

聊天管理

保留玩家消息、显式实时订阅和有界审核。

SDK:develop 分支需要玩家会话
Unity
聊天管理功能示意图
可见的结果

两个现有会话打开项目频道,发送一次、读取快照并举报保留消息。私聊需要好友,群聊需要有效成员资格。

视频稍后提供

此步骤尚无视频。指南和MCP请求已可使用。

聊天管理

准备同一个项目

  1. 在仪表盘中选择与游戏配置相同的项目。

    聊天管理 →
  2. 首次请求不需要额外定义。没有对应游戏数据时,空结果也有效。

    两个现有会话打开项目频道,发送一次、读取快照并举报保留消息。私聊需要好友,群聊需要有效成员资格。

    PHP simpleServer的所有Chat路由均返回501 NOT_SUPPORTED。

实现此功能

你可以预览指南。运行需要有效的项目密钥。 准备项目

已安装 SDK、导入项目配置,且玩家已登录。

此 SDK 示例使用 develop。请检查已安装的 SDK 是否具备所需 API。

先通过快速入门连接目标玩家,再通过明确的按钮或场景操作调用ReadChannelSnapshot(channelId)。仅打开文件不会发送请求。

C#
Assets/Scripts/ChatDemo.cs
horizOn 调用
1using UnityEngine;
2using PM.horizOn.Cloud.Manager;
3​
4// Existing imported SDK and authenticated player session required.
5// Call these methods explicitly from a player action; nothing runs on startup.
6public sealed class ChatDemo : MonoBehaviour
7{
8 public async void ReadChannelSnapshot(string channelId)
9 {
10 var user = UserManager.Instance.CurrentUser;
11 if (user == null || !user.IsValid()) return;
12 var result = await ChatManager.Instance.SyncChannel(user.UserId, channelId);
13 if (!result.IsSuccess) { Debug.LogWarning(result.ErrorCode); return; }
14 Debug.Log("Snapshot epoch: " + result.Data.channel.epoch);
15 foreach (var message in result.Data.messages) Debug.Log(message.text);
16 // This is the small authorized server window, not the full device history.
17 // A raw snapshot does not authorize or populate a managed realtime feed.
18 // WatchChannel waits for confirmed subscription; revocation hides the feed.
19 }
20​
21 public void ReadDeviceHistory(string channelId, string before = null)
22 {
23 var user = UserManager.Instance.CurrentUser;
24 if (user == null || !user.IsValid()) return;
25 var page = ChatManager.Instance.ReadLocalHistory(channelId, before, 50);
26 if (!page.IsSuccess) { Debug.LogWarning(page.ErrorCode); return; }
27 foreach (var message in page.Data.messages) Debug.Log(message.text);
28 // Continue only on an explicit action using page.Data.nextCursor.
29 // Local delivered history can outlive the small current server window.
30 // For send/report, import the SDK ChatExample and preserve its original
31 // operationId, issuedAt, channel and text before one explicit send.
32 // An uncertain outcome never permits a fresh identity or implicit retry.
33 }
34}
打开完整SDK示例 ↗

两名玩家,一个频道

两个现有会话打开项目频道,发送一次、读取快照并举报保留消息。私聊需要好友,群聊需要有效成员资格。

受管信息流需订阅确认后使用事件/resync、一个Sync和变更标记。无轮询或断线替代,权限撤销时隐藏缓存文本。

发送前按项目和玩家保存精确原始请求。主机和会话仅用于请求边界。不得替换结果未知的ID、时间、文本或修订号。

操作404不能证明失败。超时或OPERATION_EXPIRED后保留原始请求,仅用匹配回执核对。

复用原始举报ID和原因。removed表示成功重放,REPORT_EXPIRED不能创建新举报。

PHP simpleServer的所有Chat路由均返回501 NOT_SUPPORTED。

测试你的新功能。

两个现有会话打开项目频道,发送一次、读取快照并举报保留消息。私聊需要好友,群聊需要有效成员资格。

在仪表盘中选择与游戏配置相同的项目。

接口
  • GET/chat/limits
  • POST/chat/channels/open
  • POST/chat/channels/{channelId}/sync
  • POST/chat/channels/{channelId}/messages
  • GET/chat/operations/{operationId}
  • POST/chat/channels/{channelId}/messages/{messageId}/report
API 参考中的全部接口
下一步建议

为每一局添加最高分。

每局结束后保存分数并展示领先者。继续使用现有连接和玩家会话。