你的下一项功能
已验证操作
让服务器验证游戏操作。
Unity

可见的结果
有效操作被接受,无效操作被拒绝。
此步骤尚无视频。指南和MCP请求已可使用。
验证游戏操作
实现此功能
你可以预览指南。运行需要有效的项目密钥。 准备项目
已安装 SDK、导入项目配置,且玩家已登录。
此 SDK 示例使用 develop。请检查已安装的 SDK 是否具备所需 API。
C#
1using UnityEngine;
2using PM.horizOn.Cloud.Core;
3using PM.horizOn.Cloud.Manager;
4
5// 将此脚本挂到第一个场景中的某个 GameObject 上。
6public class ValidatedActionsDemo : MonoBehaviour
7{
8 async void Start()
9 {
10 // 准备:初始化、连接并登录玩家。
11 HorizonApp.Initialize();
12 await new HorizonServer().Connect();
13 await UserManager.Instance.SignUpAnonymous("PlayerName");
14
15 byte[] inputLog = System.Array.Empty<byte>();
16
17 // horizOn:开始一局,记录输入,提交经过验证的分数。
18 // 1. Dashboard: turn on "Validated submissions only" for the board "weekly"
19 var va = ValidatedActionsManager.Instance;
20
21 // 2. Round start: single-use ticket plus server seed
22 var run = await va.StartRun("weekly");
23 if (run == null) { Debug.Log(va.LastErrorCode); return; } // e.g. RUN_RATE_LIMITED
24 var random = new System.Random(run.seed);
25
26 // ... play, record the inputs into inputLog (byte[]) ...
27
28 // 3. Round end: score plus input log (the SDK sends its SHA-256 hash)
29 var result = await va.SubmitValidated(18250, inputLog);
30 if (result == null)
31 {
32 Debug.Log($"{va.LastErrorCode}, run kept: {va.HasActiveRun}"); // e.g. DURATION_TOO_SHORT
33 }
34 }
35}
测试你的新功能。
有效操作被接受,无效操作被拒绝。
在仪表盘中选择与游戏配置相同的项目。


