WindowAd - Atmosplay/AtmosplayAds-Unity GitHub Wiki
Create a WindowAd
The first step toward displaying a window ads is to create a WindowAd object in a C# script attached to a GameObject.
using System;
using UnityEngine;
using AtmosplayAds.Api;
using AtmosplayAds.Common;
public class AtmosplayWindowAdSceneScript : MonoBehaviour
{
#if UNITY_ANDROID
const string AtmosplayAds_App_ID_WindowAd = "Your_AtmosplayAds_App_ID_WindowAd_Android";
const string AtmosplayAds_AdUnit_ID_WindowAd = "Your_AtmosplayAds_AdUnit_ID_WindowAd_Android";
#elif UNITY_IOS
const string AtmosplayAds_App_ID_WindowAd = "Your_AtmosplayAds_App_ID_WindowAd_iOS";
const string AtmosplayAds_AdUnit_ID_WindowAd = "Your_AtmosplayAds_AdUnit_ID_WindowAd_iOS";
#else
const string AtmosplayAds_App_ID_WindowAd = "unexpected_platform";
const string AtmosplayAds_AdUnit_ID_WindowAd = "unexpected_platform";
#endif
WindowAd windowAd;
void Start()
{
AdOptions adOptions = new AdOptionsBuilder()
.SetChannelId("")
.build();
//After creating the WindowAd object, the SDK will start requesting ads
windowAd = new WindowAd(AtmosplayAds_App_ID_WindowAd, AtmosplayAds_AdUnit_ID_WindowAd, gameObject, adOptions);
windowAd.OnAdLoaded += HandleWindowAdLoaded;
windowAd.OnAdFailedToLoad += HandleWindowAdFailedToLoad;
windowAd.OnAdStarted += HandleWindowAdStart;
windowAd.OnAdClicked += HandleWindowAdClicked;
windowAd.OnAdFinished += HandleWindowAdFinished;
windowAd.OnAdClosed += HandleWindowAdClosed;
windowAd.OnAdFailToShow += HandleWindowAdFailToShow;
}
#region WindowAd callback handlers
public void HandleWindowAdLoaded(object sender, EventArgs args)
{
print("atmosplay---HandleWindowAdLoaded");
}
public void HandleWindowAdFailedToLoad(object sender, AdFailedEventArgs args)
{
print("atmosplay---HandleWindowAdFailedToLoad:" + args.Message);
}
public void HandleWindowAdStart(object sender, EventArgs args)
{
print("atmosplay---HandleWindowAdStart");
}
public void HandleWindowAdClicked(object sender, EventArgs args)
{
print("atmosplay---HandleWindowAdClicked");
}
public void HandleWindowAdFinished(object sender, EventArgs args)
{
print("atmosplay---HandleWindowAdFinished");
}
public void HandleWindowAdClosed(object sender, EventArgs args)
{
print("atmosplay---HandleWindowAdClosed");
}
public void HandleWindowAdFailToShow(object sender, EventArgs args)
{
print("atmosplay---HandleWindowAdFailToShow");
}
#endregion
}
Determine If WindowAd Has Been Loaded
if (windowAd != null)
{
windowAd.IsReady()
}
Show WindowAd
First please create a windowAdview GameObjet at the position where you need to display the window ads in the game:
Call this method to place the window ad on the screen.
It will auto load the next ad.
if (windowAd != null)
{
if(windowAd.IsReady())
{
// 1. The transform of GameObject you create.
// 2. The angle you want to show.(only iOS support)
windowAd.Show(windowAdView.transform, angleNumber);
}
}
Close WindowAd
if (windowAd != null)
{
windowAd.Close();
}
Destroy WindowAd
if (windowAd != null)
{
windowAd.Destroy();
windowAd = null;
}