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.
ONEAdMax initialization is required before loading ads.
The method ONEAdMaxClient.Initialize() must be executed only once.
...usingONEAdMax;...publicclassONEAdMaxDemo:MonoBehaviour{privatestaticbool _isInitialized =false;voidStart() {if (!_isInitialized) { // Initialize the ONEAdMax SDK.ONEAdMaxClient.Initialize(() => { // This callback is called once the ONEAdMax SDK is initialized. _isInitialized =true }); } }}
Banner ADs Sample Code
You can create an OAMBannerViewinstance and handle lifecycle events to extend its functionality.
Create a Banner View instance.
usingONEAdMax;...publicclassBannerViewController:MonoBehaviour{ OAMBannerView _bannerView;publicvoidCreateBannerView() {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 =newOAMBannerView(AdSize.BANNER_320x50,AdPosition.Top); }}
The parameters for the Banner View constructor are:
AdSize: The size of the ad you want to use.
AdPosition: The position where the banner view should be placed.
Banner Size
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
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.
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>/// <seealsocref="MediationKey" />/// <paramname="ad"><seecref="OAMBannerView"/></param>privatevoidSetMediationExtras(OAMBannerView ad){var extras =newDictionary<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);}
Listen for events from the banner view (optional)
/// <summary>/// Register to events the banner may raise./// </summary>privatevoidRegisterEvents(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."); };}
Create a banner view.
Complete all the settings and create theOAMBannerView
// These ad units are configured to always serve test ads. privatereadonlystring _placementId ="String your placementID"; // 320 * 50_bannerView.Create(_placementId);
Banner Load
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>publicvoidLoad(){if (_bannerView ==null) {Debug.LogWarning("The banner view is null.");return; }_bannerView.Load();}
Excessive ad requests can lead to blocking, so please be cautious!
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>publicvoidDestroy(){if (_bannerView !=null) {Debug.Log("Destroying banner view.");_bannerView.Destroy(); _bannerView =null; }}
However, if the application is in a paused state, calling Destroy() may result in missing click reports. Therefore, it should be called when the Activity or Fragment containing the banner view is destroyed.
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.
publicclassBannerViewController:MonoBehaviour{voidOnApplicationPause(bool pauseStatus) { // You should call events for pause and resume in the application lifecycle._bannerView?.OnPause(pauseStatus); }}
If not handled, missing report data may occur when using third-party mediation.