ドキュメント

​
​

Development

User Acquisition

Monetization

産業

Cloud Code

Open Unity Dashboard

Cloud Code

LiveOps
​
​
Cloud Code
  • Overview
  • Get started
  • Server authority
  • Cloud Code C# modules
    • Overview
    • Get started
    • Concepts
    • Tutorials
      • Run modules
      • Write modules
      • Development essentials
      • Automate deployment
      • Integrate services
        • Integrate with other Unity Services
        • Interact with cross-player data
        • Integrate with external services
        • Use Access Control
        • Send push messages
      • Advanced configuration
      • Use Cases
    • Reference
  • Cloud Code JavaScript scripts
  • Logging
  • Use-case samples
  • Privacy and consent
  1. Cloud Code

外部サービスとのインテグレーション

Extend Cloud Code modules with external services using NuGet packages or HTTP clients.
読み終わるまでの所要時間 4 分
最終更新 9ヶ月前

Cloud Code モジュールを外部サービスと統合できます。
カスタムデータ型を処理するには、カスタム JSON シリアル化 を実装します。

NuGet パッケージの使用

Cloud Code モジュールは .NET エコシステム内でライブになる C# ライブラリプロジェクトであるため、NuGet パッケージマネージャー を使用して依存関係をインストールします。これは、任意の外部 NuGet パッケージを Cloud Code モジュール内で使用できることを意味します。
使用可能な NuGet パッケージを表示するには、NuGet パッケージライブラリ を参照してください。

外部 API の呼び出し

任意の外部 API を呼び出すこともできます。以下のサンプルは、Cat Facts API を呼び出してランダムなネコの豆知識を取得します。
  1. CatFactsApi
    クラスを宣言して API 呼び出しを処理します。
    using Newtonsoft.Json;using RestSharp;using Unity.Services.CloudCode.Core;using Unity.Services.CloudCode.Shared;namespace CatFacts;public interface ICatFactsApi{ public Task<CatFactsApiResponse?> GetCatFact();}public class CatFactsApiResponse{ public string fact { get; set; } public int length { get; set; }}public class CatFactsApi : ICatFactsApi{ private readonly RestClient _httpClient; public CatFactsApi() { // It's important to only create one RestClient per service in order to avoid creating and destroying too many network connections which could hurt performance _httpClient = new RestClient("https://catfact.ninja/fact"); } public async Task<CatFactsApiResponse?> GetCatFact() { var request = new RestRequest(); try { var res = await _httpClient.ExecuteGetAsync(request); return JsonConvert.DeserializeObject<CatFactsApiResponse?>(res.Content); } catch (ApiException e) { throw new Exception($"Failed to get cat fact: {e.Message}"); } }}
  2. CatFactsApi
    クラスを
    ModuleConfig
    クラス内のシングルトンとして宣言します。
    public class ModuleConfig : ICloudCodeSetup { public void Setup(ICloudCodeConfig config) { config.Dependencies.AddSingleton<ICatFactsApi>(new CatFactsApi()); } }
  3. CatFactsApi
    クラスの
    GetCatFact
    メソッドを呼び出す
    GetCatFact
    関数を宣言します。
    using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Logging;using Unity.Services.CloudCode.Core;using Unity.Services.CloudCode.Shared;namespace CatFacts;public class CatFactsSample{ private static ILogger<CatFactsSample> _logger; public CatFactsSample(ILogger<CatFactsSample> logger) { _logger = logger; } [CloudCodeFunction("GetCatFact")] public async Task<CatFactsApiResponse?> GetCatFact(ICatFactsApi catFactsApi) { try { var fact = await catFactsApi.GetCatFact(); _logger.LogInformation("Cat fact: {fact}", fact?.fact); return fact; } catch (ApiException e) { _logger.LogError("Failed to get cat fact. Error: {Error}", e.Message); throw new Exception($"Failed to get cat fact: {e.Message}"); } } public class ModuleConfig : ICloudCodeSetup { public void Setup(ICloudCodeConfig config) { config.Dependencies.AddSingleton<ICatFactsApi>(new CatFactsApi()); } }}
  4. ゲームクライアントから
    GetCatFact
    関数を呼び出します。関数は、ランダムなネコの豆知識を返します。
    { "output": { "fact": "The Amur leopard is one of the most endangered animals in the world.", "length": 68 }}
Unity サービスと統合する方法の詳細については、他の Unity サービスとのインテグレーション を参照してください。

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

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

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

  • このページ
    • NuGet パッケージの使用

    • 外部 API の呼び出し


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