시작 시퀀스를 처리하기 위해 서비스를 초기화합니다.
Unity Gaming Services, Authentication, In-App Purchasing을 (IAP) 초기화하여 소비자 간 직접 (D2C) 결제 제공업체와 연동할 수 있습니다.
읽는 시간 1분최근 업데이트: 한 달 전
IAP의 시작 시퀀스를 처리하기 위해 UGS(Unity Gaming Services)를 초기화하는 스크립트를 생성합니다. 이 시작 스크립트는 다음을 수행할 수 있습니다.
- Unity Gaming Services를 초기화합니다.
- Authentication 이벤트 핸들러를 설정합니다.
- 로그인.
- IAP를 초기화하고 원격 카탈로그를 가져옵니다. 자세한 내용은 원격 카탈로그 페치를 참고하십시오.
초기화 스크립트에서 인스펙터에서 컴포넌트를 할당해야 합니다. 컴포넌트는 다음 Remote Catalog 페치 단계의 일부로 생성됩니다.
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); } }}
다음 단계
이 페이지는 IAP를 사용하여 D2C 결제 제공업체를 설정하는 워크플로의 일부입니다. 이 워크플로를 계속하려면 다음 옵션 중 하나를 선택합니다.