查询公共数据
用于加载设置为公开的游戏数据的 API。
URL 确认
此 API 使用 service-storage-api.playnanoo.com 域名。
API 信息
- URL:
https://service-storage-api.playnanoo.com/storage/v20211101/load/public - Method:
PUT - 需要认证: 是
DeviceInfo 继承
此 API 的 Req 类继承自 DeviceInfo。DeviceInfo 的所有属性会自动包含。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| storage_key | string | 必填 | 要加载的数据键 |
响应数据
Res 类
| 字段 | 类型 | 说明 |
|---|---|---|
| StorageKey | string | 已保存的数据键 |
| StorageValue | string | 已保存的数据值 |
Unity C# 实现
BaseResponse 类
所有 API 响应的基类。
public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}
字段说明:
ErrorCode:错误代码Message:错误信息WithdrawalKey:账号处于注销等待状态时,用于恢复的密钥(仅注销等待中的账号提供)BlockKey:账号被封禁时提供的密钥(仅被封禁的账号提供)
查询公共数据类
using System;
using System.Collections;
using UnityEngine.Networking;
public class StoragePublicLoad
{
static string path = "https://service-storage-api.playnanoo.com/storage/v20211101/load/public";
[Serializable]
public class Req : DeviceInfo
{
public string storage_key;
public IEnumerator Send(string storage_key, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(storage_key)) this.storage_key = storage_key;
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public string StorageKey;
public string StorageValue;
}
}
使用示例
public void LoadPublicData()
{
StoragePublicLoad.Req req = new StoragePublicLoad.Req();
StartCoroutine(req.Send(
storage_key: "public_ranking_data",
onSuccess: res =>
{
Debug.Log("공개 데이터 불러오기 성공");
Debug.Log($"저장 키: {res.StorageKey}");
// JSON 역직렬화
var rankingData = JsonUtility.FromJson<RankingData>(res.StorageValue);
Debug.Log($"상위 플레이어 수: {rankingData.topPlayers.Length}");
},
onError: error =>
{
Debug.LogError($"데이터 불러오기 실��: [{error.ErrorCode}] {error.Message}");
}
));
}
[Serializable]
public class RankingData
{
public string[] topPlayers;
public int[] scores;
}
公共数据用途
此 API 用于加载排名、公告、活动信息等所有玩家都可以访问的公共数据。
isPrivate 设置
只有在保存数据时将 isPrivate 设置为 false 或 "off" 的数据才能通过此 API 加载。