04/28/2025 20:45:36

成就排行模块

一、概述

成就排行模块,用于展示游戏进度,显示成就、排行榜、解锁成就、设置分数以及发起挑战等。

目前支持的渠道有:

  1. GameCenter
  2. Google

二、接入向导

2.1 注册回调

1)功能描述

接受MSDK排行榜模块的回调,游戏需要注册回调函数进行处理。

2)接口声明

C#
C++
/// Game的回调接口
public static event OnMSDKRetEventHandler<MSDKBaseRet> GameBaseRetEvent;
public static void SetGameObserver(MSDKGameObserver *gameObserver);

class MSDKGameObserver
{
public:
    virtual ~MSDKGameObserver() {};
    // Game的回调接口
    virtual void OnBaseRetNotify(const MSDKBaseRet &baseRet) {};
};

3)示例代码

C#
C++
MSDKGame.GameBaseRetEvent += OnGameBaseRetEvent;

public void OnGameBaseRetEvent(MSDKBaseRet ret)
{
  string methodTag = "";
  if (ret.MethodNameId == (int)MSDKMethodNameID.MSDK_GAME_SETUP) {
    methodTag = "GameSetUp";
  } else if (ret.MethodNameId == (int)MSDKMethodNameID.MSDK_GAME_SHOW_LEADER_BOARD) {
    methodTag = "ShowLeaderBoard";
  } else if (ret.MethodNameId == (int)MSDKMethodNameID.MSDK_GAME_SET_SCORE) {
    methodTag = "SetScore";
  } else if (ret.MethodNameId == (int)MSDKMethodNameID.MSDK_GAME_SHOW_ACHIEVEMENT) {
    methodTag = "ShowAchievement";
  } else if (ret.MethodNameId == (int)MSDKMethodNameID.MSDK_GAME_UNLOCK_ACHIEVE) {
    methodTag = "UnlockAchieve";
  } else if (ret.MethodNameId == (int)MSDKMethodNameID.MSDK_GAME_SHOW_CHALLENGE) {
    methodTag = "ShowChallenge"; // 仅 GameCenter 支持
  } else if (ret.MethodNameId == (int)MSDKMethodNameID.MSDK_GAME_SEND_CHALLENGE) {
    methodTag = "SendChallenge"; // 仅 GameCenter 支持
  }
  SampleInstance.showRetDialog(methodTag, ret);
}

//销毁的时候需要移除回调
private void OnDestroy()
{
  MSDKGame.GameBaseRetEvent -= OnGameBaseRetEvent;
}
MSDKGame::SetGameObserver(new MyGameObserver());

class MyGameObserver : public MSDKGameObserver {
public:
    virtual ~MSDKGameObserver() {};

    // Game的回调接口
    virtual void OnBaseRetNotify(const MSDKBaseRet &baseRet) {
        String ret = MSDKUtils::FormatJson(MSDKJsonManager::ToJson(baseRet));
        UMSDKDemoBase::showNormalAlert(ret);
    };
};

2.2 初始化排行榜功能

1)功能描述

初始化游戏排行榜功能。

2)接口声明

C#
C++
public static void Setup(string channel="", string extraJson="")
public static void Setup(const string &channel = "", const string &extraJson = "")

3)入参说明

参数名称 参数类型 说明
channel string 渠道
extraJson string 扩展字段

4)示例代码

C#
C++
MSDKGame.Setup("Google");
MSDKGame::Setup("Google");

2.3 显示成就界面

1)功能描述

显示成就界面。

2)接口声明

C#
C++
public static void ShowAchievement(string channel="", string extraJson="")
public static void ShowAchievement(const string &channel = "", const string &extraJson = "")

3)入参说明

参数名称 参数类型 说明
channel string 渠道
extraJson string 扩展字段

4)示例代码

C#
C++
MSDKGame.ShowAchievement("Google");
MSDKGame::ShowAchievement("Google");

2.4 展示排行榜界面

1)功能描述

展示排行榜界面。

2)接口声明

C#
C++
public static void ShowLeaderBoard(string board, string channel="", string extraJson="")
public static void ShowLeaderBoard(const string &board, const string &channel = "", const string &extraJson = "")

3)入参说明

参数名称 参数类型 说明
board string 对应创建的排行榜信息
channel string 渠道
extraJson string 扩展字段

4)示例代码

C#
C++
MSDKGame.ShowLeaderBoard("idOfLeaderboard", "Google");
MSDKGame::ShowLeaderBoard("idOfLeaderboard", "Google");

2.5 设置分数

1)功能描述

设置分数。

2)接口声明

C#
C++
public static void SetScore(string board, int score, string channel="", string extraJson="")
public static void SetScore(const string &board, int score, const string &channel = "", const string &extraJson = "")

3)入参说明

参数名称 参数类型 说明
board string 对应管理端创建的排行榜信息
score int 需要设置的分数
channel string 渠道
extraJson string 扩展字段

4)示例代码

C#
C++
MSDKGame.SetScore("idOfLeaderboard", 200, "Google");
MSDKGame::SetScore("idOfLeaderboard", 200, "Google");

2.6 解锁指定的成就

1)功能描述

解锁指定的成就。

2)接口声明

C#
C++
public static void UnlockAchievement(string board, double count, string channel="", string extraJson="")
public static void UnlockAchievement(const string &achieve, double count, const string &channel = "", const string &extraJson = "")

3)入参说明

参数名称 参数类型 说明
achieve string 成就名称
count double 0代表普通的 achievement,非0数值代表 incremental achievement 的增长步数
channel string 渠道
extraJson string 扩展字段

4)示例代码

C#
C++
MSDKGame.UnlockAchievement("achieveId", 3, "Google");
// apply for incremental achievement
MSDKGame::UnlockAchievement("idOfIncrementalAchievement", 2, "Google");
// apply for oridary achievement
MSDKGame::UnlockAchievement("idOfAchievement", 0, "Google");

2.7 显示挑战界面

1)功能描述

显示挑战界面。

2)接口声明

C#
C++
public static void ShowChallenge(string channel="", string extraJson="")
public static void ShowChallenge(const string &channel = "", const string &extraJson = "")

3)入参说明

参数名称 参数类型 说明
channel string 渠道,仅 GameCenter 支持
extraJson string 扩展字段

4)示例代码

C#
C++
MSDKGame.ShowChallenge("GameCenter");
MSDKGame::ShowChallenge("GameCenter");

2.8 发送挑战

1)功能描述

向游戏好友发送挑战。

2)接口声明

C#
C++
public static void SendChallenge(int type, string challengeID, double count, string message="", string channel="", string extraJson="")
public static void SendChallenge(int type, const String &challengeID, double count, const String &message = "", const String &channel = "", const String &extraJson = "")

3)入参说明

参数名称 参数类型 说明
type int 挑战类型,1:分数挑战,2:成就挑战
challengeID string type=1 时为 learderboard ID,type=2 时为 achievement ID
count double type=1 时为排行榜分数,type=2 时为成就完成百分比
message string 挑战信息
channel string 渠道,仅 GameCenter 支持
extraJson string 扩展字段

4)示例代码

C#
C++
MSDKGame.SendChallenge(type, challengeID, count, message, "GameCenter");
MSDKGame::SendChallenge(type, challengeID, count, message, "GameCenter");



Copyright © 2025 MSDK.
All rights reserved.

results matching ""

    No results matching ""