728x90
반응형
!!! AppLovin 회원가입 및 페이지에서 설정하는 과정은 생략합니다.
!!! 다른 광고 구현했었다면 관련패키지를 삭제해야합니다.
(Assets폴더에서 Plugins, ExternalDependencyManager 등)
Step. 1 - SDK 설치하기 (1)
MAX Mediation Documentation
dash.applovin.com
- 위 링크로 접속 후 그림에 표시된 Unuty Plugin을 받아 진행중인 프로젝트에 SDK를 설치해줍니다.
![]() |
![]() |
Step. 2 - SDK 설치하기 (2)
![]() ![]() |
|
![]() |
4. 페이지에서 키입력을 하는 다른 플랫폼과 다르게 AdMob은 Manager에서도 입력해주어야 합니다. 5. Facebook의 경우에는 사용 시 별도로 SDK를 설치해주어야 합니다. |
Step. 3 - Script 생성 및 gameObject 생성
![]() |
|
![]() |
2. Project - Assets - Scripts 폴더에 Create -C# Script을 선택하여 AppLovinMax로 생성해주고 AdManager Component로 추가해줍니다.![]() |
Step. 4 - Script 작성
AppLovinMax.cs
더보기
using System;
using UnityEngine;
public class AppLovinMax : MonoBehaviour
{
// SDK Keys
private const string MaxSdkKey = "MaxSdkKey";
private const string BannerAdUnitId = "BannerAdUnitId";
private const string InterstitialAdUnitId = "InterstitialAdUnitId";
private const string RewardedAdUnitId = "RewardedAdUnitId";
private int interstitialRetryAttempt;
private int rewardedRetryAttempt;
void Start()
{
// AppLovinMax 초기화
MaxSdkCallbacks.OnSdkInitializedEvent += sdkConfiguration =>
{
// AppLovin SDK is initialized, configure and start loading ads.
Debug.Log("MAX SDK Initialized");
InitializeInterstitialAds();
InitializeRewardedAds();
InitializeBannerAds();
// 배너 실행
MaxSdk.ShowBanner(BannerAdUnitId);
};
MaxSdk.SetSdkKey(MaxSdkKey);
MaxSdk.InitializeSdk();
}
#region Interstitial Ad Methods
private void InitializeInterstitialAds()
{
// Attach callbacks
MaxSdkCallbacks.Interstitial.OnAdLoadedEvent += OnInterstitialLoadedEvent;
MaxSdkCallbacks.Interstitial.OnAdLoadFailedEvent += OnInterstitialFailedEvent;
MaxSdkCallbacks.Interstitial.OnAdDisplayFailedEvent += InterstitialFailedToDisplayEvent;
MaxSdkCallbacks.Interstitial.OnAdHiddenEvent += OnInterstitialDismissedEvent;
MaxSdkCallbacks.Interstitial.OnAdRevenuePaidEvent += OnInterstitialRevenuePaidEvent;
// Load the first interstitial
LoadInterstitial();
}
void LoadInterstitial()
{
MaxSdk.LoadInterstitial(InterstitialAdUnitId);
}
public static void ShowInterstitial()
{
if (MaxSdk.IsInterstitialReady(InterstitialAdUnitId))
{
MaxSdk.ShowInterstitial(InterstitialAdUnitId);
}
else
{
Debug.Log("Ad not ready");
}
}
private void OnInterstitialLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
// Interstitial ad is ready to be shown. MaxSdk.IsInterstitialReady(interstitialAdUnitId) will now return 'true'
Debug.Log("Interstitial loaded");
// Reset retry attempt
interstitialRetryAttempt = 0;
}
private void OnInterstitialFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo)
{
// Interstitial ad failed to load. We recommend retrying with exponentially higher delays up to a maximum delay (in this case 64 seconds).
interstitialRetryAttempt++;
double retryDelay = Math.Pow(2, Math.Min(6, interstitialRetryAttempt));
Debug.Log("Interstitial failed to load with error code: " + errorInfo.Code);
Invoke("LoadInterstitial", (float)retryDelay);
}
private void InterstitialFailedToDisplayEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo, MaxSdkBase.AdInfo adInfo)
{
// Interstitial ad failed to display. We recommend loading the next ad
Debug.Log("Interstitial failed to display with error code: " + errorInfo.Code);
LoadInterstitial();
}
private void OnInterstitialDismissedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
// Interstitial ad is hidden. Pre-load the next ad
Debug.Log("Interstitial dismissed");
LoadInterstitial();
}
private void OnInterstitialRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
// Interstitial ad revenue paid. Use this callback to track user revenue.
Debug.Log("Interstitial revenue paid");
// Ad revenue
double revenue = adInfo.Revenue;
// Miscellaneous data
string countryCode = MaxSdk.GetSdkConfiguration().CountryCode; // "US" for the United States, etc - Note: Do not confuse this with currency code which is "USD" in most cases!
string networkName = adInfo.NetworkName; // Display name of the network that showed the ad (e.g. "AdColony")
string adUnitIdentifier = adInfo.AdUnitIdentifier; // The MAX Ad Unit ID
string placement = adInfo.Placement; // The placement this ad's postbacks are tied to
}
#endregion
#region Rewarded Ad Methods
private void InitializeRewardedAds()
{
// Attach callbacks
MaxSdkCallbacks.Rewarded.OnAdLoadedEvent += OnRewardedAdLoadedEvent;
MaxSdkCallbacks.Rewarded.OnAdLoadFailedEvent += OnRewardedAdFailedEvent;
MaxSdkCallbacks.Rewarded.OnAdDisplayFailedEvent += OnRewardedAdFailedToDisplayEvent;
MaxSdkCallbacks.Rewarded.OnAdDisplayedEvent += OnRewardedAdDisplayedEvent;
MaxSdkCallbacks.Rewarded.OnAdClickedEvent += OnRewardedAdClickedEvent;
MaxSdkCallbacks.Rewarded.OnAdHiddenEvent += OnRewardedAdDismissedEvent;
MaxSdkCallbacks.Rewarded.OnAdReceivedRewardEvent += OnRewardedAdReceivedRewardEvent;
MaxSdkCallbacks.Rewarded.OnAdRevenuePaidEvent += OnRewardedAdRevenuePaidEvent;
// Load the first RewardedAd
LoadRewardedAd();
}
private void LoadRewardedAd()
{
Debug.Log("Loading...");
MaxSdk.LoadRewardedAd(RewardedAdUnitId);
}
private void ShowRewardedAd()
{
if (MaxSdk.IsRewardedAdReady(RewardedAdUnitId))
{
Debug.Log("Showing");
MaxSdk.ShowRewardedAd(RewardedAdUnitId);
}
else
{
Debug.Log("Ad not ready");
}
}
private void OnRewardedAdLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
// Rewarded ad is ready to be shown. MaxSdk.IsRewardedAdReady(rewardedAdUnitId) will now return 'true'
Debug.Log("Rewarded ad loaded");
// Reset retry attempt
rewardedRetryAttempt = 0;
}
private void OnRewardedAdFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo)
{
// Rewarded ad failed to load. We recommend retrying with exponentially higher delays up to a maximum delay (in this case 64 seconds).
rewardedRetryAttempt++;
double retryDelay = Math.Pow(2, Math.Min(6, rewardedRetryAttempt));
Debug.Log("Rewarded ad failed to load with error code: " + errorInfo.Code);
Invoke("LoadRewardedAd", (float)retryDelay);
}
private void OnRewardedAdFailedToDisplayEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo, MaxSdkBase.AdInfo adInfo)
{
// Rewarded ad failed to display. We recommend loading the next ad
Debug.Log("Rewarded ad failed to display with error code: " + errorInfo.Code);
LoadRewardedAd();
}
private void OnRewardedAdDisplayedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
Debug.Log("Rewarded ad displayed");
}
private void OnRewardedAdClickedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
Debug.Log("Rewarded ad clicked");
}
private void OnRewardedAdDismissedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
// Rewarded ad is hidden. Pre-load the next ad
Debug.Log("Rewarded ad dismissed");
LoadRewardedAd();
}
private void OnRewardedAdReceivedRewardEvent(string adUnitId, MaxSdk.Reward reward, MaxSdkBase.AdInfo adInfo)
{
// Rewarded ad was displayed and user should receive the reward
Debug.Log("Rewarded ad received reward");
}
private void OnRewardedAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
// Rewarded ad revenue paid. Use this callback to track user revenue.
Debug.Log("Rewarded ad revenue paid");
// Ad revenue
double revenue = adInfo.Revenue;
// Miscellaneous data
string countryCode = MaxSdk.GetSdkConfiguration().CountryCode; // "US" for the United States, etc - Note: Do not confuse this with currency code which is "USD" in most cases!
string networkName = adInfo.NetworkName; // Display name of the network that showed the ad (e.g. "AdColony")
string adUnitIdentifier = adInfo.AdUnitIdentifier; // The MAX Ad Unit ID
string placement = adInfo.Placement; // The placement this ad's postbacks are tied to
}
#endregion
#region Banner Ad Methods
private void InitializeBannerAds()
{
// Attach Callbacks
MaxSdkCallbacks.Banner.OnAdLoadedEvent += OnBannerAdLoadedEvent;
MaxSdkCallbacks.Banner.OnAdLoadFailedEvent += OnBannerAdFailedEvent;
MaxSdkCallbacks.Banner.OnAdClickedEvent += OnBannerAdClickedEvent;
MaxSdkCallbacks.Banner.OnAdRevenuePaidEvent += OnBannerAdRevenuePaidEvent;
// Banners are automatically sized to 320x50 on phones and 728x90 on tablets.
// You may use the utility method `MaxSdkUtils.isTablet()` to help with view sizing adjustments.
MaxSdk.CreateBanner(BannerAdUnitId, MaxSdkBase.BannerPosition.BottomCenter);
// Set background or background color for banners to be fully functional.
MaxSdk.SetBannerBackgroundColor(BannerAdUnitId, Color.white);
}
private void OnBannerAdLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
// Banner ad is ready to be shown.
// If you have already called MaxSdk.ShowBanner(BannerAdUnitId) it will automatically be shown on the next ad refresh.
Debug.Log("Banner ad loaded");
}
private void OnBannerAdFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo)
{
// Banner ad failed to load. MAX will automatically try loading a new ad internally.
Debug.Log("Banner ad failed to load with error code: " + errorInfo.Code);
}
private void OnBannerAdClickedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
Debug.Log("Banner ad clicked");
}
private void OnBannerAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
// Banner ad revenue paid. Use this callback to track user revenue.
Debug.Log("Banner ad revenue paid");
// Ad revenue
double revenue = adInfo.Revenue;
// Miscellaneous data
string countryCode = MaxSdk.GetSdkConfiguration().CountryCode; // "US" for the United States, etc - Note: Do not confuse this with currency code which is "USD" in most cases!
string networkName = adInfo.NetworkName; // Display name of the network that showed the ad (e.g. "AdColony")
string adUnitIdentifier = adInfo.AdUnitIdentifier; // The MAX Ad Unit ID
string placement = adInfo.Placement; // The placement this ad's postbacks are tied to
}
#endregion
}
- 배너 관련하여 다른 패키지와 달리 자동으로 dontdestroyonload가 적용되어 있으므로 따로 설정할 필요는 없고, 배너의 배경색이나 포지션 정도 정해줄 수 있습니다.
728x90
반응형
'Language > Unity' 카테고리의 다른 글
[Unity] Minify의 Use R8, Release, Debug 각 옵션에 대한 설명 (0) | 2023.03.28 |
---|---|
OnDrag와 OnMouseDrag의 차이 (0) | 2023.03.21 |
Unity C# 숫자 3자리마다 콤마 삽입 및 삭제하기 (0) | 2023.03.21 |