private MyTargetView _myTargetView;
private void Awake()
{
UInt32 slotId = 0;
#if UNITY_ANDROID
slotId = ANDROID_SLOT_ID;
#elif UNITY_IOS
slotId = IOS_SLOT_ID;
#endif
// Enabling debug mode
// MyTargetView.IsDebugMode = true;
// Create an instance of MyTargetView, 320x50 format
_myTargetView = new MyTargetView(slotId);
// Create an instance of MyTargetView, 300x250 format
// _myTargetView = new MyTargetView(slotId, AdSize.Size300x250);
}
private readonly Object _syncRoot = new Object();
private MyTargetView _myTargetView;
private void Awake()
{
if (_myTargetView != null)
{
return;
}
lock (_syncRoot)
{
if (_myTargetView != null)
{
return;
}
// Create an instance of MyTargetView
_myTargetView = new MyTargetView(YOUR_SLOT_ID);
// Set event handlers
_myTargetView.AdClicked += OnAdClicked;
_myTargetView.AdLoadFailed += OnAdLoadFailed;
_myTargetView.AdLoadCompleted += OnAdLoadCompleted;
_myTargetView.AdShown += OnAdShown;
// Start loading ad
_myTargetView.Load();
}
}
private void OnAdClicked(Object sender, EventArgs eventArgs) { }
private void OnAdShown(Object sender, EventArgs eventArgs) { }
private void OnAdLoadFailed(Object sender, ErrorEventArgs errorEventArgs) { }
private void OnAdLoadCompleted(Object sender, EventArgs eventArgs)
{
// The ad is successfully loaded
// Set position on the screen
_myTargetView.X = 0;
_myTargetView.Y = 0;
// Start displaying ad
_myTargetView.Start();
}
private void OnDestroy()
{
if (_myTargetView == null)
{
return;
}
lock (_syncRoot)
{
if (_myTargetView == null)
{
return;
}
_myTargetView.Dispose();
_myTargetView = null;
}
}
// Disable automatic ad rotation
_myTargetView = new MyTargetView(YOUR_SLOT_ID, AdSize.Size320x50, false)
private InterstitialAd CreateInterstitialAd()
{
UInt32 slotId = 0;
#if UNITY_ANDROID
slotId = ANDROID_SLOT_ID;
#elif UNITY_IOS
slotId = IOS_SLOT_ID;
#endif
// Enabling debug mode
// InterstitialAd.IsDebugMode = true;
// Create an instance of InterstitialAd
return new InterstitialAd(slotId);
}
private InterstitialAd _interstitialAd;
private void InitAd()
{
// Create an instance of InterstitialAd
_interstitialAd = CreateInterstitialAd();
// Set event handlers
_interstitialAd.AdLoadCompleted += OnLoadCompleted;
_interstitialAd.AdDismissed += OnAdDismissed;
_interstitialAd.AdDisplayed += OnAdDisplayed;
_interstitialAd.AdVideoCompleted += OnAdVideoCompleted;
_interstitialAd.AdClicked += OnAdClicked;
_interstitialAd.AdLoadFailed += OnAdLoadFailed;
// Start loading ad
_interstitialAd.Load();
}
private void OnLoadCompleted(Object sender, EventArgs e)
{
}
private void OnAdDismissed(Object sender, EventArgs e)
{
}
private void OnAdDisplayed(Object sender, EventArgs e)
{
}
private void OnAdVideoCompleted(Object sender, EventArgs e)
{
}
private void OnAdClicked(Object sender, EventArgs e)
{
}
private void OnAdLoadFailed(Object sender, ErrorEventArgs e)
{
Debug.Log("OnAdLoadFailed: " + e.Message);
}
private void OnLoadCompleted(Object sender, EventArgs e)
{
// in a separate Page
_interstitialAd.Show();
// or in dialog box
// _interstitialAd.ShowDialog();
}
private InterstitialAd CreateInterstitialAd()
{
UInt32 slotId = 0;
#if UNITY_ANDROID
slotId = ANDROID_SLOT_ID;
#elif UNITY_IOS
slotId = IOS_SLOT_ID;
#endif
// Enabling debug mode
// InterstitialAd.IsDebugMode = true;
// Create an instance of InterstitialAd
return new InterstitialAd(slotId);
}
private InterstitialAd _interstitialAd;
private void InitAd()
{
// Create an instance of InterstitialAd
_interstitialAd = CreateInterstitialAd();
// Set event handlers
_interstitialAd.AdLoadCompleted += OnLoadCompleted;
_interstitialAd.AdDisplayed += OnAdDisplayed;
_interstitialAd.AdDismissed += OnAdDismissed;
_interstitialAd.AdVideoCompleted += OnAdVideoCompleted;
_interstitialAd.AdClicked += OnAdClicked;
_interstitialAd.AdLoadFailed += OnAdLoadFailed;
// Start loading ad
_interstitialAd.Load();
}
private void OnLoadCompleted(Object sender, EventArgs e)
{
}
private void OnAdDisplayed(Object sender, EventArgs e)
{
}
private void OnAdDismissed(Object sender, EventArgs e)
{
}
private void OnAdVideoCompleted(Object sender, EventArgs e)
{
}
private void OnAdClicked(Object sender, EventArgs e)
{
}
private void OnAdLoadFailed(Object sender, ErrorEventArgs e)
{
Debug.Log("OnAdLoadFailed: " + e.Message);
}
private void OnLoadCompleted(Object sender, EventArgs e)
{
// in a separate Page
_interstitialAd.Show();
// or in dialog box
// _interstitialAd.ShowDialog();
}
private InterstitialAd _ad;
private void InitAd()
{
// Create instance InterstitialAd
_ad = new InterstitialAd(YOUR_SLOT_ID);
// Set age
_ad.CustomParams.Age = 23;
// Set gender
_ad.CustomParams.Gender = CustomParams.GenderEnum.Male;
}