Before loading ads, it is necessary to initialize ONEAdMax.
The ONEAdMaxClient.Initialize() should only be performed once during the initial setup.
...
using ONEAdMax;
...
public class ONEAdMaxDemo : MonoBehaviour
{
private static bool _isInitialized = false;
void Start()
{
if (!_isInitialized)
{
// Initialize the ONEAdMax SDK.
ONEAdMaxClient.Initialize(() =>
{
// This callback is called once the ONEAdMax SDK is initialized.
_isInitialized = true
});
}
}
}
Interstitial Ads Sample Code
You can create an instance of OAMInterstitial and extend its functionality by handling events.
Creating an instance of Interstitial Ads.
public class InterstitialAdController : MonoBehaviour
{
OAMInterstitial _interstitialAd;
/// <summary>
/// Creates the ad.
/// </summary>
public void CreateInterstitialAd()
{
Debug.Log("Creating Interstitial ad.");
if (_interstitialAd != null)
{
Debug.LogWarning("Already have a Interstitial ad.");
return;
}
_interstitialAd = new OAMInterstitial();
}
}
Custom options for Interstitial Ads (optional).
/// <summary>
/// Customization of the ads screen.
/// </summary>
/// <seealso cref="CustomExtraKey"/>
/// <param name="ad"><see cref="OAMInterstitial"/></param>
private void SetCustomExtras(OAMInterstitial ad)
{
var customExtras = new Dictionary<CustomExtraKey, object>
{
// Change interstitial ad background color and transparency (Defaults to "#FF000000")
{ CustomExtraKey.BACKGROUND_COLOR, "#FF000000" },
// Set whether to show a close button in the top right corner of the interstitial ad. (Defaults to false)
{ CustomExtraKey.HIDE_CLOSE_BTN, false },
// Change to False to provide a margin based on the ad image. (Defaults to true)
{ CustomExtraKey.CLOSE_BTN_MARGIN_FROM_EDGE, true },
// Left margin of the interstitial ad close button. (Defaults to -28dp)
{ CustomExtraKey.CLOSE_BTN_LEFT_MARGIN, -28 },
// Top margin of the interstitial ad close button. (Defaults to 20dp)
{ CustomExtraKey.CLOSE_BTN_TOP_MARGIN, 20 },
// Right margin of the interstitial ad close button. (Defaults to 20dp)
{ CustomExtraKey.CLOSE_BTN_RIGHT_MARGIN, 20 },
// Bottom margin of the interstitial ad close button. (Defaults to 0dp)
{ CustomExtraKey.CLOSE_BTN_BOTTOM_MARGIN, 0 },
// Disable interstitial ad exit with a backkey. (Defaults to false)
{ CustomExtraKey.DISABLE_BACK_BTN, false },
// Whether to show an exit message in interstitial ads. (Defaults to false)
{ CustomExtraKey.IS_ENDING_AD, false },
// Change the exit ad message.
{ CustomExtraKey.ENDING_TEXT, "To exit, press the Back button one more time." },
// Change the text size of the exit ad message.
{ CustomExtraKey.ENDING_TEXT_SIZE, 14 },
// Change the text color of the exit ad message.
{ CustomExtraKey.ENDING_TEXT_COLOR, "#FFFFFFFF" },
// Change the gravity of exit ad message.
{ CustomExtraKey.ENDING_TEXT_GRAVITY, OAMGravity.RIGHT },
};
ad.SetCustomExtras(customExtras);
}
Setting an event listener for Interstitial Ads (optional).
/// <summary>
/// Register to events the interstital ad may raise.
/// </summary>
private void RegisterEvents(OAMInterstitial ad)
{
// Raised when an ad is loaded into the interstitial ad.
ad.OnLoaded += () =>
{
Debug.Log("Interstitial ad loaded.");
};
// Raised when the interstitial ad fails to load.
ad.OnLoadFailed += (OAMError error) =>
{
Debug.LogError("Interstitial ad failed to load an ad with error : " + error);
};
// Raised when an ad opened full screen content.
ad.OnOpened += () =>
{
Debug.Log("Interstitial ad has been opened.");
};
// Raised when the ad failed to open full screen content.
ad.OnOpenFailed += (OAMError error) =>
{
Debug.LogError("Interstitial ad failed to open an ad with error : " + error);
};
// Raised when the ad closed full screen content.
ad.OnClosed += (CloseEventType closeEventType) =>
{
Debug.LogError("Interstitial ad closed with type : " + closeEventType);
};
// Raised when a click is recorded for an ad.
ad.OnClicked += () =>
{
Debug.Log("Interstitial ad was clicked.");
};
}
Creating Interstitial Ads
Complete all the settings and create the OAMInterstitial.
// These ad units are configured to always serve test ads.
private readonly string _placementId = "string your placement ID;"
_interstitialAd.Create(_placementId);
Interstitial Ads Load
Call the Load() API for interstitial ads to request an ad from the server.
/// <summary>
/// Loads the ad.
/// </summary>
public void Load()
{
if (_interstitialAd == null)
{
Debug.LogWarning("The interstital ad is null.");
return;
}
_interstitialAd.Load();
}
Excessive ad requests can be a reason for blocking, so please be cautious!
Interstitial Ads 노출하기
광고 로드가 완료되면 광고를 노출을 원하는 시점에 Show() API를 호출하여 화면에 노출 시킵니다.
/// <summary>
/// Shows the ad.
/// </summary>
public void Show()
{
if (_interstitialAd != null && _interstitialAd.IsLoaded())
{
Debug.Log("Showing interstital ad.");
_interstitialAd.Show();
}
else
{
Debug.LogError("The Interstitial ad hasn't loaded yet.");
}
}
Interstitial Ads Memory Destroy
Destroy the memory within the instance of the interstitial ad.
/// <summary>
/// Destroys the ad.
/// </summary>
public void Destroy()
{
if (_interstitialAd != null)
{
Debug.Log("Destroying interstitial ad.");
_interstitialAd.Destroy();
_interstitialAd = null;
}
}
Check whether the Interstitial Ads are loaded.
Check whether the interstitial ad is loaded. (returns true | false)