Documentation

LevelPlay component API reference

Use the public methods and events of the LevelPlay components to control ads from your scripts.
Read time 8 minutesLast updated 2 days ago

This page documents the public methods, properties, and events of the four LevelPlay component classes:
For the Inspector window properties of each component, refer to LevelPlay component reference.

LevelPlay SDK component class

The
LevelPlaySdkBehaviour
class initializes the LevelPlay SDK. Add it once, in the first scene your game loads.
Related API:
LevelPlay.Init

Methods

Method

Description

Initialize()
Initializes the SDK with the app key for the current platform and the configured user ID. If no app key is set, it logs a warning and does nothing.
SetPauseGame(bool pause)
Same as
LevelPlay.SetPauseGame
. This method is supported only on iOS.

Events

Event

Description

Parameters

On Init SuccessInvoked when the SDK initializes successfully. Invoked on the Unity main thread.
LevelPlayConfiguration
On Init FailedInvoked when the SDK fails to initialize. Invoked on the Unity main thread.
LevelPlayInitError
The
LevelPlayBannerAdBehaviour
class loads and displays a banner ad at a fixed position on the screen.
Related API:
LevelPlayBannerAd
Important
The banner reads its Inspector properties when it creates the ad, on its first load. To apply changes later, call
DestroyAd()
and then
LoadAd()
.

Methods and properties

Member

Description

LoadAd()
Creates the banner from the Inspector settings on the first call, and loads it.
ShowAd()
Shows the banner. Does nothing before the banner is created.
HideAd()
Hides the banner without destroying it.
DestroyAd()
Destroys the banner. The next
LoadAd()
call creates a new one.
PauseAutoRefresh()
,
ResumeAutoRefresh()
Pauses or resumes the banner's auto-refresh.
GetAdId()
,
GetAdUnitId()
,
GetAdSize()
,
GetPosition()
,
GetPlacementName()
Returns the banner's current values.
Ad
The underlying
LevelPlayBannerAd
, or
null
if no ad exists.

Events

Event

Description

Parameters

On Ad LoadedInvoked when the banner loads.
LevelPlayAdInfo
On Ad Load FailedInvoked when the banner fails to load.
LevelPlayAdError
On Ad DisplayedInvoked when the banner becomes visible.
LevelPlayAdInfo
On Ad Display FailedInvoked when the banner fails to display.
LevelPlayAdInfo
,
LevelPlayAdError
On Ad ClickedInvoked when the player clicks the banner.
LevelPlayAdInfo
On Ad ExpandedInvoked when the banner expands to cover the screen.
LevelPlayAdInfo
On Ad CollapsedInvoked when the banner returns from its expanded state.
LevelPlayAdInfo
On Ad Left ApplicationInvoked when the app goes to the background after the player clicks the banner.
LevelPlayAdInfo
On Ad Impression Data ReadyInvoked when impression-level revenue data is available for this banner. Invoked on the Unity main thread.
LevelPlayImpressionData

Interstitial Ad (LevelPlay) component class

The
LevelPlayInterstitialAdBehaviour
class loads and shows a full-screen interstitial ad, for example between levels. It exposes its settings as public properties, such as
AndroidAdUnitId
,
LoadOnStart
, and
PlacementName
, and its events as public
UnityEvent
properties.
Related API:
LevelPlayInterstitialAd
For an example that uses this class, refer to Show an interstitial ad from a script.

Methods and properties

Member

Description

LoadAd()
Creates the ad from the Inspector settings on the first call, and loads it.
ShowAd()
Shows the ad using Placement Name. If no ad is ready, it logs a warning and does nothing.
ShowAd(string placementName)
Shows the ad with a specific placement.
IsAdReady()
Returns
true
if an ad is loaded and ready to show.
IsPlacementCapped()
,
IsPlacementCapped(string placementName)
Returns
true
if the placement is capped.
DestroyAd()
Destroys the ad. The next
LoadAd()
call creates a new one.
GetAdId()
Returns the ID of the current ad, or
null
.
Ad
The underlying
LevelPlayInterstitialAd
, or
null
.

Events

Event

Description

Parameters

On Ad LoadedInvoked when the ad loads and is ready to show.
LevelPlayAdInfo
On Ad Load FailedInvoked when the ad fails to load.
LevelPlayAdError
On Ad DisplayedInvoked when the ad opens.
LevelPlayAdInfo
On Ad Display FailedInvoked when the ad fails to show.
LevelPlayAdInfo
,
LevelPlayAdError
On Ad ClickedInvoked when the player clicks the ad.
LevelPlayAdInfo
On Ad Closed (
OnAdClosed
)
Invoked when the player closes the ad. Resume your game here.
LevelPlayAdInfo
On Ad Info ChangedInvoked when the ad info of a loaded ad changes.
LevelPlayAdInfo
On Ad Impression Data ReadyInvoked when impression-level revenue data is available. Invoked on the Unity main thread.
LevelPlayImpressionData

Rewarded Ad (LevelPlay) component class

The
LevelPlayRewardedAdBehaviour
class loads and shows a full-screen rewarded ad that grants the player a reward when they finish watching it.
Related API:
LevelPlayRewardedAd
For an example of a method that you connect to On Ad Rewarded in the Inspector window, refer to Grant a reward with a script.
The
LevelPlayRewardedAdBehaviour
class has all the methods, properties, and events of the
LevelPlayInterstitialAdBehaviour
class
, plus the following methods and event.

Methods

Method

Description

Parameters

Returns

GetReward()
Gets the reward for Placement Name. Use it for pre-show UI, such as "Watch an ad for 100 coins".NoneThe reward set for Placement Name, or the ad unit's default reward when no placement is set.
null
before the ad is created.
GetReward(string placement)
Gets the reward for a specific placement.
placement
: The placement to get the reward for.
The reward for the placement.

Events

Event

Description

Parameters

On Ad RewardedInvoked when the player earns the reward. Grant the reward here. Don't grant it in On Ad Closed.
LevelPlayAdInfo
,
LevelPlayReward