Main functions

  • Display of video reward advertisement
  • Callback support from video reward advertisement
  • Support for each SDK mediation

System operating environment

  • Android
    • Android SDK 4.1 or later
  • iOS
    • iOS 9.0 or later
    • 64bit for iOS

Development environment

  • Unity 2019.2.12f1
  • JDK 1.8 or later
  • SDK build target 28

Plugin Installation Procedure

I will explain the procedure for installing Plugin to Unity.

  1. Import GNSAdSDK-UnityPlugin-Reward-4.0.0 to Unity project
  2. Register events for video reward advertisement using Plugin API
  3. Add discard processing
  4. Load video reward advertisement
  5. Display of video reward advertisement

1. Import GNSAdSDK-UnityPlugin-Reward plugin to Unity project

  1. Open the Unity project that incorporates the plugin.
  2. Refer to [https://github.com/googlesamples/unity-jar-resolver] (http://github.com/googlesamples/unity-jar-resolver) and introduce PlayServicesResolver.
  3. Select Assets -> Import Package -> Custom Package from the menu bar.
  4. Select the GNSAdSDK-UnityPlugin-Reward-4.0.0.unitypackage file in the folder.
  5. Make sure all files' checkboxes are checked and click Import.

2. Using the Plugin API, register events for video reward advertisement

The code below is necessary to create a video reward advertisement and register an event. When registering an event, please complete the registration process before loading the movie.

using GNSAdSDK.Api;

...

private static bool isRegistedRewardVideoEventHandler = false;

private void RegistRewardVideoAdEventHandler ()
{
    if (! isRegistedRewardVideoEventHandler) {
        RewardVideoAd rewardVideoAd = RewardVideoAd.Instance;

        rewardVideoAd.OnAdLoaded + = (object sender, System.EventArgs args) => {
            / / Processing when loading video reward ads is complete
        };
        rewardVideoAd.OnAdStarted + = (object sender, VideoRewardData args) => {
            // Processing when video reward advertisement is played
            / / * For iOS only, an instance of VideoRewardData with all properties empty is passed to args.
        };
        rewardVideoAd.OnAdRewarded + = (object sender, VideoRewardData args) => {
            / / Processing when reward is given to user
        };
        rewardVideoAd.OnAdClosed + = (object sender, VideoRewardData args) => {
            // Processing when the video reward ad is closed
            / / * For iOS only, an instance of VideoRewardData with all properties empty is passed to args.
        };
        rewardVideoAd.OnAdFailedToLoad + = (object sender, VideoRewardFailedData args) => {
            // Processing when loading video reward advertisement fails
        };
    }
    isRegistedRewardVideoEventHandler = true;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  • The RewardVideoAd instance is a singleton object for manipulating video reward advertisements.
  • Since RewardVideoAd instance is a singleton object, we recommend that you register events only once to avoid event duplication.

VideoRewardData possesses the following properties.

public class VideoRewardData: EventArgs
{
    // name
    // * For iOS, it is always null.
    public string AdName {get; set;}
    // Amount of money
    public double Amount {get; set;}
    // type
    public string Type {get; set;}
}
1
2
3
4
5
6
7
8
9
10
11

VideoRewardFailedData possesses the following properties.

public class VideoRewardFailedData: EventArgs
{
    // Ad network name
    // * For iOS, it is always null.
    public string AdnetworkName {get; set;}
    // code
    public int Code {get; set;}
    // Message
    public string Message {get; set;}
}
1
2
3
4
5
6
7
8
9
10
11

3. Add destruction processing

For Android In order to perform discard processing at OnDestroy, please set the Application.Quit callback as follows.

  • It is not mandatory when creating only iOS.
using GNSAdSDK.Api;

...

void OnApplicationQuit() {
    RewardVideoAd.Instance.DisposeAd();
}
1
2
3
4
5
6
7
8

4. Load video reward advertisement

Below is the code necessary for loading video reward ads.

using GNSAdSDK.Api;

...

private void LoadRewardVideoAd ()
{
    #if UNITY_ANDROID
        string zoneId = "Please insert zoneId here";
    #elif UNITY_IPHONE
        string zoneId = "Please insert zoneId here";
    # else
        string zoneId = "dummy";
    # endif

    RewardVideoAd rewardVideoAd = RewardVideoAd.Instance;
    rewardVideoAd.LoadAd (zoneId);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  • The RewardVideoAd instance is a singleton object for manipulating video reward advertisements.
  • Loading may take more than a few seconds, please load video ads early.
  • If you want to show another movie after the completion of playback of one movie, you need to load again.

5. Display video reward advertisement

The code below is necessary for displaying video reward advertisement. After loading the movie, you can call ShowAd ().

using GNSAdSDK.Api;

...

private void ShowRewardVideoAd()
{
   RewardVideoAd rewardVideoAd = RewardVideoAd.Instance;

    // Check if the animation can be displayed
    if (rewardVideoAd.IsLoaded ()) {
        // Display video
        rewardVideoAd.ShowAd ();
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

6. About pre-call advertisement

Points to note when you want to load the next ad before showing advertisement

Implement LoadAd(zoneId); into the ad close event (OnAdClosed), not within the reward grant event (OnAdRewarded).

Last Updated: 7/21/2020, 4:39:55 PM