ドキュメント

​
​

Development

User Acquisition

Monetization

産業

Leaderboards

Unity SDK tutorial

Open Unity Dashboard

Leaderboards

LiveOps
​
​
Leaderboards
  • Overview
  • Get started
  • Concepts
  • Tutorials
    • Configuration
    • Unity SDK tutorial
    • Unity SDK sample
    • Cloud Code samples
      • Cloud Code Modules (C#)
      • Cloud Code Script (Javascript)
  • Reference
  • Privacy and consent
  1. Leaderboards

Cloud Code C# モジュールによる Leaderboards へのアクセス

Refer to code samples that access Leaderboards with Cloud Code C# Modules.
読み終わるまでの所要時間 3 分
最終更新 8ヶ月前

Cloud Code を使用し Cloud Code C# モジュール を介することで、Leaderboards 機能にアクセスできます。
プレイヤーが Cloud Code モジュールを呼び出す例について考えてみましょう。以下のコードスニペットは、プレイヤーのスコアを送信し、そのエントリー (ランクなど) を取得し、さらにリーダーボードの上位スコアを取得します。
C#:
using Microsoft.Extensions.DependencyInjection;using Unity.Services.CloudCode.Apis;using Unity.Services.CloudCode.Core;using Unity.Services.Leaderboards.Model;public class LeaderboardsExample{ [CloudCodeFunction("LeaderboardsExample")] public async Task<LeaderboardResult> LeaderboardsExampleAsync( IExecutionContext context, IGameApiClient apiClient, string leaderboardId, string playerId, int score) { string accessToken = context.AccessToken; Guid projectId = Guid.Parse(context.ProjectId); var addScoreResult = await apiClient.Leaderboards.AddLeaderboardPlayerScoreAsync( context, accessToken, projectId, leaderboardId, playerId, new LeaderboardScore(score)); var getScoreResult = await apiClient.Leaderboards.GetLeaderboardPlayerScoreAsync( context, accessToken, projectId, leaderboardId, playerId); var getScoresResult = await apiClient.Leaderboards.GetLeaderboardScoresAsync( context, accessToken, projectId, leaderboardId); return new LeaderboardResult() { AddScoreResult = addScoreResult.StatusCode.ToString(), GetScoreResult = getScoreResult.Data, GetScoresResult = getScoresResult.Data }; }}public class LeaderboardResult{ public string AddScoreResult { get; set; } public LeaderboardEntryWithUpdatedTime GetScoreResult { get; set; } public LeaderboardScoresPage GetScoresResult { get; set; }}public class ModuleConfig : ICloudCodeSetup{ public void Setup(ICloudCodeConfig config) { config.Dependencies.AddSingleton(GameApiClient.Create()); }}
プレイヤースコープのエンドポイントへの管理レベルのアクセスも Cloud Code を介して利用可能です。これにより、複数のプレイヤーのスコアや、Cloud Code モジュールを呼び出したプレイヤー以外のプレイヤーのスコアを更新できます。これを行うには、アクセストークンの代わりに、サービストークンを Cloud Code モジュールに渡します。
C#:
public class LeaderboardsExample{ [CloudCodeFunction("LeaderboardsExample")] public async Task<LeaderboardResult> LeaderboardsExampleAsync( IExecutionContext context, IGameApiClient apiClient, string leaderboardId, string playerId, int score) { string serviceToken = context.ServiceToken; Guid projectId = Guid.Parse(context.ProjectId); var addScoreResult = await apiClient.Leaderboards.AddLeaderboardPlayerScoreAsync( context, serviceToken, projectId, leaderboardId, playerId, new LeaderboardScore(score)); var getScoreResult = await apiClient.Leaderboards.GetLeaderboardPlayerScoreAsync( context, serviceToken, projectId, leaderboardId, playerId); var getScoresResult = await apiClient.Leaderboards.GetLeaderboardScoresAsync( context, serviceToken, projectId, leaderboardId); return new LeaderboardResult() { AddScoreResult = addScoreResult.StatusCode.ToString(), GetScoreResult = getScoreResult.Data, GetScoresResult = getScoresResult.Data }; }}

追加リソース

  • Unity Dashboard
  • Cloud Code ドキュメント
  • Unity Authentication

Copyright © 2026 Unity Technologies
法規事項プライバシーポリシークッキーDocumentation Terms of Use私の個人情報を販売または共有しないプライバシーに関する選択 (クッキー設定)

"Unity" の名称、Unity のロゴ、およびその他の Unity の商標は、米国およびその他の国における Unity Technologies またはその関係会社の商標または登録商標です (詳しくはこちら)。その他の名称またはブランドは該当する所有者の商標です。

一部のページは利便性向上のため機械翻訳を使用しており、内容に不正確な表現が含まれる場合があります。内容に齟齬または不一致が生じた場合は、英語版を正本とします。

  • このページ
    • 追加リソース


このページの問題を報告する