FloatAd - Atmosplay/AtmosplayAds-Unity Wiki

Create a FloatAd

The first step toward displaying a window ads is to create a FloatAd object in a C# script attached to a GameObject.

using System;
using UnityEngine;
using AtmosplayAds.Api;
using AtmosplayAds.Common;
public class AtmosplayFloatAdSceneScript : MonoBehaviour
{
#if UNITY_ANDROID
  const string AtmosplayAds_App_ID_FloatAd = "Your_AtmosplayAds_App_ID_FloatAd_Android";
  const string AtmosplayAds_AdUnit_ID_FloatAd = "Your_AtmosplayAds_AdUnit_ID_FloatAd_Android";
#elif UNITY_IOS
  const string AtmosplayAds_App_ID_FloatAd = "Your_AtmosplayAds_App_ID_FloatAd_iOS";
  const string AtmosplayAds_AdUnit_ID_FloatAd = "Your_AtmosplayAds_AdUnit_ID_FloatAd_iOS";
#else
  const string AtmosplayAds_App_ID_FloatAd = "unexpected_platform";
  const string AtmosplayAds_AdUnit_ID_FloatAd = "unexpected_platform";
#endif

  FloatAd floatAd;

  void Start() 
  {
    AdOptions adOptions = new AdOptionsBuilder()
      .SetChannelId("")
      .SetAutoLoadNext(true)
      .build();

    //After creating the FloatAd object, the SDK will start requesting ads
    floatAd = new FloatAd(AtmosplayAds_App_ID_FloatAd, AtmosplayAds_AdUnit_ID_FloatAd, gameObject, adOptions);
        floatAd.OnAdLoaded += HandleFloatAdLoaded;
        floatAd.OnAdFailedToLoad += HandleFloatAdFailedToLoad;
        floatAd.OnAdStarted += HandleFloatAdStart;
        floatAd.OnAdClicked += HandleFloatAdClicked;
        floatAd.OnAdRewarded += HandleFloatAdRewarded;
        floatAd.OnAdClosed += HandleFloatAdClosed;
  }

#region FloatAd callback handlers
public void HandleFloatAdLoaded(object sender, EventArgs args)
{
    print("atmosplay---HandleFloatAdLoaded");
}

public void HandleFloatAdFailedToLoad(object sender, AdFailedEventArgs args)
{
    print("atmosplay---HandleFloatAdFailedToLoad:" + args.Message);
}

public void HandleFloatAdStart(object sender, EventArgs args)
{
    print("atmosplay---HandleFloatAdStart");
}

public void HandleFloatAdClicked(object sender, EventArgs args)
{
    print("atmosplay---HandleFloatAdClicked");
}


public void HandleFloatAdRewarded(object sender, EventArgs args)
{
    print("atmosplay---HandleFloatAdRewarded");
}


public void HandleFloatAdClosed(object sender, EventArgs args)
{
    print("atmosplay---HandleFloatAdClosed");
}

#endregion
}  

Determine If FloatAd Has Been Loaded

if (floatAd != null)
{
floatAd.IsReady(AtmosplayAds_AdUnit_ID_FloatAd)
}

Set the position and width of the float display

Please create a floatAdView GameObjet at the position where you need to display the floatAd in the game before call the show() method:

if (floatAd != null)
{
  floatAd.SetPointAndWidth(floatAdView.transform);
}

Show FloatAd

This method add the float ad to your screen.

warning:

  1. if you want to update the position, call the UpdatePointAndWidth() please.
  2. if you want to show again after hiding, call the ShowAgainAfterHiding() please.
if (floatAd != null)
{
if(floatAd.IsReady(AtmosplayAds_AdUnit_ID_FloatAd))
{
  floatAd.Show(AtmosplayAds_AdUnit_ID_FloatAd);
}
}

Update FloatAd position and Size

  //If you want to update the position and size of the float ads, please update the position and size of the floatAdView GameObject in the game first, then use the following interface to update the float ads to the new position
if (floatAd != null)
{
  floatAd.UpdatePointAndWidth(floatAdView.transform);
}

Hide FloatAd

Make the floatAd's hidden value to Yes. Then the user can't see the ad in screen.

if (floatAd != null)
{
    floatAd.Hide();
}

ShowAgainAfterHiding FloatAd

Make the floatAd's hidden value to No. Then the user will see the ad again.

if (floatAd != null)
{
    floatAd.ShowAgainAfterHiding();
}

Destroy FloatAd

if (floatAd != null)
{
    floatAd.Destroy();
    floatAd = null;
}