使用の準備
Follow this workflow to create a Unity account, link your project, and install the SDK to get started with Unity Authentication.
読み終わるまでの所要時間 1 分最終更新 4日前
Authentication を使用するには、以下を行う必要があります。
- UGS にサインアップします。
- Unity エディターのプロジェクトにダッシュボードをリンクします。
- ゲームコードに SDK をインストールします。
- SDK を初期化します。
サインアップ
Unity アカウントをお持ちでない場合は、アカウントを作成 し、新しいプロジェクトを作成 してから、Unity Gaming Services にサインアップしてください。- Unity Dashboard にサインインします。
- サイドパネルで Administration を選択します。
- 上部のバナーの Sign Up (サインアップ) を選択し、その後の指示に従います。
プロジェクトのリンク
プロジェクト ID を通じて、Unity エディター内の Unity クラウドプロジェクトにプロジェクトをリンクします。プロジェクト ID を取得するには、以下のステップに従います。-
Unity エディターメニューで、Edit (編集) > Project Settings (プロジェクト設定) > Services (サービス) タブを選択します。

- まだ Unity ID でサインインしていない場合は、新しい Unity ID を作成するか、サインインします。
- 新しいプロジェクトを作成するには、組織を選択し、Create (作成) を選択します。既存のプロジェクトにリンクするには、I already have a Unity Project ID (すでに Unity プロジェクト ID を持っています) を選択します。その後、ドロップダウンから組織とプロジェクトを選択し、Link (リンク) を選択します。
SDK のインストール
Unity の最新の Authentication パッケージをインストールするには- Unity エディターで、Window (ウィンドウ) > Package Manager (パッケージマネージャー) を開きます。
- Package Manager で、Unity Registry (Unity レジストリ) のリストビューを選択します。
- Authentication を検索するか、パッケージリスト内で見つけます。
- このパッケージを選択し、Install を選択します。
Unity Services SDK の初期化
ゲーム内で Unity Authentication を実装するには、以下のコードスニペットに従って、プロジェクトに含まれる すべての Unity Services SDK を初期化 します。using System;using Unity.Services.Core;using UnityEngine;public class InitializationExample : MonoBehaviour{ async void Awake() { try { await UnityServices.InitializeAsync(); } catch (Exception e) { Debug.LogException(e); } }}
認証イベントの登録
プレイヤーの状態に関するアップデートを受信するには、SignedInSignInFailedSignedOut// Setup authentication event handlers if desiredvoid SetupEvents() { AuthenticationService.Instance.SignedIn += () => { // Shows how to get a playerID Debug.Log($"PlayerID: {AuthenticationService.Instance.PlayerId}"); // Shows how to get an access token Debug.Log($"Access Token: {AuthenticationService.Instance.AccessToken}"); }; AuthenticationService.Instance.SignInFailed += (err) => { Debug.LogError(err); }; AuthenticationService.Instance.SignedOut += () => { Debug.Log("Player signed out."); }; AuthenticationService.Instance.Expired += () => { Debug.Log("Player session could not be refreshed and expired."); };}