Version: 2017.3
IAP Promo
IAP 프로모션 플레이스먼트

IAP Promo 통합

Unity 에디터에서 프로젝트 준비

Unity 서비스 설정

IAP Promo를 사용하려면 다음 단계를 거쳐야 합니다.

  1. 프로젝트를 Unity 서비스에 사용할 수 있도록 설정.
  2. 프로젝트에서 Unity IAP와 Unity 애즈를 활성화합니다.

Unity IAP 설정

IAP Promo에는 지원되는 Unity IAP SDK 버전(1.17 이상)이 필요합니다. 최신 IAP SDK를 받으려면 In-App Purchasing 를 서비스 창(Window > Services)에서 활성화하거나 에셋 스토어에서 임포트합니다. 서비스 창에서 활성화하는 경우 표시되는 메시지에 따라 에셋 패키지를 임포트해야 합니다.

에디터의 서비스 창에서 Unity IAP 활성화
에디터의 서비스 창에서 Unity IAP 활성화

자세한 내용은 IAP 설정 문서를 참조하십시오.

Unity 애즈 설정

IAP Promo에는 지원되는 Unity 애즈 SDK 버전(2.2 이상)이 필요합니다. 최신 Ads SDK를 받으려면 에셋 스토어에서 임포트하십시오. 그러면 Unity 애즈를 프로젝트에 사용할 수 있습니다.

자세한 내용은 Unity 애즈 설정을 참조하십시오.

구현

필요한 서비스를 설정한 후 게임에서 구현할 수 있습니다.

IAP 구현

Promotions 를 사용하려면 Unity 애즈를 초기화하기 전에 IAP를 초기화해야 합니다. 초기화 옵션으로는 코드리스 또는 스크립팅의 두 가지를 사용할 수 있습니다.

코드리스 IAP 사용

코드리스 IAP를 선택하면 초기화가 자동으로 처리됩니다. 코드리스 IAP를 사용하려면 Product Catalog 를 채운 다음 해당 카탈로그를 페치할 IAP Listener 를 생성합니다.

코드리스 Product Catalog 를 채우는 방법:

  1. 에디터에서 Window > UnityIAP > IAP Catalog를 선택하여 IAP Catalog 창을 엽니다. 이 창에는 이전에 설정한 제품이 모두 나열됩니다. 이때 Product Catalog 에 하나 이상의 Product 가 설정되어 있어야 합니다. Products 설정에 대한 전체 설명은 코드리스 IAP를 참조하십시오.

  2. IAP Catalog 창에서 App Store Export > Cloud JSON을 선택하여 Product Catalog 의 로컬 복사본을 익스포트합니다.

IAP 제품 카탈로그를 JSON으로 익스포트
IAP 제품 카탈로그를 JSON으로 익스포트

다음, IAP Listener 를 생성합니다. Window > Unity IAP > Create IAP Listener를 선택한 후 게임의 첫 번째 씬에 추가합니다. 게임이 부팅되는 즉시 리스너가 Product Catalog 를 페치합니다. 따라서 게임에서 Promotions 를 요청할 때 씬에 코드리스 버튼이 아직 표시되지 않아 Product 가 준비되지 않는 오류가 발생하지 않습니다.

스크립팅 사용

스크립트를 통해 Unity IAP를 수동으로 초기화하는 경우 아래 코드 예시와 같이 로직을 추가하여 IAP가 항상 Unity 애즈보다 먼저 초기화되도록 할 수 있습니다.

using System.Collections;
using System.Collections.Generic;

using UnityEngine;
using UnityEngine.Advertisements;
using UnityEngine.Events;
using UnityEngine.Purchasing;
using UnityEngine.UI;

[RequireComponent(typeof(AdsManager))]
public class UnityIAP : MonoBehaviour, IStoreListener
{
    private IStoreController controller;
    private AdsManager ads;

    private const string product_coins = "100.gold.coins";
    private const string product_hat = "top_hat";
    private const string product_elite = "elite_status";
    private const string product_bundle = "gem_super_box";
    public int coin_count = 0;
    public int gems_count = 0;
    public bool hat_owned = false;
    public bool elite_member = false;


    private void Awake()
    {
        this.ads = GetComponent<AdsManager>();
        // Where AdsManager is your Ads initialization script
    }

    private void Start()
    {
        Debug.Log("UnityIAP.Init()");

        // var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());

        StandardPurchasingModule module = StandardPurchasingModule.Instance();
        ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog();
        ConfigurationBuilder builder = ConfigurationBuilder.Instance(module);
        IAPConfigurationHelper.PopulateConfigurationBuilder(ref builder, catalog);

        UnityPurchasing.Initialize(this, builder);
    }

    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        Debug.Log("UnityIAP.OnInitialized(...)");
        this.controller = controller;

