- Gamingservices - ABTestSample #2 익명 로그인2023년 02월 25일
- 개양반
- 작성자
- 2023.02.25.:17
1. 오늘 알아볼 내용
오늘은 게이밍서비스를 초기화하고 익명로그인 하는 방법에 대해 다루겠습니다.
2. GamingServices 초기화 진행
2-1 폴더 및 파일 생성
Assets\Use Case Samples\AB Test Level Difficulty\Scripts 폴더를 만듭니다.
Assets\Use Case Samples\AB Test Level Difficulty\Scripts 폴더에 ABTestLevelDifficultySceneManager.cs 파일을 만듭니다.
using System; using System.Collections.Generic; using System.Threading.Tasks; using Unity.Services.Authentication; using Unity.Services.Core; using Unity.Services.Core.Environments; using UnityEngine; namespace Unity.Services.Samples.ABTestLevelDifficulty { public class ABTestLevelDifficultySceneManager : MonoBehaviour { } }
2-2 스크립트 작성
2-2-1 ABTestLevelDifficultySceneManager.cs
GamingServices를 사용하려면 앱이 실행될 때, 한번 초기화를 진행해야 합니다. ABTestLevelDifficultySceneManager.cs 에 아래의 스크립트를 입력합니다.
// ABTestLevelDifficultySceneManager.cs async void Start() { try { await InitializeServices(); } catch (Exception e) { Debug.LogException(e); } } async Task InitializeServices() { await UnityServices.InitializeAsync(); // throw를 방지하기 위해 비동기 대기를 처리하는 동안 장면이 언로드되지 않았는지 확인합니다. if (this == null) return; Debug.Log("Initialization and signin complete."); }
2-3 오브젝트 생성과 컴포넌트 연결
Hierarchy View에 빈게임오브젝트를 만들고 이름을 ABTestLevelDifficultySample 로 변경합니다. ABTestLevelDifficultySample 오브젝트에 ABTestLevelDifficultySceneManager 스크립트를 연결합니다.
2-4 테스트
유니티 재생 버튼을 눌러 초기화가 완료되는지 확인합니다.
3. 익명 로그인
다음은 익명로그인을 구현합니다.
3-1 스크립트 작성
3-1-1 ABTestLevelDifficultySceneManager.cs
ABTestLevelDifficultySceneManager.InitializeServices 에서 초기화가 완료된 후 익명 로그인이 진행되도록 스크립트에 아래의 내용을 추가합니다.
// ABTestLevelDifficultySceneManager.cs async Task InitializeServices() { // -- 초기화 관련 코드 생략 -- // 익명로그인 요청 await SignInAnonymously(); // await 이후 this == null 을 처리해주는게 좋습니다. if (this == null) return; Debug.Log("Initialization and signin complete."); } async Task SignInAnonymously() { if (!AuthenticationService.Instance.IsSignedIn) { Debug.Log("Signing in..."); // 익명로그인 진행 await AuthenticationService.Instance.SignInAnonymouslyAsync(); if (this == null) return; Debug.Log($"Player id: {AuthenticationService.Instance.PlayerId}"); } }
3-2 테스트 진행
플레이 버튼을 눌러 테스트를 진행합니다.
Player id를 확인합니다.
유니티 대쉬보드로 이동해서 해당 id가 생성되었는지 확인합니다.
오늘은 여기까지!
제 블로그가 만족스럽다면 커피 한잔 값으로 후원을 해주실 수 있어요! 'Unity 자습서 > GamingServices' 카테고리의 다른 글
Gamingservices - ABTestSample #4 재화 만들기 (0) 2023.02.25 Gamingservices - ABTestSample #3 로그아웃과 신규 계정 생성 (0) 2023.02.25 GamingServices - ABTestSample #1 환경 세팅 (0) 2023.02.24 유니티 게이밍서비스 활성화하기 (0) 2023.02.24 다음글이전글이전 글이 없습니다.댓글