시작 시퀀스를 처리하기 위해 서비스를 초기화합니다.
Unity Gaming Services, Authentication, In-App Purchasing을 (IAP) 초기화하여 소비자 간 직접 (D2C) 결제 제공업체와 연동할 수 있습니다.
읽는 시간 1분최근 업데이트: 10일 전
IAP의 시작 시퀀스를 처리하기 위해 UGS(Unity Gaming Services)를 초기화하는 스크립트를 생성합니다. 이 시작 스크립트는 다음을 수행할 수 있습니다.
- Unity Gaming Services를 초기화합니다.
- Authentication 이벤트 핸들러를 설정합니다.
- 로그인.
- IAP를 초기화하고 원격 카탈로그를 가져옵니다. 자세한 내용은 원격 카탈로그 페치를 참고하십시오.
초기화 스크립트에서 인스펙터에서
PurchaseManagerPurchaseManager서비스 초기화 예제 스크립트
다음 예제 스크립트의 이름은ServiceOrchestratorusing System;using System.Threading.Tasks;using Unity.Services.Authentication;using Unity.Services.Core;using UnityEngine;// Ensure you have reference to your PurchaseManager namespace if applicablepublic class ServiceOrchestrator : MonoBehaviour{ // Assign this in the Inspector public PurchaseManager purchaseManager; async void Awake() { try { { // 1. Unity Gaming Services 초기화 await Unity.Services.Core.UnityServices.InitializeAsync(); // 2. Auth 이벤트 핸들러 설정 SetupEvents(); // 3. 로그인 await SignUpAnonymouslyAsync(); // 4. IAP 초기화 및 페치 카탈로그 await purchaseManager.InitializeIAP(); } catch(기타 e) { Debug.LogException(e); } } // Setup authentication event handlers if desired void 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."); }; } // Sign in async Task SignUpAnonymouslyAsync() { try { { await AuthenticationService.Instance.SignInAnonymouslyAsync(); Debug.Log("Sign in anonymously succeeded!"); Debug.Log($"PlayerID: {AuthenticationService.Instance.PlayerId}"); } catch(AuthenticationException ex) { // Compare error code to AuthenticationErrorCodes Debug.LogException(ex); } catch(RequestFailedException ex) { // Compare error code to CommonErrorCodes Debug.LogException(ex); } }}