サーバー主導型のプレイヤー統計データを実装する
Last updated on February 4, 2026
注釈:本資料はAI技術を用いて翻訳されています。
概要
サーバー主導型の統計データは、マルチプレイヤー競技ゲーム、またはゲーム用に専用ゲームサーバーが実行されている場合に適しています。これにより、ゲームクライアントから統計データの更新を維持する代わりに、ゲームサーバーからサーバー主導型のアクションを実行できます。
使用例には以下が含まれます:
目標
- AccelByte Unreal および Unity サーバー SDK を使用して主導型統計データを管理する方法を学ぶ。
前提条件
- 統計設定に精通していること
- AccelByte 管理者ポータルへのアクセス
- AccelByte Unreal または Unity SDK へのアクセス
- 参考用の AccelByte 統計データ API ドキュメントへのアクセス
サーバーからの統計データの使用
管理者ポータルで統計データが設定されたら、このセクションで説明されている例を使用して、サーバーから直接使用できます。
プレイヤーとゲーム全体のグローバル統計データの追跡で説明されているように、サポートされている複数の更新方法を利用することもできます。
サーバーからの統計データの更新
サーバーからの更新機能は、クライアントと同様に機能します。クライアント側の更新は、プレイヤーとゲーム全体のグローバル統計データの追跡から確認することもできます。
サーバー SDK 機能を使用するには、以下のスニペットを参照してください:
- Unreal
- Unity
Unreal Engine
FServerApiClientPtr ApiServer = AccelByteOnlineSubsystemPtr->GetServerApiClient();
FString UserId = "Player User Id";
FString AdditionalKey = " Your additional key";
FAccelByteModelsUpdateUserStatItemWithStatCode UserStatItem{};
UserStatItem.StatCode = " Your stat code ";
UserStatItem.UpdateStrategy = EAccelByteStatisticUpdateStrategy::OVERRIDE;
UserStatItem.Value = 100.0f;
TArray<FAccelByteModelsUpdateUserStatItemWithStatCode> BulkUpdateUserStatItems = { UserStatItem };
ApiServer->ServerStatistic.BulkUpdateUserStatItemValue(UserId
, AdditionalKey
, BulkUpdateUserStatItems
, THandler<TArray<FAccelByteModelsUpdateUserStatItemsResponse>>::CreateLambda([](TArray<FAccelByteModelsUpdateUserStatItemsResponse> Result)
{
// Do something if BulkUpdateUserStatItemValue is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if BulkUpdateUserStatItemValue has an error
}));
Unity
ServerStatistic serverStatistic = AccelByteSDK.GetServerRegistry().GetApi().GetStatistic();
string additionalKey = " Your additional key";
string userId = "Player User Id";
StatItemUpdate userStatItem = new StatItemUpdate
{
statCode = " Your stat code ",
updateStrategy = StatisticUpdateStrategy.OVERRIDE,
value = 100
};
StatItemUpdate[] bulkUpdateUserStatItems = { userStatItem };
serverStatistic.UpdateUserStatItems(userId, additionalKey, bulkUpdateUserStatItems, result =>
{
if (result.IsError)
{
// Do something if UpdateUserStatItems an error
Debug.Log($"Error UpdateUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if UpdateUserStatItems is successful
});
サーバーからのユーザー統計データの取得
サーバーからのユーザー統計データの取得も、クライアントと同様に機能します。これは、サーバーから追加のロジック、計算、または処理を実装する場合に便利です。
サーバー SDK 機能を使用するには、以下のスニペットを参照してください:
- Unreal
- Unity
Unreal Engine
FServerApiClientPtr ApiServer = AccelByteOnlineSubsystemPtr->GetServerApiClient();
FString UserId = "Player User Id";
TArray<FString> StatCodes = { "Stat Code 1", "Stat Code 2" };
TArray<FString> Tags = { "Tag 1", "Tag 2", "Tag 3" };
ApiServer->ServerStatistic.GetUserStatItems(UserId
, StatCodes
, Tags
, THandler<FAccelByteModelsUserStatItemPagingSlicedResult>::CreateLambda([](FAccelByteModelsUserStatItemPagingSlicedResult Result)
{
// Do something if GetUserStatItems is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if GetUserStatItems has an error
}));
Unity
ServerStatistic serverStatistic = AccelByteSDK.GetServerRegistry().GetApi().GetStatistic();
string userId = "Player User Id";
string[] statCodes = { "Stat Code 1", "Stat Code 2" };
string[] tags = { "Tag 1", "Tag 2", "Tag 3" };
serverStatistic.GetUserStatItems(userId, statCodes, tags, result =>
{
if (result.IsError)
{
// Do something if GetUserStatItems an error
Debug.Log($"Error GetUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if GetUserStatItems is successful
});