본문 바로가기
Unity/Settings

유니티 광고 Advertisement 사용하기

by 노튜 2020. 4. 8.
728x90
반응형

 

본 글은 2019.3 version은 Advertisement 3.4.4 버전을 사용합니다. 

 

Advertisment Legacy를 사용하여 광고를 연결한다면 아래의 글에서 다룹니다. 다음 글은 아래의 설명과 같이

Advertisment Legacy 4.4.2 April 03,2023 이며, 유니티 버전은 2022.3.32f1 버전을 기준으로 작성되었습니다.

2025.01.27 - [유니티/중급] - 유니티 Advertisement Legacy

 

유니티 Advertisement Legacy

Advertisement Legacy 구현 사용된 유니티 버전은 2022.3.32f1 이며 Advertisement Legacy 4.4.2 · April 03, 2023 버전을 사용한다. 본 글에서는 연동하는 방법에 대해서는 다루지 않는다.특별히 요구되는 부분은

notyu.tistory.com

 

 

1. 3.4.4 version

Advertisement 3.4.4와 이전 버전은 다릅니다. 

3.4.4부터는 리스너를 등록하고 사용하도록 변경되었습니다.

Advertisement를 초기화에 GameID를 사용합니다.

등록한 광고 타입 (스킵, 노스킵등) PlacementId를 사용합니다.

광고 시청 결과는 등록한 리스너의 OnUnityAdsDidFinish()에서 처리합니다.

  

 

GameID는 Unity dashboard target application Setting Project settings Game Ids

PlacementID는 Unity dashboard → target application → Monetization → Placements 

 

RewardedVideo 광고는 다음과 같이 사용 가능합니다.

AdManager 구성은 개인마다 다들 수 있습니다. 

하나의 예입니다.

※자세한 사항은 아래  참고자료 Integration guid for Unity -Knowledge Base 참고해주세요. 

using System.Collections;
using UnityEngine;
using UnityEngine.Advertisements;
using System;

public class AdManager :MonoBehaviour, IUnityAdsListener
{    
    string gameId = "12345";
    string myPlacementId = "rewardedVideo";
    bool testMode = false;
    
    private void Start()
    {
        Advertisement.AddListener(this);
        Advertisement.Initialize(gameId, testMode);
    }
    
    private void OnDisable()
    {
        Advertisement.RemoveListener(this);
    }
    
    public void ShowAd()
    {
        StartCoroutine(ShowAdWhenReady());
    }

    IEnumerator ShowAdWhenReady()
    {
        while (!Advertisement.IsReady(myPlacementId))
        {
            yield return null;
        }   
        Advertisement.Show(myPlacementId);
    }
    
    #region UnityAdLister interfaces
    public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    {
        if (showResult == ShowResult.Finished) {
            // Do something here.
        }
        else if (showResult == ShowResult.Skipped)
        {
            // Do something here;
        }
        else if (showResult == ShowResult.Failed) {
            Debug.LogWarning("The ad did not fhinish due to an error");
        }
    }
    
    public void OnUnityAdsReady(string placementId)
    {
        if (placementId == myPlacementId) {
          //  Advertisement.Show(myPlacementId);
        }

    }

    public void OnUnityAdsDidError(string message)
    {
        Debug.LogError("OnUnityAdsDidError :" + message);
    }

    public void OnUnityAdsDidStart(string placementId)
    {
        if (placementId == myPlacementId)
        {
            //  Advertisement.Show(myPlacementId);
        }
    }
    
    #endregion
}

 

 

2. 3.4.2 version

 

3.4.2 버전은 ShowOptions에 Action callback 함수를 이용하였습니다.

결과는 ShowResult를 받아 광고 종료, 스킵, 에러등을 처리하였습니다. 

 

public class AdManager : MonoBehaviour {

 string myPlacementId = "12345"
  public void ShowAd(){
  StartCoroutine(ShowAdWhenReady());
  }

  IEnemerator ShowAdWhenReady(){
  while(!Advertisement.IsReady(myPlacementId)){
  	yield return null;
  }

   ShowOptions options = new ShowOptions { resultCallback = HadleShowResult};

   Advertisement.Show(myPlacementId, options);    
  }

  private void HandleShowResult(ShowResult result)
  {
      swith(result){
      case ShowResult.Finished: 
      //Code here 
      Debug.Log("The ad was successfully Shown."); break;
      case ShowResult.Skipped: 
      // Code here 
      Debug.Log("The ad was skipped before reaching the end."); break;
      case ShowResult.Failed: Debug.Log("The ad failed to be shown."); break;
      }
 }
}

 

3. 3.4.4 verison 발생가능한 오류

 

https://notyu.tistory.com/20

 

유니티 광고 오류

2019.3.10f1 버전 이후 발생할 수 있는 오류 유니티 광고 API가 업데이트되었습니다. 새 버전에서는 리스너를 등록하고, Advertisement를 컨트롤하도록 구성되어있습니다. 광고를 컨트롤하는 class가 연결된 Objec..

notyu.tistory.com

 

References

[1] Integration guide for Unity

https://unityads.unity3d.com/help/unity/integration-guide-unity?_ga=2.73117395.1507809706.1587192431-568278560.1586929562

 

Integration guide for Unity - Knowledge base

Integration guide for Unity Overview This guide covers integration for implementing Unity Ads in your made-with-Unity game. If you are an iOS developer using Objective-C, click here. If you are an Android developer using Java, click here. Click here for th

unityads.unity3d.com

 

728x90
반응형