노력과 삽질 퇴적물

유니티: 구글 애드몹 본문

프로그래밍note/엔진 관련

유니티: 구글 애드몹

MTG 2016. 4. 5. 19:41






0. 필요한 파일


파일명

예시 경로

 GoogleMobileAds.unitypackage

 [#]

 (해당사항 없음)

 android-sdk

 C:\android-sdk-windows







1. 애드몹 가입 및 광고 ID생성


참조: 안드로이드: 구글 애드몹, 1. 애드몹 가입 및 광고 ID생성






2. 유니티, import






3. 유니티, 구현


* 마켓에서 'Device ID'로 검색하면 디바이스 아이디 검출앱이 꽤 많습니다.
물론 이미 알고 있는 경우 생략 가능합니다.


1) 스크립트, 배너

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
... ... ...
using GoogleMobileAds.Api;
 
public class SampleHandler : MonoBehaviour
{
    private BannerView adBannerView = null;
 
    void Start ()
    {
        if (adBannerView == null)
        {
            AdRequest.Builder builder = new AdRequest.Builder();
            adRequest = builder.Build();
            //adRequest = builder.AddTestDevice(AdRequest.TestDeviceSimulator).AddTestDevice("MY_DEVICE_ID").Build();//FOR TEST
            adBannerView = new BannerView("ca-app-pub-xxxxxxxxxxxxx", AdSize.Banner, AdPosition.BottomLeft);
            adBannerView.LoadAd(adRequest);//해당 함수로 광고 요청 반복 가능.
        }
    }
 
    ... ... ...
    private void DoAD()
    {
        adBannerView.Show();
    }
}
cs



2) 스크립트, 전면광고

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
... ... ...
using GoogleMobileAds.Api;
 
public class SampleHandler : MonoBehaviour
{
    private InterstitialAd adInterstitial = null;
    private AdRequest adRequest = null;
 
    void Start ()
    {
        if (interstitialAd == null)
        {
            adRequest = builder.Build();
            //adRequest = builder.AddTestDevice(AdRequest.TestDeviceSimulator).AddTestDevice("MY_DEVICE_ID").Build();//FOR TEST
            adInterstitial = new InterstitialAd("ca-app-pub-xxxxxxxxxxxxx");
            adInterstitial.AdClosed += AdListener;//전면광고를 종료시 이벤트 추가.
            adInterstitial.LoadAd(adRequest);
        }
    }
    ... ... ...
    private void DoAD()
    {
        if(adInterstitial.IsLoaded())
        {
            adInterstitial.Show();
        }
    }
 
    private void AdListener(object sender, System.EventArgs args)
    {
        adInterstitial.LoadAd(adRequest);
    }
}
cs






기타. 참조자료


예제.

애드몹(광고) 붙이기


기타

Unity - Scripting API: ADBannerView

> Banner Ads  |  AdMob for Android  |  Google Developers

unity - ResolutionException: Cannot find candidate artifact for com.google.android.gms:play-services-games:8.1+ - Game Development Stack Exchange






기타. 변경이력


일자

변경이력

2016-04-05

 초안