유니티용 구글 Admob SDK 설치
Releases · googleads/googleads-mobile-unity
Official Unity Plugin for the Google Mobile Ads SDK - googleads/googleads-mobile-unity
github.com
구글 Admob 설정
Google AdMob: 모바일 앱 수익 창출
인앱 광고를 사용하여 모바일 앱에서 더 많은 수익을 창출하고, 사용이 간편한 도구를 통해 유용한 분석 정보를 얻고 앱을 성장시켜 보세요.
admob.google.com
구글 Admob 홈페이지
배너 광고 | Unity | Google for Developers
Google 모바일 광고 Unity 플러그인 버전 5.4.0 이하에서는 서비스가 종료되어 광고가 게재되지 않을 수 있습니다. 지원되는 SDK 버전으로 앱을 업데이트합니다. 이 페이지는 Cloud Translation API를 통해
developers.google.com
v8.7.0 기준
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class AdmobBanner : MonoBehaviour
{
[Header("안드로이드 ID")]
public string androidUnitId = "ca-app-pub-3940256099942544/6300978111";
[Header("아이폰 ID")]
public string iosUnitId = "ca-app-pub-3940256099942544/2934735716";
string adUnitId;
BannerView _bannerView;
public void Start()
{
// Google Mobile Ads 초기화
MobileAds.Initialize((InitializationStatus initStatus) =>
{
// 초기화 완료
});
#if UNITY_ANDROID
adUnitId = androidUnitId;
#elif UNITY_IOS
adUnitId = iosUnitId;
#else
adUnitId = "unexpected_platform";
#endif
// 광고 로드
LoadAd();
}
public void LoadAd() // 광고 로드
{
if (_bannerView == null)
{
// 배너 뷰 생성
CreateBannerView();
}
var adRequest = new AdRequest.Builder()
.AddKeyword("unity-admob-sample")
.Build();
Debug.Log("배너 광고를 로드합니다.");
_bannerView.LoadAd(adRequest);
}
public void CreateBannerView() // 배너 뷰 생성
{
Debug.Log("배너 뷰 생성 중");
if (_bannerView != null)
{
// 기존 광고 제거
DestroyAd();
}
AdSize adaptiveSize =
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullWidth);
_bannerView = new BannerView(adUnitId, adaptiveSize, AdPosition.Top);
//_bannerView = new BannerView(adUnitId, AdSize.Banner, 0, 50);
}
private void ListenToAdEvents() // 광고 이벤트 리스너
{
_bannerView.OnBannerAdLoaded += () =>
{
Debug.Log("배너 광고가 로드되었습니다. 응답 정보: "
+ _bannerView.GetResponseInfo());
};
_bannerView.OnBannerAdLoadFailed += (LoadAdError error) =>
{
Debug.LogError("배너 광고 로드 실패: " + error);
};
_bannerView.OnAdPaid += (AdValue adValue) =>
{
Debug.Log(string.Format("배너 광고 지불: {0} {1}.",
adValue.Value,
adValue.CurrencyCode));
};
_bannerView.OnAdImpressionRecorded += () =>
{
Debug.Log("배너 광고 노출 기록.");
};
_bannerView.OnAdClicked += () =>
{
Debug.Log("배너 광고 클릭됨.");
};
_bannerView.OnAdFullScreenContentOpened += () =>
{
Debug.Log("배너 광고 전체 화면 열림.");
};
_bannerView.OnAdFullScreenContentClosed += () =>
{
Debug.Log("배너 광고 전체 화면 닫힘.");
};
}
public void ShowAd() // 광고 표시
{
if (_bannerView != null)
{
Debug.Log("배너 광고 표시.");
_bannerView.Show();
}
else
{
// 광고가 없으면 새로 로드
LoadAd();
}
}
public void HideAd() // 광고 숨기기
{
if (_bannerView != null)
{
Debug.Log("배너 광고 숨김.");
_bannerView.Hide();
}
}
public void DestroyAd() // 광고 제거
{
if (_bannerView != null)
{
Debug.Log("배너 광고 제거.");
_bannerView.Destroy();
_bannerView = null;
}
}
}
참고할만한 글
유니티 C# 구글 애드몹 Google Admob 전면 광고 간단 적용법
구글 애드몹 SDK 설치 https://github.com/googleads/googleads-mobile-unity/releases Releases · googleads/googleads-mobile-unity Official Unity Plugin for the Google Mobile Ads SDK - googleads/googleads-mobile-unity github.com 구글 애드몹 홈페
parksh3641.tistory.com
유니티 C# 구글 애드몹 Google Admob 보상형 광고 간단 적용법
구글 애드몹 SDK 설치 https://github.com/googleads/googleads-mobile-unity/releases Releases · googleads/googleads-mobile-unity Official Unity Plugin for the Google Mobile Ads SDK - googleads/googleads-mobile-unity github.com 구글 애드몹 홈페
parksh3641.tistory.com
의뢰하기
유니티로 제작된 게임을 업그레이드 해드립니다. - 크몽
DevPark 전문가의 IT·프로그래밍 서비스를 만나보세요. <p><strong style="font-size: 24px;&q...
kmong.com