This document is about: PUN 2
SWITCH TO

PUN Classic (v1)、PUN 2、Boltはメンテナンスモードとなっております。Unity2022についてはPUN 2でサポートいたしますが、新機能が追加されることはありません。お客様のPUNプロジェクトおよびBoltプロジェクトが停止することはなく、将来にわたってパフォーマンス性能が落ちることはありません。 今後の新しいプロジェクトについては、Photon FusionまたはQuantumへ切り替えていただくようよろしくお願いいたします。

Photon Oculus認証

アプリケーションのセットアップ

Oculusは認証プロバイダとして簡単に追加でき、 追加はPhotonアプリケーションのダッシュボードから数秒で設定できます。

アプリケーションの「管理」ページに進み、「認証」セクションにスクロールダウンしてください。 新たな認証プロバイダをOculusに追加する場合、または既存の認証プロバイダを編集する場合には、以下の設定が必須です:

  • appid: OculusアプリケーションのIDです。
  • appsecret: Oculusアプリケーションの秘密です。

クライアントコード

Oculusはユーザーを、Oculus IDとクライアントに提供されるノンスで認証しています。 暗号法では、ノンスは1回のみ使用可能な乱数です。 詳細はこちらを参照してください。

証明書を取得

クライアントはまずOculusにログインし、ノンスを生成する必要があります。 このノンスは、そのクライアントが有効なOculusユーザーであることの証明です。

Oculus SDKはOculusのウェブサイトから取得してください。

Unityのインストラクション

Unity用のOculusプラットフォームSDKをダウンロードして、プロジェクトにインポートしてください。

エディターのメニューバーから「Oculusプラットフォーム」へ進み -> 「設定の編集」でOculus AppIDを入力してください。

以下のコードを使用してログイン済みのユーザーのOculus IDを取得し、ノンスを生成します:

C#

using UnityEngine;
using Oculus.Platform;
using Oculus.Platform.Models;

public class OculusAuth : MonoBehaviour
{
    private string oculusId;

    private void Start()
    {
        Core.AsyncInitialize().OnComplete(OnInitializationCallback);
    }

    private void OnInitializationCallback(Message<PlatformInitialize> msg)
    {
        if (msg.IsError)
        {
            Debug.LogErrorFormat("Oculus: Error during initialization. Error Message: {0}",
                msg.GetError().Message);
        }
        else
        {
            Entitlements.IsUserEntitledToApplication().OnComplete(OnIsEntitledCallback);
        }
    }

    private void OnIsEntitledCallback(Message msg)
    {
        if (msg.IsError)
        {
            Debug.LogErrorFormat("Oculus: Error verifying the user is entitled to the application. Error Message: {0}",
                msg.GetError().Message);
        }
        else
        {
            GetLoggedInUser();
        }
    }

    private void GetLoggedInUser()
    {
        Users.GetLoggedInUser().OnComplete(OnLoggedInUserCallback);
    }

    private void OnLoggedInUserCallback(Message<User> msg)
    {
        if (msg.IsError)
        {
            Debug.LogErrorFormat("Oculus: Error getting logged in user. Error Message: {0}",
                msg.GetError().Message);
        }
        else
        {
            oculusId = msg.Data.ID.ToString(); // do not use msg.Data.OculusID;
            GetUserProof();
        }
    }

    private void GetUserProof()
    {
        Users.GetUserProof().OnComplete(OnUserProofCallback);
    }

    private void OnUserProofCallback(Message<UserProof> msg)
    {
        if (msg.IsError)
        {
            Debug.LogErrorFormat("Oculus: Error getting user proof. Error Message: {0}",
                msg.GetError().Message);
        }
        else
        {
            string oculusNonce = msg.Data.Value;
            // Photon Authentication can be done here
        }
    }
}

認証

クライアントはOculus IDを送信し、それぞれのキー「userid」と「nonce」を使用して文字列パラメータであるノンスを生成する必要があります。

C#

PhotonNetwork.AuthValues = new AuthenticationValues();
PhotonNetwork.AuthValues.AuthType = CustomAuthenticationType.Oculus;
PhotonNetwork.AuthValues.AddAuthParameter("userid", oculusId);
PhotonNetwork.AuthValues.AddAuthParameter("nonce", oculusNonce);
// do not set AuthValues.Token or authentication will fail
// connect
Back to top