ゲームの統計情報

このドキュメントでは、C++ ゲームで Google Play Games サービスのゲームの統計データを使用する方法について説明します。このドキュメントは、Google Play Games サービスをセットアップするで説明されているとおりにプロジェクトをセットアップしていることを前提としています。ゲームの統計データ API は PgsGameStatsClient にあります。

始める前に

ゲームの統計データのゲーム コンセプトをまだ確認されていない場合は、確認することをおすすめします。

Game Stats API を使用してコーディングを開始する前に:

ゲームの統計データ クライアントを取得する

実績 API の使用を開始するには、まず PgsGameStatsClient オブジェクトを取得する必要があります。そのためには、PgsPlayerGameEvent_create メソッドを呼び出してアクティビティを渡します。

クライアントサイドの統合

PlayerGameEvent のクライアントサイド統合では、トリガー ポイントで C++ SDK でイベント オブジェクトを構築し、SDK が提供するアップロード関数を使用して送信する必要があります。

同様に、progressUpdate イベントでは、currentProgress プロパティと追加の定義済みプロパティを使用して更新された進行状況を記録し、SDK が提供するアップロード関数を使用して送信します。

イベント

PlayerGameEvent のクライアントサイドの統合は次のとおりです。

Build Player Game Event

C++


// Build the PlayerGameEvent
PgsPlayerGameEvent* player_event = PgsPlayerGameEvent_create("matchCompleted");
if (player_event != nullptr) {
   PgsPlayerGameEvent_putString(player_event, "matchId", "Match_A");
   PgsPlayerGameEvent_putString(player_event, "gameMode", "Battle_B");
   PgsPlayerGameEvent_putString(player_event, "mapId", "Location_XYZ");
   PgsPlayerGameEvent_putBoolean(player_event, "isWinner", true);
   PgsPlayerGameEvent_putLong(player_event, "playerElimination", 2);
}
progressUpdate プレーヤー ゲームイベントをビルドする

C++


PgsPlayerGameEvent* progress_event = PgsPlayerGameEvent_create("progressUpdate");
if (progress_event != nullptr) {
   PgsPlayerGameEvent_putLong(progress_event, "currentProgress", 52);
}
Record Event And Upload

C++


// Record the event
PgsGameStatsClient_recordEvent(client, player_event);

// This submits the events to PGS
PgsGameStatsClient_requestEventsUpload(client);

// Clean up handle to avoid leaks
PgsPlayerGameEvent_destroy(player_event);

// Clean up client handle when PGS operations are finished
PgsGameStatsClient_destroy(client);