游戏创意与功能

你的下一项功能

玩家资料

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

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

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

使用玩家资料2:37

此教程以英语播放。

单独打开视频 ↗

准备同一个项目

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

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

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

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

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

实现此功能

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

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

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

保存C#文件并挂到GameObject,进入Play后检查Console。

C#
Assets/Scripts/PlayerProfileDemo.cs
horizOn 调用准备
1using UnityEngine;
2using PM.horizOn.Cloud.Core;
3using PM.horizOn.Cloud.Manager;
4​
5// 将此脚本挂到第一个场景中的某个 GameObject 上。
6public class PlayerProfileDemo : MonoBehaviour
7{
8 async void Start()
9 {
10 // 准备:初始化、连接并登录玩家。
11 HorizonApp.Initialize();
12 await new HorizonServer().Connect();
13 if (!UserManager.Instance.IsSignedIn)
14 {
15 bool authenticated = UserManager.Instance.HasCachedAnonymousToken()
16 ? await UserManager.Instance.RestoreAnonymousSession()
17 : await UserManager.Instance.SignUpAnonymous("StatisticsPlayer");
18 if (!authenticated) return;
19 }
20​
21 // horizOn:读取资料,然后修改头像、头像框和徽章。
22 // Profile, unlocks and the cosmetics catalog of the signed in player
23 var profile = await PlayerProfileManager.Instance.GetProfile();
24 if (profile == null) { Debug.Log(PlayerProfileManager.Instance.LastErrorCode); return; }
25​
26 // Save avatar, frame and up to three badges (ids from your catalog in the dashboard)
27 var updated = await PlayerProfileManager.Instance.SetProfile(
28 "avatar.zombie_07", profile.profile.frameId, new[] { "badge.supporter" });
29 }
30}
打开完整SDK示例 ↗

测试你的新功能。

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

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

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

为每一局添加最高分。

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

教程视频

玩家资料Unity2:31

此教程以英语播放。

单独打开视频 ↗