すべてを統合する - 全期間のリーダーボード - (Unity モジュール)
Last updated on February 4, 2026
注釈:本資料はAI技術を用いて翻訳されています。
リーダーボードランキングを表示するための UI の接続
-
LeaderboardAllTimeMenu_Starterクラスを開き、作成したラッパーを保存する変数を定義します。private LeaderboardEssentialsWrapper_Starter leaderboardWrapper; -
次に、
OnEnable()関数を以下のコードに置き換えます。これはLeaderboardEssentialsWrapper_Starterクラスを使用してラッパーを初期化し、ラッパーが有効な場合にのみランキングリストを表示します。private void OnEnable()
{
leaderboardWrapper ??= TutorialModuleManager.Instance.GetModuleClass<LeaderboardEssentialsWrapper_Starter>();
if (leaderboardWrapper)
{
DisplayRankingList();
}
} -
LeaderboardsMenuクラスから選択されたゲームモードに基づいてリーダーボードコードを参照する、以下のヘルパー変数を作成します。private string LeaderboardCode =>
LeaderboardEssentialsModels.GetLeaderboardCodeByGameMode(LeaderboardsMenu.SelectedGameMode); -
次に、
DisplayRankingList()関数を以下のコードで更新します。この関数はリーダーボードランキングを取得するリクエストを送信します。リストを受信した後、リーダーボードリストからすべてのプレイヤー情報(例:表示名)をクエリします。完了すると、表示するリーダーボードエントリをインスタンス化します。private void DisplayRankingList()
{
widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Loading);
leaderboardListPanel.DestroyAllChildren();
// Get leaderboard ranking list.
leaderboardWrapper.GetRankings(
LeaderboardCode,
(Result<LeaderboardRankingResult> result) =>
{
// The backend treats an empty leaderboard as an error. Therefore, display the empty state instead.
if (result.IsError || result.Value.data.Length <= 0)
{
BytewarsLogger.LogWarning($"Failed to display leaderboard rankings. Error: {result.Error.Message}");
widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Empty);
return;
}
// Query the users info in the leaderboard rankings.
UserPoint[] rankings = result.Value.data;
AccelByteSDK.GetClientRegistry().GetApi().GetUser().GetUserOtherPlatformBasicPublicInfo(
"ACCELBYTE",
result.Value.data.Select(x => x.userId).ToArray(),
(Result<AccountUserPlatformInfosResponse> usersInfoResult) =>
{
// Abort if failed to query users info.
if (usersInfoResult.IsError)
{
BytewarsLogger.LogWarning($"Failed to display leaderboard rankings. Error: {result.Error.Message}");
widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Error);
return;
}
// Generate leaderboard ranking entries.
int rankOrder = 0;
bool isCurrentPlayerInRanked = false;
Dictionary<string, AccountUserPlatformData> usersInfo = usersInfoResult.Value.Data.ToDictionary(x => x.UserId, x => x);
foreach(UserPoint ranking in rankings)
{
LeaderboardEntry entry = Instantiate(leaderboardEntryPrefab, leaderboardListPanel).GetComponent<LeaderboardEntry>();
usersInfo.TryGetValue(ranking.userId, out AccountUserPlatformData userInfo);
entry.SetRankingDetails(ranking.userId, ++rankOrder, AccelByteWarsOnlineUtility.GetDisplayName(userInfo), ranking.point);
// If the user is the current logged-in player, display the rank on the player ranking entry card.
if (ranking.userId == GameData.CachedPlayerState.PlayerId)
{
isCurrentPlayerInRanked = true;
DisplayPlayerRanking(new UserRanking()
{
rank = rankOrder,
point = ranking.point
});
}
}
// Get the logged-in player's rank if it is not included in the leaderboard.
if (!isCurrentPlayerInRanked)
{
leaderboardWrapper.GetUserRanking(
GameData.CachedPlayerState.PlayerId,
LeaderboardCode,
(Result<UserRankingDataV3> userRankResult) =>
{
// Display the leaderboard result.
DisplayPlayerRanking(userRankResult.IsError ? null : userRankResult.Value.AllTime);
widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Not_Empty);
});
return;
}
// Display the leaderboard result.
widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Not_Empty);
});
},
0, LeaderboardEssentialsModels.QueryRankingsLimit);
}
リソース
-
このチュートリアルで使用されているファイルは、Unity Byte Wars GitHub リポジトリで入手できます。