Help Center/Details/

Rewarded Video

Load Rewarded Video Ad

We would recommend you that preload the ad and set up the callback event, since it takes time to load video ads.

Public void LoadRewardAd()
{
    If (this.rewardAd != null)
    {
        Debug.LogError("Ads already loaded");
        This.information.text = "Ads are already loaded";
        Return;
    }

    Var adSlot = new AdSlot.Builder()
if UNITY_IOS
        .SetCodeId("your ios placement id")
else
        .SetCodeId("your android placement id")
endif
        .SetRewardName("Gold Coin")
        .SetRewardAmount(3) 
        .SetUserID("user123") //optional
        .SetMediaExtra("media_extra")//optional
        .SetOrientation(AdOrientation.Horizontal) //set how you wish the video ad to be displayed, horizontal or vertical
        .Build();

    this.AdNative.LoadRewardVideoAd(adSlot, new RewardVideoAdListener(this));
}

Display Rewarded Video Ad

Call the method ShowRewardVideoAd after successfully loading an ad.

Private sealed class RewardVideoAdListener : IRewardVideoAdListener
{
    Private example example;

    Public RewardVideoAdListener(Example example)
    {
        This.example = example;
    }

    // Failed to load rewarded video ad
    Public void OnError(int code, string message)
    {
        Debug.LogError("OnRewardError: " + message);
        This.example.information.text = "OnRewardError: " + message;
    }

    // Load rewarded video ad successfully, indicating that it can be played online without local video cache
    Public void OnRewardVideoAdLoad(RewardVideoAd ad)
    {
        Debug.Log("OnRewardVideoAdLoad");
        This.example.information.text = "OnRewardVideoAdLoad";
        ad.SetRewardAdInteractionListener(new RewardAdInteractionListener(this.example));
        ad.SetDownloadListener(New AppDownloadListener(this.example));
        this.example.rewardAd = ad;
    }

    // Successfully cached video data, indicating that it can be played using the local cache.
    Public void OnRewardVideoCached()
    {
        Debug.Log("OnRewardVideoCached");
        This.example.information.text = "OnRewardVideoCached";
    }
}

Monitoring Settings of Rewarded Video Ad

To further customize the behavior of your ad, you can hook into a number of events in the ad's lifecycle

Private sealed class RewardAdInteractionListener : IRewardAdInteractionListener
{
    Private example example;

    Public RewardAdInteractionListener(Example example)
    {
        This.example = example;
    }

    // ad display
    Public void OnAdShow()
    {
        Debug.Log("rewardVideoAd show");
        This.example.information.text = "rewardVideoAd show";
    }

    // The video is clicked
    Public void OnAdVideoBarClick()
    {
        Debug.Log("rewardVideoAd bar click");
        This.example.information.text = "rewardVideoAd bar click";
    }

    // The ad is closed
    Public void OnAdClose()
    {
        Debug.Log("rewardVideoAd close");
        This.example.information.text = "rewardVideoAd close";
    }

    // video playback is complete
    Public void OnVideoComplete()
    {
        Debug.Log("rewardVideoAd complete");
        This.example.information.text = "rewardVideoAd complete";

    }

    // video playback error
    Public void OnVideoError()
    {
        Debug.LogError("rewardVideoAd error");
        This.example.information.text = "rewardVideoAd error";
    }

    // The reward is valid (requires backend configuration regarding whether to issue a reward)
    Public void OnRewardVerify(Bool rewardVerify, int rewardAmount, string rewardName)
    {
        Debug.Log("verify:" + rewardVerify + " amount:" + rewardAmount +
            " name:" + rewardName);
        This.example.information.text =
            "verify:" + rewardVerify + " amount:" + rewardAmount +
            " name:" + rewardName;
    }
}

Rewarded Video Ad Destruction

Since the rewarded video ad is always referenced, the corresponding resource will not be released and needs to be released by yourself.

public void DisposeAds()
{
#if UNITY_IOS
    if (this.rewardAd != null)
    {
        this.rewardAd.Dispose();
        this.rewardAd = null;
    }
#else
    if (this.rewardAd != null)
    {
        this.rewardAd = null;
    }
#endif
}

If you need more than one rewarded video ad, it is recommended to create multiple RewardVideoAd and manage the corresponding video separately. If only one is displayed at a time, LoadRewardAd can be called after the first rewarded video closes to load the new rewarded video ad. Please refer to the demo example for specific usage.

Reference

RewardVideoAd Interface

Public Sealed Class RewardVideoAd : IDisposable

    {

        _/// <inheritdoc/>_

        Public VoidDispose()
        {

        }

        _/// <summary>_
        _/// Set up ad interaction listener._
        _/// </summary>_
        Public VoidSetRewardAdInteractionListener(IRewardAdInteractionListener listener)
        {

        }

        _/// <summary>_
        _/// Set up ad download listener (Android)._
        _/// </summary>_

        Public VoidSetDownloadListener(IAppDownloadListener listener)
        {

        }

        _/// <summary>_
        _/// Get the ad interaction type._
        _/// </summary>_

        Public IntGetInteractionType()
        {
            Return 0;
        }

        _/// <summary>_
        _/// Show rewarded video ads._
        _/// </summary>_

        Public VoidShowRewardVideoAd()

        {

        }

        _/// <summary>_
        _/// Set whether to show the download bar._
        _/// </summary>_

        Public VoidSetShowDownLoadBar(bool show)
        {

        }

    }
Did the content solve your problem?