이번에는 Unity 프로젝트에 AdColony SDK 연동을 해보겠습니다! (역시 매우 간단)


AdColony 홈페이지 링크 : https://www.adcolony.com

AdColony SDK 다운로드 링크 : https://github.com/AdColony/AdColony-Unity-SDK-3



위의 AdColony GitHub 링크로 가서


[Clone or download -> Download ZIP]


한 후, 다운로드 받은 애드콜로니 유니티패키지를 프로젝트에 import 합니다.





다음으로 진행하기 전에 기본적인 세팅이 필요한데요


우선 애드콜로니에 회원가입하고 로그인 합니다.


그 다음 [MONETIZATION] 탭에서 [Setup New App] 을 클릭합니다





App의 Platform과 국가, 이름


광고를 Skip 가능하게 할 지와 


13세 미만 어린이에게 지도 감독이 필요한 앱인지 여부를 체크합니다.


그리고 앱의 특성이나 출시 국가에 따라 다르겠지만 웬만한 정책위반을 피하기 위해


되도록이면 [Customize Your Ads] 부분에 정치, 종교, 성인 등의 광고 타입은 체크해제 해주는 것이 좋습니다. 


모든 세팅이 완료되면 [Create] 합니다.





아래는 광고 App의 기본적 Setup이 완료된 모습입니다.


[AdColony App ID] 는 스크립트를 작성할 때 필요하므로 잘 기억해둡니다.


