기술 자료

시작 시퀀스를 처리하기 위해 서비스를 초기화합니다.

Unity Gaming Services, Authentication, In-App Purchasing을 (IAP) 초기화하여 소비자 간 직접 (D2C) 결제 제공업체와 연동할 수 있습니다.
읽는 시간 2분최근 업데이트: 3달 전

IAP의 시작 시퀀스를 처리하기 위해 UGS(Unity Gaming Services)를 초기화하는 스크립트를 생성합니다. 이 시작 스크립트는 다음을 수행할 수 있습니다.
  1. Unity Gaming Services를 초기화합니다.
  2. Authentication 이벤트 핸들러를 설정합니다.
  3. 로그인.
  4. IAP를 초기화하고 원격 카탈로그를 가져옵니다. 자세한 내용은 원격 카탈로그 페치를 참고하십시오.
참고
UGS를 초기화하기 전에 환경을 설정합니다.
초기화 스크립트에서 인스펙터에서
PurchaseManager
컴포넌트를 할당해야 합니다.
PurchaseManager
컴포넌트는 다음 Remote Catalog 페치 단계의 일부로 생성됩니다.

서비스 초기화 예제 스크립트

다음 예제 스크립트의 이름은
ServiceOrchestrator
입니다.
중요
세션 토큰이 손실된 후 구매가 지속되지 않으므로 익명 로그인을 인증 방법으로 사용하지 않는 것이 좋습니다. 마찰이 없는 플랫폼별 제공자가 앱에서 실현할 수 없는 경우 애니메이션 인증 및 연결을 참조하십시오.
using 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 결제 제공업체를 설정하는 워크플로의 일부입니다. 이 워크플로를 계속하려면 다음 옵션 중 하나를 선택합니다.