Unity IAP ์ด๊ธฐํ
Unity IAP ํจํค์ง๋ฅผ ์ด๊ธฐํํ๊ณ , ํ์ ์ค์ ์ ๊ตฌ์ฑํ๊ณ , ์ง์๋๋ ํ๋ซํผ ์ธ์ฑ ๊ตฌ๋งค ์ฒ๋ฆฌ๋ฅผ ์์ํ๊ธฐ ์ํ ์ค์ ์ ๊ฒ์ฆํ๋ ๋ฐฉ๋ฒ์ ์์๋ด
๋๋ค.
์ฝ๋ ์๊ฐ 2๋ถ์ต๊ทผ ์
๋ฐ์ดํธ: 11์ผ ์
Unity IAP(์ธ์ฑ ๊ตฌ๋งค)๋ฅผ ์ฌ์ฉํ๊ธฐ ์ ์ IAP ํจํค์ง๋ฅผ ์ด๊ธฐํํฉ๋๋ค.
ํ๋ก์ ํธ์์ Unity ์ ๋๋ฆฌํฑ์ค ๋๋ Unity Authentication์ ์ฌ์ฉํ๋ ค๋ฉด IAP๋ฅผ ์ด๊ธฐํํ๊ธฐ ์ ์ ๋จผ์ UGS(Unity Gaming Services)๋ฅผ ์ด๊ธฐํํด์ผ ํฉ๋๋ค. ์ฌ์ฉ ๋ฐฉ๋ฒ์ ์๋์ Unity Gaming Services ์ด๊ธฐํ ์น์
์ ์ฐธ์กฐํ์ญ์์ค.
Unity Gaming Services ์ด๊ธฐํ
๋ชจ๋ Unity Gaming Services๋ฅผ ์ด๊ธฐํํ๋ ค๋ฉดUnityServices.InitializeAsync()Task์ธ์ฑ ๊ตฌ๋งค ์ด๊ธฐํ
ํ์ ์กฐ๊ฑด
๊ตฌ๋งคํ ์ ํ์ ์๋ํฐ ์นดํ๋ก๊ทธ ๋ง๋ค๊ธฐ์ ๋จ๊ณ๋ฅผ ์๋ฃํฉ๋๋ค.์ด๊ธฐํ ๋จ๊ณ
์ด๊ธฐํ๋ ๋ค์ ๋จ๊ณ๋ก ๊ตฌ์ฑ๋ฉ๋๋ค.- ์ฑ ์คํ ์ด์ ๋ํ ์ป๊ธฐ.
StoreController - ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ฅผ ์ ์ฐ๊ฒฐํฉ๋๋ค.
StoreController - ์ฑ ์คํ ์ด ์ฐ๊ฒฐํฉ๋๋ค.
- ์ฑ ์คํ ์ด ์ํ์ ๊ฐ์ ธ์ค๋ ๊ฒฝ์ฐ
- ์ฑ ์คํ ์ด ๊ตฌ๋งค๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
using System.Collections.Generic;using UnityEngine.Purchasing;public class MyIAPManager{ private StoreController m_StoreController; public MyIAPManager() { // Define products var catalogProvider = new CatalogProvider(); catalogProvider.AddProduct("100_gold_coins", ProductType.Consumable, new StoreSpecificIds() { {"100_gold_coins_google", GooglePlay.Name}, {"100_gold_coins_mac", MacAppStore.Name} }); // Get StoreController m_StoreController = UnityIAPServices.StoreController(); // Add event listeners m_StoreController.OnStoreDisconnected += OnStoreDisconnected; m_StoreController.OnProductsFetched += OnProductsFetched; m_StoreController.OnProductsFetchFailed += OnProductsFetchFailed; m_StoreController.OnPurchasesFetched += OnPurchasesFetched; m_StoreController.OnPurchasesFetchFailed += OnPurchasesFetchFailed; // Connect to store m_StoreController.Connect().ContinueWith(_ => { // Fetch products from store catalogProvider.FetchProducts( list => m_StoreController.FetchProducts(list) ); }); } /// <summary> /// Invoked when connection is lost to the current store, or on a Connect() failure. /// </summary> /// <param name="failure">Information regarding the failure.</param> private void OnStoreDisconnected(StoreConnectionFailureDescription ์คํจ) { } /// <summary> /// Invoked with products that are successfully fetched. /// </summary> /// <param name="products">Products successfully returned from the app store.</param> private void OnProductsFetched(์ ํ ๋ชฉ๋ก<Product>) { // Fetch purchases for successfully retrieved products m_StoreController.FetchPurchases(); } /// <summary> /// Invoked when an attempt to fetch products has failed or when a subset of products failed to be fetched. /// </summary> /// <param name="failure">Information regarding the failure.</param> private void OnProductsFetchFailed(ProductFetchFailed ์คํจ) { } /// <summary> /// Invoked when previous purchases are fetched. /// </summary> /// <param name="orders">All active pending, completed, and deferred orders for previously fetched products.</param> private void OnPurchasesFetched(์ ๋ ฌ ์ฃผ๋ฌธ) { } /// <summary> /// Invoked when an attempt to fetch previous purchases has failed. /// </summary> /// <param name="failure">Information regarding the failure.</param> private void OnPurchasesFetchFailed(PurchasesFetchFailureDescription ์คํจ) { } /// <summary> /// Invoked when a purchase needs to be processed and fulfilled. /// </summary> /// <param name="order">The order awaiting fulfillment.</param> private void OnPurchasePending(PendingOrder ์์) { }}
StoreController ๊ฐ์ ธ์ค๊ธฐ
StoreControllerStoreControllerStoreController์ ์ด๋ฒคํธ ํธ๋ค๋ฌ ์ฐ๊ฒฐ
์คํ ์ด๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์๋ํ๋ ค๋ฉด ๋ค์ ์ด๋ฒคํธ์ ํธ๋ค๋ฌ๋ฅผ ์ฐ๊ฒฐํฉ๋๋ค.- OnStoreDisconnected
- OnProductsFetched
- OnProductsFetchFailed
- OnPurchasesFetched
- OnPurchasesFetchFailed
- OnPurchasePending
StoreController์ฑ ์คํ ์ด ์ฐ๊ฒฐ
์ฑ ์คํ ์ด์ ์ฐ๊ฒฐํ๋ ค๋ฉด StoreController.Connect๋ฅผ ํธ์ถํฉ๋๋ค. ์ฐ๊ฒฐ์ด ์๋ฃ๋๊ฑฐ๋ ์คํจํ๋ฉด ๋ฐํ๋TaskOnStoreDisconnected์ํ ํ์น
์ ํ์ ๊ตฌ๋งคํ ์ ์๋์ง ํ์ธํ๋ ค๋ฉด StoreController.FetchProducts์ ๋ฌธ์ํ์ญ์์ค. ์ฑ๊ณตํ๋ฉด ์ฑ๊ณต์ ์ผ๋ก ๋ฐํ๋ ์ ํ ๋ชฉ๋ก๊ณผ ํจ๊ป
OnProductsFetchedOnProductsFetchFailedFetchProductsFetchProductsFetchProductsOnPurchasePendingGetProducts(์ ํ)
GetProductsFetchProductsFetchProductsFetchProductsGetProducts๊ตฌ๋งค ํ์น
StoreController.FetchPurchasesPendingOrdersConfirmedOrdersDeferredOrdersFetchPurchasesOnPurchasesFetchedOnPurchasesFetchFailedOrdersOnPurchasePending์คํ๋ผ์ธ ๊ตฌ๋งค ํ์น
Apple์ StoreKit 2์ ๊ฐ์ ์ผ๋ถ ํ๋ซํผ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ์ ํ ๋ฐ์ดํฐ๋ฅผ ์บ์ฑํ์ง ์๊ณ ๋ ์คํ๋ผ์ธ ์ก์ธ์ค ๊ถํ์ ๊ธฐ๊ธฐ์ ์บ์ฑํฉ๋๋ค. ์ด ์ ๊ทผ ๋ฐฉ์์ ๊ถ์ฅ๋์ง ์์ง๋งOnProductsFetchFailedFetchPurchasesFetchPurchasesProductType.UnknowntypeProductDefinition.idProductDefinition.storeSpecificIdGetPurchases(๊ตฌ๋งค)
GetPurchasesFetchPurchasesFetchPurchasesGetProductsFetchProductsFetchPurchasesGetPurchases