4-3. Banner Ads for Unity

It is a rectangular image or text ad that occupies a portion of the screen. It remains visible on the screen while the user interacts with the app and automatically refreshes.

Before you begin

04. Unity-Plugin Guide

ONEAdMax SDK Intitialize

ONEAdMax initialization is required before loading ads. The method ONEAdMaxClient.Initialize() must be executed only once.

...
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
            });
        }
    }
}

You can create an OAMBannerViewinstance and handle lifecycle events to extend its functionality.

Create a Banner View instance.

using ONEAdMax;
...
public class BannerViewController : MonoBehaviour
{    
    OAMBannerView _bannerView;
    
    public void CreateBannerView()
    {
        Debug.Log("Creating banner view.");

        // If we already have a banner.
        if (_bannerView != null) {
            Debug.LogWarning("Already have a banner.");
            return;
        }

        // Create a 320x50 banner view at top of the screen.
        _bannerView = new OAMBannerView(AdSize.BANNER_320x50, AdPosition.Top);
    }
}
Size
상수(Constant)

320x50

AdSize.BANNER_320x50

300x250

AdSize.BANNER_300x250

320x100

AdSize.BANNER_320x100

Set the banner display animation.

Set the animation when the banner is displayed. (Default: AnimType.NONE) There are a total of 7 animations you can configure.

_bannerView.SetAnimType(AnimType.SLIDE_LEFT); // Defaults to AnimType.NONE

애니메이션 타입 종류

상수
설명

AnimType.NONE

No animation (default)

AnimType.FADE_IN

Fade-in animation

AnimType.SLIDE_LEFT

Slide animation to the left

AnimType.SLIDE_RIGHT

Slide animation to the right

AnimType.TOP_SLIDE

Slide animation from the top

AnimType.BOTTOM_SLIDE

Slide animation from the bottom

AnimType.CIRCLE

Banner rotation animation

Set the network schedule timeout (optional)

Set the network schedule timeout for banner ads. (Default: 5 seconds) When loading ads, a timeout period is given for each network. If an ad is not received within that time, it will move to the next network.

_bannerView.SetNetworkScheduleTimeout(5); // Default 5 seconds

Set the banner ad request refresh interval (optional)

Set the refresh interval for banner ads. (Default: 60 seconds) The configurable range is between 15 and 300 seconds, and if set to -1, the ad will not refresh automatically.

// The default is 60 seconds, with a setting range of 15 to 300 seconds.
_bannerView.SetRefreshTime(60);

Fill the banner background color (optional)

You can fill the empty space of the banner view with a background color. (Default: true)

_bannerView.SetAutoBgColor(true); // Defaults to true

Set the banner mediation options (optional).

Supports configuration values for some mediation settings of the banner ads.

/// <summary>
/// Extend the functionality of the mediation that appears in your ads.
/// </summary>
/// <seealso cref="MediationKey" />
/// <param name="ad"><see cref="OAMBannerView"/></param>
private void SetMediationExtras(OAMBannerView ad)
{
    var extras = new Dictionary<MediationKey, object>
    {
        // Set to true to show Cauly ads on the lock screen. (Defaults to false)
        { MediationKey.CAULY_ENABLE_LOCK, false },
        
        // Control ad serving intervals on Cauly's side. (Defaults to true)
        { MediationKey.CAULY_ENABLE_DYNAMIC_RELOAD_INTERVAL, true },
        
        // Controls how often ads appear in media. (Default 20 seconds)
        // (available after changing CAULY_DAYNAMIC_RELOAD_INTERVAL to False)
        { MediationKey.CAULY_RELOAD_INTERVAL, 20 },
        
        // Set thread priority.
        { MediationKey.CAULY_THREAD_PRIORITY, 5 },
        
        // Options to set age information for meso ads. (Defaults to -1)
        // Unknown = -1; Children(under 13) = 0; Teens and adults(over 13) = 1
        { MediationKey.MEZZO_AGE_LEVEL, -1 },
        
        // Option to allow the banner to run in the background. (true | false)
        { MediationKey.MEZZO_ENABLE_BACKGROUND_CHECK, false },
        
        // The app's Store URL
        { MediationKey.MEZZO_STORE_URL, "..." }
    };

    ad.SetMediationExtras(extras);
}
📌Starting Mediation

Listen for events from the banner view (optional)

/// <summary>
/// Register to events the banner may raise.
/// </summary>
private void RegisterEvents(OAMBannerView ad)
{
    // Raised when an ad is loaded into the banner view.
    ad.OnLoaded += () =>
    {
        Debug.Log("Banner view loaded.");
    };

    // Raised when an ad fails to load into the banner view.
    ad.OnLoadFailed += (OAMError error) =>
    {
        Debug.LogError("Banner view failed to load an ad with error : " + error);
    };

    // Raised when a click is recorded for an ad.
    ad.OnClicked += () =>
    {
        Debug.Log("Banner view was clicked.");
    };
}
ONE AdMax SDK Error Codes

Create a banner view.

Complete all the settings and create theOAMBannerView

// These ad units are configured to always serve test ads.   
private readonly string _placementId = "String your placementID";  // 320 * 50

_bannerView.Create(_placementId);

Call the Load() API at the desired time to request an ad from the server for displaying the banner ad.

/// <summary>
/// Creates the banner view and loads a banner ad.
/// </summary>
public void Load()
{
    if (_bannerView == null)
    {
        Debug.LogWarning("The banner view is null.");
        return;
    }

    _bannerView.Load();
}

Stop displaying the banner ad.

Call it when you no longer want to display the banner ad.

/// <summary>
/// Destroys the ad.
/// When you are finished with a OAMBannerView, make sure to call
/// the Destroy() method before dropping your reference to it.
/// </summary>
public void Destroy()
{
    if (_bannerView != null)
    {
        Debug.Log("Destroying banner view.");
        _bannerView.Destroy();
        _bannerView = null;
    }
}

Check whether the banner ad is loaded.

Check whether the banner ad is loaded. (returns true | false)

_bannerView.IsLoaded();

Extend the application lifecycle.

Implement to check the onPause and onResume status of the application where the banner ad is being displayed.

public class BannerViewController : MonoBehaviour
{
    void OnApplicationPause(bool pauseStatus)
    {
        // You should call events for pause and resume in the application lifecycle.
        _bannerView?.OnPause(pauseStatus);
    }
}

Last updated