        this.ads.Init();
        // Where Init() is your method to initialize Unity 애즈
    }

    public void OnInitializeFailed(InitializationFailureReason error)
    {
        Debug.Log("UnityIAP.OnInitializeFailed(" + error + ")");

        this.ads.Init();
        // In case IAP initialization fails, you may still want to initialize Ads
    }

    public void Buy(string productId)
    {
        Debug.Log("UnityIAP.BuyClicked(" + productId + ")");
        this.controller.InitiatePurchase(productId);
    }

    public void OnPurchaseFailed(Product item, PurchaseFailureReason r)
    {
        Debug.Log("UnityIAP.OnPurchaseFailed(" + item + ", " + r + ")");
    }

    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    {
        string purchasedItem = e.purchasedProduct.definition.id;

        switch (purchasedItem)
        {
            case product_coins:
                Debug.Log("IAPLog: Congratualtions you are richer!");
                coin_count += 100;
                Debug.Log("IAPLog: Coin count: " + coin_count);
                break;

            case product_hat:
                hat_owned = true;
                Button topHatButton = GameObject.Find("buyTopHat").GetComponent<Button>();
                topHatButton.interactable = false;
                topHatButton.GetComponentInChildren<Text>().text = "That hat is dashing!";
                Debug.Log("IAPLog: Hat owned: " + hat_owned);
                break;

            case product_elite:
                elite_member = true;
                Button eliteButton = GameObject.Find("buyElite").GetComponent<Button>();
                eliteButton.interactable = false;
                eliteButton.GetComponentInChildren<Text>().text = "Welcome to Elite Status";
                Debug.Log("IAPLog: Elite member: " + elite_member);
                break;
            case product_bundle:
                gems_count += 5000;
                break;
        }

        return PurchaseProcessingResult.Complete;
    }
}

Unity 애즈 구현

IAP 초기화 스크립트의 OnInitialized() 콜백 메서드 안에서 Unity 애즈를 초기화하면 올바른 초기화 순서가 유지됩니다. 이 코드 샘플은 호출할 Unity 애즈 초기화 메서드의 예입니다.

using System.Collections;
using System.Collections.Generic;

using UnityEngine;
using UnityEngine.Advertisements;
using UnityEngine.Events;
using UnityEngine.Purchasing;
using UnityEngine.UI;

public class AdsManager : MonoBehaviour
{
    #if UNITY_IOS
        private string gameId = "0000000"; // Your iOS game ID here
    #elif UNITY_ANDROID
        private string gameId = "9999999"; // Your Android game ID here
    #else
        private string gameId = "0123456"; // Prevents Editor Errors
    #endif

    public void Init()
    {
        Debug.Log("UnityAds.Init()");
        if (!Advertisement.isSupported || Advertisement.isInitialized)
        {
            Debug.Log("Could not initialize ads");
            return;
        }

        Debug.Log("Initializing Unity 애즈 with game ID: " + gameId);
        Advertisement.Initialize(gameId, false);
    }

    public void ShowAdUnit()
    {
        Debug.Log("Unity 애즈 Log: Ad shown");
        Advertisement.Show("testAdButton"); // Ad Placement ID for ad here
    }

    public void ShowPromo()
    {
        Debug.Log("Unity 애즈 Log: Promo Shown");
        Advertisement.Show("testPromoButton"); // Ad Placement ID for Promo here
    }
}

참고: IAP 초기화에 코드리스 IAP를 사용하는 경우 Unity 애즈 초기화 메서드를 코드의 다른 부분에서 호출해야 합니다.

개발자 대시보드에서 프로모션 설정

개발자 대시보드의 IAP Promo 섹션으로 이동하여 IAP Promo 제안을 설정합니다.

  • Placements를 사용하여 Promotions 가 게임 안에 표시되는 시기와 방법을 설정합니다.
  • Products 인터페이스를 사용하여 Product Catalog 를 임포트하고 각 Product의 크리에이티브 에셋을 관리합니다.
  • 프로모션에 포함되는 PlacementsProducts 와 프로모션의 타겟 사용자 같은 Promotions 파라미터를 정의합니다.

통합 테스트

다음 코드 예제를 구현하여 IAP Promo 콘텐츠를 호출합니다.

public void ShowPromo()
{
    Advertisement.Show (placementID);
}

에디터에서 Play를 눌러 Placement 에서 요청할 때 테스트 광고가 표시되는지 확인합니다. 실제 프로모션 크리에이티브 에셋을 보려면 제작 모드에서 게임을 디바이스에 빌드해야 합니다.




IAP Promo
IAP 프로모션 플레이스먼트