Oculus(Meta Quest)
Provide an Oculus sign-in option to enable players to authenticate using their Meta Quest accounts on virtual reality platforms.
읽는 시간 1분최근 업데이트: 한 달 전
최소 SDK 버전: 2.3.1
이 문서에서는 게임에서 Oculus 계정을 사용해 플레이어의 인증을 설정하는 다음 시나리오에 대해 설명합니다.- Oculus 로그인 설정
- 기존 사용자 로그인 또는 새 사용자 생성
- 사용자를 익명 로그인에서 커스텀 ID 제공업체를 통한 플랫폼 로그인으로 업데이트
Oculus 로그인 설정
Unity Authentication의 ID 제공업체로 Oculus를 설정하려면 다음을 따르십시오.- Unity 에디터 메뉴에서 Edit > Project Settings… 로 이동한 후, 내비게이션 메뉴에서 Services > Authentication을 선택합니다.
- ID Providers를 Oculus로 설정한 후, Add를 클릭합니다.
- App ID 텍스트 필드에 앱 ID를 입력합니다.
- App Secret 텍스트 필드에 앱 비밀 정보를 입력합니다.
- 헤드셋을 착용하고 Settings > System > Developer로 이동합니다.
- USB Connection Dialog 옵션을 활성화합니다.
- USB-C 케이블을 사용해 헤드셋을 컴퓨터에 연결합니다.
- 데이터 액세스 권한을 요청하는 창이 표시되면 Allow를 클릭합니다.
- 기기가 성공적으로 연결되었는지 확인하기 위해 Unity 프로젝트를 열고 File > Build Settings로 이동합니다. Platform 목록에서 Android를 선택하고 Switch Platform을 클릭합니다.
- Run Device 목록에서 Oculus 헤드셋을 선택합니다. 목록에 헤드셋이 없는 경우 Refresh를 클릭해 목록을 새로 고칩니다.
- 이 Oculus Integration 패키지를 설정하고 설치합니다. Oculus Developer Center에서도 패키지를 찾을 수 있습니다.
- 프로젝트에 임포트한 후, 에디터의 메뉴 바에서 Oculus > Platform > Edit Settings로 이동합니다. Oculus 앱 ID를 입력해야 합니다.
참고: Oculus 헤드셋을 개발자 모드로 설정해야 합니다. 개발자 모드로 설정하려면 개발에 사용하려는 개발자 계정으로 로그인해야 합니다. 여기에서 Oculus 개발자 계정을 생성할 수 있습니다.using UnityEngine;using Oculus.Platform;using Oculus.Platform.Models;public class OculusAuth : MonoBehaviour{ private string userId; 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 { userId = 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; // Authentication can be performed here } }}
기존 플레이어 로그인 또는 신규 플레이어 생성
SignInWithOculusAsync- Oculus 자격 증명을 사용해 새 Unity Authentication 플레이어 생성
- Oculus 자격 증명을 사용해 기존 플레이어 로그인
SignInWithOculusAsyncSignInWithOculusAsyncSignInWithOculusAsyncasync Task SignInWithOculusAsync(string nonce, string userId){ try { await AuthenticationService.Instance.SignInWithOculusAsync(nonce, userId); Debug.Log(“SignIn is successful.”); } catch (AuthenticationException ex) { // Compare error code to AuthenticationErrorCodes // Notify the player with the proper error message Debug.LogException(ex); } catch (RequestFailedException ex) { // Compare error code to CommonErrorCodes // Notify the player with the proper error message Debug.LogException(ex); }}
플레이어를 익명 로그인에서 Oculus 계정 로그인으로 업데이트
익명 인증을 설정한 후, 플레이어가 Oculus 계정을 생성하고 Oculus 계정을 통해 로그인하도록 업그레이드하려는 경우, 게임이 플레이어에게 Oculus 로그인 창을 표시하고 Oculus에서 세션 티켓을 가져와야 합니다. 그런 다음LinkWithOculusAsync- 를 사용해 캐시된 플레이어의 계정에 로그인합니다.
SignInAnonymouslyAsync - 를 사용해 캐시된 플레이어의 계정을 Oculus 계정에 연결합니다.
LinkWithOculusAsync
async Task LinkWithOculusAsync(string nonce, string userId){ try { await AuthenticationService.Instance.LinkWithOculusAsync(nonce, userId); Debug.Log(“Link is successful.”); } catch (AuthenticationException ex) when (ex.ErrorCode == AuthenticationErrorCodes.AccountAlreadyLinked) { // Prompt the player with an error message. Debug.LogError(“This user is already linked with another account. Log in instead.”); } catch (Exception ex) { Debug.LogError(“Link failed.”); Debug.LogException(ex); }}
Oculus 계정 연결 해제
플레이어가 Oculus 계정 연결을 해제할 수 있도록UnlinkOculusAsyncasync Task UnlinkOculusAsync(string idToken){ try { await AuthenticationService.Instance.UnlinkOculusAsync(idToken); Debug.Log("Unlink is successful."); } catch (AuthenticationException ex) { // Compare error code to AuthenticationErrorCodes // Notify the player with the proper error message Debug.LogException(ex); } catch (RequestFailedException ex) { // Compare error code to CommonErrorCodes // Notify the player with the proper error message Debug.LogException(ex); }}