跳转到主要内容

创建表

用于创建排行榜表的 API。

URL 确认

此 API 使用 service-api.playnanoo.com 域名。

API 信息

  • URL: https://service-api.playnanoo.com/leaderboard/v20240301/table/create
  • Method: PUT
  • 需要认证: 是
DeviceInfo 继承

此 API 的 Req 类继承自 DeviceInfo。DeviceInfo 的所有属性会自动包含。

请求参数

参数类型必填说明
namestring必填表名称
rotationstring必填循环方式 ("never" 或 "rotation")
rotation_timeoffsetint条件循环时间偏移(rotation 时必填)
rotation_datestring条件循环开始日期(rotation 时必填)
rotation_timestring条件循环开始时间(rotation 时必填)
rotation_periodint条件循环周期(天)(rotation 时必填)
record_typestring必填记录类型 ("highscore", "lowscore", "sum", "last")
record_sort_typestring必填排序类型 ("asc", "desc")
record_prioritystring必填记录优先级 ("Y" 或 "N")

响应数据

Res 类

字段类型说明
TableIdstring创建的表 ID

Unity C# 实现

BaseResponse 类

所有 API 响应的基类。

public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}

字段说明:

  • ErrorCode:错误代码
  • Message:错误信息
  • WithdrawalKey:账号处于注销等待状态时,用于恢复的密钥(仅注销等待中的账号提供)
  • BlockKey:账号被封禁时提供的密钥(仅被封禁的账号提供)

Enum 定义

public enum Rotaion
{
NEVER,
ROTATION
}

public enum RecordType
{
LOWSCORE,
HIGHSCORE,
SUM,
LAST
}

public enum SortType
{
DESC,
ASC
}

创建表类

using System;
using System.Collections;
using UnityEngine.Networking;

public class CreateTable
{
static string path = "https://service-api.playnanoo.com/leaderboard/v20240301/table/create";

[Serializable]
public class Req : DeviceInfo
{
public string name;

public string rotation;

public string record_type;

public string record_sort_type;

public string record_priority;

public int rotation_timeoffset;

public string rotation_date;

public string rotation_time;

public int rotation_period;

public IEnumerator Send(
string name,
Rotaion rotation,
int rotationTimeOffset,
string rotationDate,
string rotationTime,
int rotationPeriod,
RecordType recordType,
SortType recordSortType,
bool recordPriority,
Action<Res> onSuccess,
Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(name)) this.name = name;
this.record_priority = recordPriority ? "Y" : "N";
this.rotation = GetRotation(rotation);
this.record_type = GetRecordType(recordType);
this.record_sort_type = GetSortType(recordSortType);
if(this.rotation == "rotation")
{
this.rotation_timeoffset = rotationTimeOffset;
this.rotation_period = rotationPeriod;
if (!string.IsNullOrEmpty(rotationDate)) this.rotation_date = rotationDate;
if (!string.IsNullOrEmpty(rotationTime)) this.rotation_time = rotationTime;
}

yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}

// 공통 Common 함수로 만들어 두세요.
private string GetRotation(Rotaion value)
{
if (value == Rotaion.NEVER)
{
return "never";
}

return "rotation";
}

private string GetRecordType(RecordType value)
{
return value switch
{
RecordType.LOWSCORE => "lowscore",
RecordType.SUM => "sum",
RecordType.LAST => "last",
_ => "highscore",
};
}

private string GetSortType(SortType value)
{
if (value == SortType.ASC)
{
return "asc";
}

return "desc";
}
}

[Serializable]
public class Res : BaseResponse
{
public string TableId;
}
}

使用示例

public void CreateLeaderboardTable()
{
CreateTable.Req req = new CreateTable.Req();

StartCoroutine(req.Send(
name: "Weekly Ranking",
rotation: Rotaion.ROTATION,
rotationTimeOffset: 0,
rotationDate: "2024-03-01",
rotationTime: "00:00:00",
rotationPeriod: 7, // 7일마다 순환
recordType: RecordType.HIGHSCORE,
recordSortType: SortType.DESC,
recordPriority: true,
onSuccess: res =>
{
Debug.Log("테이블 생성 성공");
Debug.Log($"테이블 ID: {res.TableId}");
},
onError: error =>
{
Debug.LogError($"테이블 생성 실패: [{error.ErrorCode}] {error.Message}");
}
));
}
循环方式
  • never:赛季不循环的永久排行榜
  • rotation:按指定周期自动循环赛季的排行榜
记录类型
  • highscore:仅保留最高分
  • lowscore:仅保留最低分
  • sum:累加所有分数
  • last:更新为最近的分数
循环周期

rotation_period 以天为单位设置。例如,要每 7 天循环一次,请将 rotation_period 设置为 7。