Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Native ads

fan-c-yu edited this page Mar 5, 2021 · 7 revisions

Preparation

If you have not created ad spaces or downloaded SDK, please refer to the link below.

SDK Implementation

If you have not imported Unity package into project, please follow the link below.


How to show native ads

Procedure is as follows.

  1. Native ads layout
  2. Native ads load
  1. Add GameObject into Canvas which is located within Scene. Set ad position/size by using RectTransform of Inspector. native_layout_1

  2. Add NendAdNativeView to GameObject created at step1 above. native_layout_2

  3. Add Text or RawImage of ads to GameObject created at step 1 above to set position/size. native_layout_3

  4. Connect Text or RawImage to NendAdNativeView ad items below on inspector. native_layout_4

Item Explanation
Pr Text Text which displays Advertising Explicitly
Short Text Text which displays ad header
Long Text Text which displays ad text
Promotion Name Text Text which displays promotion name
Promotion Url Text Text which displays promotion URL
Action Button Text Text which displays action button text
Ad Image RawImage which displays ad images
Logo Image RawImage which show logo images

Each item has to be displayed under the restriction below.

  • Advertising Explicitly must be displayed.
  • Either ad header, ad text or promotion name has to be displayed.
  • If ad space includes image, ad image has to be displayed.
  • Ad expansion/shrink ratio must be within 30% ~150%.
  • Ad image clipping must be within 6% both horizontally and vertically.
  • Clipping logo image is not allowed.

Other items which can be set by Inspector of NendAdNativeView.

The following items can be set.

Item Explanation type Supplement
View Tag The tag which recognize ad view int
Render When Loaded Choose if ad information is described right after ad load. bool Use this function if you want to display ads at specified timing
Render When Activated Choose if you draw ad information when GameObject becomes active bool Use this function if you want to display ads at specified timing
Advertising Explicitly Text which is displayed for Advertising Explicitly AdvertisingExplicitly
Ad Shown Event which is notified when ad is displayed UnityEvent<NendAdNativeView>
Ad Clicked Event which is notified when ad is clicked. UnityEvent<NendAdNativeView>

The following messages will be shown.

Items Message
PR PR
Sponsored Sponsored
AD 広告
Promotion プロモーション

IF in NendAdNativeView

You can use the following IF from app side.

public bool RenderAd ()

Draw ad which is already loaded. If ad is not loaded, it returns false.

public int ViewTag { get; set; }

get/set tags.

public bool Loaded { get; }

Acquire the status if ad is loaded or not.

Code sample to show ads at times you specified.
using UnityEngine;
using NendUnityPlugin.AD.Native;
...

public class YourScene : MonoBehaviour {

    // On the assumption that these are connected on Inspector
    public NendAdNativeView nativeAdView;

    private void DoSomething () {
        if (nativeAdView.Loaded) {
            nativeAdView.RenderAd ();
        }
    }
}
  1. Add NendAdNative to GameObject which you selected and which is within scene which displays ads. native_load_1

  2. Register NendAdNativeView which displays ad ID and Ads on NendAdNative Inspector. native_load_2

Item Explanation Type Supplement
Account apiKey and spotID of Android and iOS apiKey:string spotID:int OS which is not included in build does not need this setting.
Load When Activated If NendAdNative loads ads when GameObject becomes active. bool Load all ads registered on NendAdNativeView
Enable Auto Reload If ad is reloaded automatically bool Reload all ads redistered on NendAdNativeView
Reload Interval Auto reload interval(millisecond) double Must be 30 seconds or more
Views View which displays native ads NendAdNativeView Multiple settings are allowed
Ad Loaded Event which is notified when ad is loaded UnityEvent<NendAdNativeView>
Ad Failed To Receive Event which is notified when ad load failed. UnityEvent<NendAdNativeView, int, string> The second argument is error code and the third argument is error message.
The content of error code is as follows.
332: The number of ad display exceeded the maximum cap.
340: Request failed(communication error etc.)
341: inside SDK error
342: unsupported image format
type Ad space type NativeAdType Use this function to check ad display on Editor. It is not used when actual device works.

If Load When Activated is true and Render When Loaded of registered NendAdNativeView is true, native ad load and display is done automatically when GameObject with NendAdNative is read by scene.

Item Ad type
SmallSquare With ad image(80x80)
LargeWide With adimage(300x180)
TextOnly No ad image

About IF in NendAdNative class

You can use the following IF from app side.

public void LoadAd ()

Load all registered ads in NendAdNativeView.

public void LoadAd (int viewTag)

Load NendAdNativeView ads with specified tags

public NendAdNativeView[] Views { get; }

Acquire the list of registered NendAdNativeView

public void RegisterAdView (NendAdNativeView view)

Register NendAdNativeView which displays ads.

public void UnregisterAdView (NendAdNativeView view)

Delete registered NendAdNativeView.

public void EnableAutoReload (double interval)

Reload ads automatically by specified interval (millisecond).
Reload interval has to be 30 seconds or more.

public void DisableAutoReload ()

Stop auto ad reload.

Sample Code: Load NendAdNativeView ads which have not acquired ads.
using NendUnityPlugin.AD.Native;
...

// Acquiring instance from GameObject with NendAdNative.
var nativeAd = gameObject.GetComponet <NendAdNative> ();
foreach (var nativeAdView in nativeAd.Views) {
    if (!nativeAdView.Loaded) {
        nativeAd.LoadAd (nativeAdView.ViewTag);
    }
}
Sample Code: Auto reload/pause by move/return to background.
using UnityEngine;
using NendUnityPlugin.AD.Native;
...

public class YourScene : MonoBehaviour {

    // On the assumption that these are connected on Inspector
    public NendAdNative nativeAd;

    void OnApplicationPause (bool pauseStatus) {
        if (pauseStatus) {
            nativeAd.DisableAutoReload ();
        } else {
            // e.g. Reload every 1 min
            nativeAd.EnableAutoReload (60000.0);
        }
    }
}

Notes

  • Make sure to register EventSystem to the scenes which display ads.(Normally it is automatically registered when UI such as Canvas are added to scene)
  • Activate GraphicRaycaster of Canvas that display ads.

Verification

Clone this wiki locally