游戏创意与功能

你的下一项功能

玩家资料

显示玩家的头像、头像框和徽章。

SDK:develop 分支需要玩家会话
Godot
玩家资料功能示意图
可见的结果

重新加载个人资料后,所选头像、头像框或徽章会显示出来。

使用玩家资料2:37

此教程以英语播放。

单独打开视频 ↗

准备同一个项目

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

    玩家资料 →
  2. 在控制台表单中创建或复用这些测试条目。这些是示例值,并非项目当前数据。

    外观 ID
    avatar.zombie_07 (avatar), badge.supporter (badge)
    已锁定(只有拥有解锁的玩家才能选择)
    false

    每个条目都是一个 ID,由你的游戏映射到自己的美术资源。免费条目所有玩家都能选择,锁定条目只有拥有解锁的玩家才能选择(来自带解锁的礼品码,或在用户管理中授予)。

  3. 运行示例前先保存、重新加载并核对条目。保留其他定义。

实现此功能

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

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

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

保存GDScript并挂到主场景节点,运行后检查Output。

GDScript
res://scripts/player_profile.gd
horizOn 调用准备
1# 将此脚本挂到主场景中的某个节点上。
2extends Node
3​
4​
5func _ready() -> void:
6 # 准备:初始化、连接并登录玩家。
7 var connected = await Horizon.connect_to_server()
8 if not connected:
9 print("Failed to connect to horizOn server")
10 return
11 if not Horizon.auth.isSignedIn():
12 var signed_in: bool
13 if Horizon.auth.hasCachedAnonymousToken():
14 signed_in = await Horizon.auth.restoreAnonymousSession()
15 else:
16 signed_in = await Horizon.auth.signUpAnonymous("StatisticsPlayer")
17 if not signed_in:
18 return
19​
20 # horizOn:读取资料,然后修改头像、头像框和徽章。
21 # Profile, unlocks and the cosmetics catalog of the signed in player
22 var result: Dictionary = await Horizon.playerProfile.getProfile()
23 var profile: Dictionary = result.get("profile", {})
24​
25 # Save avatar, frame and up to three badges (ids from your catalog in the dashboard)
26 var updated: Dictionary = await Horizon.playerProfile.setProfile(
27 "avatar.zombie_07", profile.get("frameId", ""), ["badge.supporter"])
28 if updated.is_empty():
29 print(Horizon.playerProfile.getLastErrorCode())
打开完整SDK示例 ↗

测试你的新功能。

重新加载个人资料后,所选头像、头像框或徽章会显示出来。

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

接口
  • GET/player-profile
  • PUT/player-profile
API 参考中的全部接口
排行榜功能示意图
下一步建议

为每一局添加最高分。

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

教程视频

玩家资料Godot3:21

此教程以英语播放。

单独打开视频 ↗