하단에 디폴트로 생선된 Zone [Ad Zone #1] 이 보일텐데 Zone 세팅을 위해 클릭해줍니다.





[Zone is active] - Yes 해주고


[Zone ID] 도 [AdColony App ID]  마찬가지로 스크립트 작성에 필요하므로 잘 기억해둡니다.


Zone Name과 Creative Type을 설정해줍니다. (우리는 비디오 광고를 연동할 것이기 때문에 Video로 설정)





그 다음 [Zone Type] 을 아래와 같이 


Value Exchange/V4VC 로 설정해줍니다.


모든 설정을 마치면 [Save] 합니다.





여기까지 되었다면 다시 유니티로 돌아와서


AdColonyManager 라는 스크립트를 만들고


아래의 코드를 복사 붙여넣기 합니다.


애드콜로니 사이트에서 App 세팅할 때 보았던


[AdColony App ID] 와 [Zone ID] 를 각각 플랫폼별 id 변수에 넣어줍니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using UnityEngine;
using System.Collections.Generic;
 
public class AdColonyManager : MonoBehaviour
{
    private const string android_appId = "xxxxxxxxxxxxxxxxxxx";
    private const string android_zoneId = "xxxxxxxxxxxxxxxxxxx";
 
    private const string ios_appId = "xxxxxxxxxxxxxxxxxxx";
    private const string ios_zoneId = "xxxxxxxxxxxxxxxxxxx";
 
    private string appId = string.Empty;
    private string zoneId = string.Empty;
 
    private AdColony.InterstitialAd ad = null;
 
    void Start()
    {
        Initialize();
    }
 
    private void Initialize()
    {
#if UNITY_ANDROID
        this.appId = android_appId;
        this.zoneId = android_zoneId;
#elif UNITY_IOS
        this.appId = ios_appId;
        this.zoneId = ios_zoneId;
#endif
 
        AdColony.Ads.OnConfigurationCompleted += (List<AdColony.Zone> zones_) =>
        {
            Debug.Log("AdColony.Ads.OnConfigurationCompleted called");
 
            if (zones_ == null || zones_.Count <= 0)
            {
                Debug.Log("Configure Failed");
            }
            else
            {
                Debug.Log("Configure Succeeded.");
            }
        };
 
        AdColony.Ads.OnRequestInterstitial += (AdColony.InterstitialAd ad_) =>
        {
            Debug.Log("AdColony.Ads.OnRequestInterstitial called");
 
            ad = ad_;
 
            // to do ...
            // 광고 요청에 성공했을 때 처리
 
            ShowAd();
        };
 
        AdColony.Ads.OnRequestInterstitialFailed += () =>
        {
            Debug.Log("AdColony.Ads.OnRequestInterstitialFailed called");
 
            // to do ...
            // 광고 요청에 실패했을 때 처리
        };
 
        AdColony.Ads.OnOpened += (AdColony.InterstitialAd ad_) =>
        {
            Debug.Log("AdColony.Ads.OnOpened called");
        };
 
 
        AdColony.Ads.OnClosed += (AdColony.InterstitialAd ad_) =>
        {
            Debug.Log("AdColony.Ads.OnClosed called, expired: " + ad_.Expired);
        };
 
        AdColony.Ads.OnExpiring += (AdColony.InterstitialAd ad_) =>
        {
            Debug.Log("AdColony.Ads.OnExpiring called");
        };
 
        AdColony.Ads.OnRewardGranted += (string zoneId, bool success, string name, int amount) =>
        {
            Debug.Log(string.Format("AdColony.Ads.OnRewardGranted called\n\tzoneId: "
                + "{0}\n\tsuccess: {1}\n\tname: {2}\n\tamount: {3}",
                zoneId, success, name, amount));
 
            if (success)
            {
                // to do ...
                // 광고 시청이 완료되었을 때 처리
                // 광고 시청에 대한 보상 지급 등 ...
            }
        };
 
        AdColony.AppOptions appOptions = new AdColony.AppOptions();
        appOptions.AdOrientation = AdColony.AdOrientationType.AdColonyOrientationAll;
 
        AdColony.Ads.Configure(this.appId, appOptions, this.zoneId);
    }
 
    public void RequestAd()
    {
        Debug.Log("**** Request Ad ****");
 
        AdColony.AdOptions adOptions = new AdColony.AdOptions();
        adOptions.ShowPrePopup = false;
        adOptions.ShowPostPopup = false;
 
        AdColony.Ads.RequestInterstitialAd(this.zoneId, adOptions);
    }
 
    public void ShowAd()
    {
        Debug.Log("**** Show Ad ****");
 
        if (this.ad != null)
        {
            AdColony.Ads.ShowAd(this.ad);
        }
    }
 
}
 
cs



RequestAd() 함수로 광고 요청을 보낸 후


요청에 성공했다면 OnRequestInterstitial 콜백을 타고


ShowAd() 함수를 호출되는 구조입니다. (요청에 실패하면 OnRequestInterstitialFailed 콜백)


그리고 ShowAd() 로 광고 시청이 완료되면 


OnRewardGranted 콜백이 호출되므로 (success == true)


콜백 안에 광고 시청에 대한 보상을 지급하는 코드를 작성해주면 됩니다.



* 광고 procedure


Initialize() -> RequestAd() -> OnRequestInterstitial -> ShowAd() -> OnRewardedGranted



위와 같은 절차로 여러분의 프로젝트에 코드를 녹여주시고 


OnRequestInterstitialFailed 나 OnExpiring 등 기타 콜백함수도 입맛에 맞게 정의해주시면 되겠습니다.


참고로 AdColony는 UnityAds와 다르게 Editor 상에서는 테스트가 불가능하므로 모바일에서 테스트해보시길 바랍니다!



이번에는 Unity 프로젝트에 Unity Ads를 연동해보겠습니다. (매우 간단 주의)



우선 Unity에서 [Window -> Services] 하면 인스펙터 뷰 옆에 아래와 같은 화면이 나타나는데


Ads 항목이 OFF(디폴트)로 되어있는 것을 볼 수 있습니다.





Ads 항목을 클릭하면 아래와 같이 나오는데


토글 버튼을 눌러 비활성화되어있는 Ads를 활성화 시킵니다.





13세 미만 아이들에게 지도감독이 필요한 앱인지 여부를 설정하고 Continue 합니다.





활성화가 완료되면 아래와 같이 나옵니다.


원하는 Platform을 체크합니다.


Enable test mode를 체크하면 유니티에서 제공하는 짧은 테스트 광고영상만 송출됩니다.


(런칭 시 반드시 위 항목 체크를 해제할 것)





여기까지 완료했다면, 


using UnityEngine.Advertisements; 


를 할수있게 됩니다!


UnityAdsHelper라는 C# 스크립트를 하나 생성하고


아래의 코드를 복사해서 붙여 넣습니다.


그 다음, 빈 게임 오브젝트를 하나 생성하고 UnityAdsHelper.cs를 AddComponent 해줍니다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using UnityEngine;
using UnityEngine.Advertisements;
 
public class UnityAdsHelper : MonoBehaviour
{
    private const string android_game_id = "xxxxxxx";
    private const string ios_game_id = "xxxxxxx";
 
    private const string rewarded_video_id = "rewardedVideo";
 
    void Start()
    {
        Initialize();
    }
 
    private void Initialize()
    {
#if UNITY_ANDROID
        Advertisement.Initialize(android_game_id);
#elif UNITY_IOS
        Advertisement.Initialize(ios_game_id);
#endif
    }
 
    public void ShowRewardedAd()
    {
        if (Advertisement.IsReady(rewarded_video_id))
        {
            var options = new ShowOptions { resultCallback = HandleShowResult };
 
            Advertisement.Show(rewarded_video_id, options);
        }
    }
 
    private void HandleShowResult(ShowResult result)
    {
        switch (result)
        {
            case ShowResult.Finished:
                {
                    Debug.Log("The ad was successfully shown.");
 
             // to do ...
             // 광고 시청이 완료되었을 때 처리
 
                    break;
                }
            case ShowResult.Skipped:
                {
                    Debug.Log("The ad was skipped before reaching the end.");
 
             // to do ...
             // 광고가 스킵되었을 때 처리
 
                    break;
                }
            case ShowResult.Failed:
                {
                    Debug.LogError("The ad failed to be shown.");
 
             // to do ...
             // 광고 시청에 실패했을 때 처리
 
                    break;
                }
        }
    }
}
 
cs



위 코드는


ShowRewardedAd() 함수로 비디오 광고 송출 요청을 하고


HandleShowResult 콜백으로 요청 결과에 따라 Finished, Skipped, Failed 처리하는 구조로 되어있습니다.


* 여기서 androiod game id와 ios game id 그리고 rewarded video id가 필요한데


Services의 우측 상단에 있는 Go to Dashboard 를 누르면





아래와 같은 화면이 뜨는데


여기서 android 게임 ID와 ios 게임 ID를 확인할 수 있습니다.





UnityAdsHelper.cs의 android_game_id 변수와 ios_game_id 변수에 Game Id 숫자 7자리를 각각 넣어주시면 됩니다.


그 다음, 구글 플레이 스토어 또는 애플 앱 스토어 플랫폼을 클릭하여 Ad placements 정보를 확인합니다.





기본적으로 Video와 Rewarded Video 두 가지가 생성되어있는데


첫 번째에 있는 Video는 Skip이 가능한 광고이고


두 번째에 있는 Rewarded Video는 Skip이 불가능한 보상형 광고입니다. 


수익을 많이 내려면 당연히 Skip이 불가능한 보상형 광고를 써야겠죠?


위 스크린샷 처럼 Rewarded Video를 Enabled 하고 Default로 설정합니다. (우측에 EDIT 버튼으로 세부설정이 가능함)


그리고 Rewarded Video의 PLACEMENT ID를 복사하여


UnityAdsHelper.cs의 rewarded_video_id 변수에 넣어줍니다.



----------------------------------------------------------------------------------



자, 모든 준비가 끝났습니다!


Unity Editor에서 ShowRewardedAd()로 광고를 요청했을 때 아래와 같은 화면이 나온다면


정상적으로 연동된 것입니다.





이제 원하는 상황에 ShowRewardedAd() 함수를 호출하고 (주로 게임 오버될 때 혹은 특정 버프를 받을 때)


HandleShowResult 콜백에서 원하는 처리를 하여 마무리해줍니다. (캐릭터 부활 혹은 버프효과 적용 등)




+ Recent posts