メインコンテンツまでスキップ

すべてを統合する - 毎週のリーダーボード - (Unity モジュール)

Last updated on February 4, 2026

注釈:本資料はAI技術を用いて翻訳されています。

定期的なリーダーボードランキングを表示するためにUIを接続する

  1. PeriodicLeaderboardMenu_Starter クラスを開き、作成したラッパーを保存する変数を定義します。

    private PeriodicLeaderboardWrapper_Starter periodicLeaderboard;
  2. 次に、OnEnable() 関数を以下のコードに置き換えます。これは PeriodicLeaderboardWrapper_Starter クラスを使用してラッパーを初期化し、ラッパーが有効な場合にのみランキングリストを表示します。

    private void OnEnable()
    {
    periodicLeaderboard ??= TutorialModuleManager.Instance.GetModuleClass<PeriodicLeaderboardWrapper_Starter>();
    if (periodicLeaderboard)
    {
    DisplayRankingList();
    }
    }
  3. LeaderboardsMenu クラスから選択されたゲームモードと、LeaderboardPeriodMenu クラスから選択された期間に基づいてリーダーボードコードを参照するヘルパー変数を作成します。

    private string LeaderboardCode => 
    LeaderboardEssentialsModels.GetLeaderboardCodeByGameMode(LeaderboardsMenu.SelectedGameMode);
    private string PeriodName =>
    LeaderboardEssentialsModels.GetFormattedLeaderboardPeriod(LeaderboardPeriodMenu.SelectedPeriod);
  4. 次に、DisplayRankingList() 関数を以下のコードで更新します。この関数は、選択された期間に基づいて統計サイクル設定を取得するリクエストを送信します。次に、その設定からサイクルIDを使用して定期的なリーダーボードランキングを取得するリクエストを送信します。リストを受信した後、リーダーボードリストからすべてのプレイヤー情報(例:表示名)をクエリします。完了すると、表示するリーダーボードエントリをインスタンス化します。

    private void DisplayRankingList()
    {
    widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Loading);
    leaderboardListPanel.DestroyAllChildren();

    // Get statistics cycle config by selected period.
    periodicLeaderboard.GetStatCycleConfigByName(PeriodName, (result) =>
    {
    // Abort if the period is not found.
    if (result.IsError)
    {
    BytewarsLogger.LogWarning($"Failed to display leaderboard rankings. Error: {result.Error.Message}");
    widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Error);
    return;
    }

    // Get leaderboard ranking list by statistics cycle.
    string cycleId = result.Value.Id;
    periodicLeaderboard.GetRankingsByCycle(
    LeaderboardCode,
    cycleId,
    (Result<LeaderboardRankingResult> rankingResult) =>
    {
    // The backend treats an empty leaderboard as an error. Therefore, display the empty state instead.
    if (rankingResult.IsError || rankingResult.Value.data.Length <= 0)
    {
    BytewarsLogger.LogWarning($"Failed to display leaderboard rankings. Error: {rankingResult.Error.Message}");
    widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Empty);
    return;
    }

    // Query the users info in the leaderboard rankings.
    UserPoint[] rankings = rankingResult.Value.data;
    AccelByteSDK.GetClientRegistry().GetApi().GetUser().GetUserOtherPlatformBasicPublicInfo(
    "ACCELBYTE",
    rankingResult.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: {rankingResult.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 UserCycleRanking()
    {
    Rank = rankOrder,
    Point = ranking.point,
    CycleId = cycleId
    });
    }
    }

    // Get the logged-in player's rank if it is not included in the leaderboard.
    if (!isCurrentPlayerInRanked)
    {
    periodicLeaderboard.GetUserRanking(
    GameData.CachedPlayerState.PlayerId,
    LeaderboardCode,
    (Result<UserRankingDataV3> userRankResult) =>
    {
    // Display the leaderboard result.
    DisplayPlayerRanking(userRankResult.IsError ? null : userRankResult.Value.Cycles.FirstOrDefault(x => x.CycleId == cycleId));
    widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Not_Empty);
    });
    return;
    }

    // Display the leaderboard result.
    widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Not_Empty);
    });
    },
    0, LeaderboardEssentialsModels.QueryRankingsLimit);
    });
    }

リソース