跳转到主要内容

修改表

用于修改排行榜表设置的 API。

URL 确认

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

API 信息

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

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

请求参数

参数类型必填说明
uidstring必填表代码
record_typestring必填记录类型 ("highscore", "lowscore", "sum", "last")
record_sort_typestring必填排序类型 ("asc", "desc")
record_prioritystring必填记录优先级 ("Y" 或 "N")

响应数据

Res 类

字段类型说明
Statusstring处理状态

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 RecordType
{
LOWSCORE,
HIGHSCORE,
SUM,
LAST
}

public enum SortType
{
DESC,
ASC
}

修改表类

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

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

[Serializable]
public class Req : DeviceInfo
{
public string uid;
public string record_type;
public string record_sort_type;
public string record_priority;

public IEnumerator Send(
string table_code,
RecordType recordType,
SortType recordSortType,
bool recordPriority,
Action<Res> onSuccess,
Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(table_code)) this.uid = table_code;
this.record_type = GetRecordType(recordType);
this.record_sort_type = GetSortType(recordSortType);
this.record_priority = recordPriority ? "Y" : "N";

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

// 공통 Common 함수로 만들어 두세요.
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 Status;
}
}

使用示例

public void EditLeaderboardTable()
{
TableEdit.Req req = new TableEdit.Req();

StartCoroutine(req.Send(
table_code: "my_leaderboard_table",
recordType: RecordType.LOWSCORE, // 낮은 점수가 더 좋은 경우
recordSortType: SortType.ASC, // 오름차순 정렬
recordPriority: true,
onSuccess: res =>
{
Debug.Log("테이블 수정 성공");
Debug.Log($"상태: {res.Status}");
},
onError: error =>
{
Debug.LogError($"테이블 수정 실패: [{error.ErrorCode}] {error.Message}");
}
));
}
记录类型
  • highscore:仅保留最高分
  • lowscore:仅保留最低分(适用于赛车游戏等)
  • sum:累加所有分数
  • last:更新为最近的分数
排序类型
  • desc:降序排列(高分排在前面)
  • asc:升序排列(低分排在前面)
修改表注意事项

更改表设置可能会改变现有的排名计算方式。由于可能影响玩家已记录的分数,请谨慎修改。