Note for Android:
Currently, using Unity to directly build an Android APK cannot use native video ads, because Unity packages the APK with the game's Activity hardware acceleration turned off by default, making it impossible to display video. If you need to display native ad videos, you must use the export project method. The handling method is as follows:
(1) Select the Export Project mode to export the Android project.
(2) Modify the properties in AndroidManifest and set the hardwareAccelerated property shown in the image to true.
After completing the above steps, use the current Android project for packaging.
ATNativeAd:
| API | Parameters | Description |
|---|---|---|
| loadNativeAd | string placementid, Dictionary | Load an ad (Starting from v5.6.8, for Pangle template rendering, Mintegral auto-render ads, etc., the width and height must be passed through the extra parameter; otherwise, the ad size may display abnormally.) |
| setListener | ATNativeAdListener listener | Set the listener callback interface (deprecated after version 5.9.51) |
| hasAdReady | string placementid | Check if there is an ad cache |
| renderAdToScene | string placementid, ATNativeAdView anyThinkNativeAdView | Display the ad |
| entryScenarioWithPlacementID | string placementId, string scenarioID | Set entry into a displayable ad scenario |
You can use the following code to load a native ad:
public void loadNative()
{
Debug.Log ("Developer load native, unit id = " + mPlacementId_native_all);
ATNativeAd.Instance.client.onAdLoadEvent += onAdLoad;
ATNativeAd.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
ATNativeAd.Instance.client.onAdImpressEvent += onAdImpressed;
ATNativeAd.Instance.client.onAdClickEvent += onAdClick;
ATNativeAd.Instance.client.onAdCloseEvent += onAdClose;
ATNativeAd.Instance.client.onAdVideoStartEvent += onAdVideoStart;
ATNativeAd.Instance.client.onAdVideoEndEvent += onAdVideoEnd;
ATNativeAd.Instance.client.onAdVideoProgressEvent += onAdVideoProgress;
//----- v5.6.8 and above -----
Dictionary jsonmap = new Dictionary();
#if UNITY_ANDROID
ATSize nativeSize = new ATSize(width, height);
jsonmap.Add(ATNativeAdLoadingExtra.kATNativeAdLoadingExtraNativeAdSizeStruct, nativeSize);
#elif UNITY_IOS || UNITY_IPHONE
ATSize nativeSize = new ATSize(width, height, false);
jsonmap.Add(ATNativeAdLoadingExtra.kATNativeAdLoadingExtraNativeAdSizeStruct, nativeSize);
ATNativeAd.Instance.loadNativeAd(mPlacementId_native_all, jsonmap);
}
Note: Please continue reading to learn how to be notified on load success/failure events.
ATNativeAd.Instance.hasAdReady(mPlacementId_native_all);
You can use the following code to display a native ad:
public void showNative()
{
Debug.Log ("Developer show native....");
ATNativeConfig conifg = new ATNativeConfig ();
string bgcolor = "#ffffff";
string textcolor = "#000000";
int rootbasex = 100, rootbasey = 100;
int x = rootbasex,y = rootbasey,width = 300*3,height = 200*3,textsize = 17;
conifg.parentProperty = new ATNativeItemProperty(x,y,width,height,bgcolor,textcolor,textsize, true);
//adlogo
x = 0*3;y = 0*3;width = 30*3;height = 20*3;textsize = 17;
conifg.adLogoProperty = new ATNativeItemProperty(x,y,width,height,bgcolor,textcolor,textsize, true);
//adicon
x = 0*3;y = 50*3-50;width = 60*3;height = 50*3;textsize = 17;
conifg.appIconProperty = new ATNativeItemProperty(x,y,width,height,bgcolor,textcolor,textsize, true);
//ad cta
x = 0*3;y = 150*3;width = 300*3;height = 50*3;textsize = 17;
conifg.ctaButtonProperty = new ATNativeItemProperty(x,y,width,height,"#ff21bcab","#ffffff",textsize, true);
//ad desc
x = 60*3;y = 100*3;width = 240*3-20;height = 50*3-10;textsize = 10;
conifg.descProperty = new ATNativeItemProperty(x,y,width,height,bgcolor,"#777777",textsize, true);
//ad image
x = 60*3;y = 0*3+20;width = 240*3-20;height = 100*3-10;textsize = 17;
conifg.mainImageProperty = new ATNativeItemProperty(x,y,width,height,bgcolor,textcolor,textsize, true);
//ad title
x = 0*3;y = 100*3;width = 60*3;height = 50*3;textsize = 12;
conifg.titleProperty = new ATNativeItemProperty(x,y,width,height,bgcolor,textcolor,textsize, true);
//(Added in v5.7.21)ad dislike button (close button)
x = 300*3 - 75;y = 0;width = 75;height = 75;
conifg.dislikeButtonProperty = new ATNativeItemProperty(x,y,width,height,"#00000000",textcolor,textsize, true);
ATNativeAdView anyThinkNativeAdView = new ATNativeAdView(conifg);
AnyThinkAds.Demo.ATManager.anyThinkNativeAdView = anyThinkNativeAdView;
Debug.Log("Developer renderAdToScene--->");
ATNativeAd.Instance.renderAdToScene(mPlacementId_native_all, anyThinkNativeAdView);
}
When using the scenario feature:
public void showNative()
{
...
Dictionary jsonmap = new Dictionary();
jsonmap.Add(AnyThinkAds.Api.ATConst.SCENARIO, showingScenarioID);
ATNativeAd.Instance.renderAdToScene(mPlacementId_native_all, anyThinkNativeAdView, jsonmap);
}
The trailing parameter passed to the ATNativeItemProperty class constructor indicates whether to use pixels (only effective for iOS). For example, on an iPhone 6, if you pass 30, 120, 300, 450 for x, y, width, and height respectively, the actual values passed to the Objective-C code on an iPhone 7 will be 15, 60, 150, 225; these values will be 10, 40, 100, 150; that is, the final values depend on the screen ratio of the target device.
As you can see above, we have defined an ATNativeConfig class for you to configure various properties of native ad assets (bgColor, textColor, textSize, position, etc.), such as the CTA button, app icon, title text, description text, cover image, and so on. Feel free to modify the properties in the config object and see what happens based on your modifications.
ATNativeConfig contains multiple ATNativeItemProperty objects, used to control the style of the Native ad. ATNativeItemProperty controls the position and style of a single Native ad element; some elements may not support some properties in ATNativeItemProperty. For example, image elements (icon, main image) only support x, y, width, height, and usesPixel, but do not support background color, font size, and font color, whereas text elements (such as title, cta, desc) support all properties. In iOS games, if you want to specify "transparent", use "clearColor". For example, if you want the background of the ad area to be transparent, assign "clearColor" to the backgroundColor of parentProperty. Note: 1) Only iOS supports clearColor. For Android, if you need to specify a transparent background, simply set the alpha part in rgba to 0; 2) iOS does not support alpha, so the color value should be passed like #5aef00 (six-digit RGB value), while Android can support alpha, with its color containing 8 hexadecimal digits, such as 5a2b3c00.
parentProperty
parentProperty controls the overall size of the Native ad, as shown in the red circled area below.

Native ad element descriptions are as follows:
Note: All of the above Native ad elements, when returned, need to be rendered.

To remove a native ad from the screen, use the following code:
public void cleanView()
{
Debug.Log ("Developer cleanView native....");
ATNativeAd.Instance.cleanAdView(mPlacementId_native_all,AnyThinkAds.Demo.ATManager.anyThinkNativeAdView);
}
Dictionary jsonmap = new Dictionary();
#if UNITY_ANDROID
ATSize nativeSize = new ATSize(width, height);
jsonmap.Add(ATNativeAdLoadingExtra.kATNativeAdLoadingExtraNativeAdSizeStruct, nativeSize);
jsonmap.Add(AnyThinkAds.Api.ATConst.ADAPTIVE_HEIGHT, AnyThinkAds.Api.ATConst.ADAPTIVE_HEIGHT_YES);
...
ATNativeAd.Instance.loadNativeAd(mPlacementId_native_all, jsonmap);
...
Dictionary jsonmap = new Dictionary();
jsonmap.Add(AnyThinkAds.Api.ATConst.ADAPTIVE_HEIGHT, AnyThinkAds.Api.ATConst.ADAPTIVE_HEIGHT_YES);
ATNativeAd.Instance.renderAdToScene(mPlacementId_native_all, anyThinkNativeAdView, jsonmap);
...
Dictionary jsonmap = new Dictionary();
jsonmap.Add(AnyThinkAds.Api.ATConst.POSITION, AnyThinkAds.Api.ATConst.POSITION_BOTTOM);//Centered at the bottom of the screen
//jsonmap.Add(AnyThinkAds.Api.ATConst.POSITION, AnyThinkAds.Api.ATConst.POSITION_TOP);//Centered at the top of the screen
ATNativeAd.Instance.renderAdToScene(mPlacementId_native_all, anyThinkNativeAdView, jsonmap);
For callback information details, please see: Callback Information Description
Use the following code to implement multiple listeners:
// Ad loading succeeded
ATNativeAd.Instance.client.onAdLoadEvent += onAdLoad;
// Ad loading failed
ATNativeAd.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
// Ad display succeeded
ATNativeAd.Instance.client.onAdImpressEvent += onAdImpressed;
// Ad clicked
ATNativeAd.Instance.client.onAdClickEvent += onAdClick;
// Ad close button was clicked (some ad networks have this callback)
ATNativeAd.Instance.client.onAdCloseEvent += onAdClose;
// Ad video started playing (some ad networks have this callback)
ATNativeAd.Instance.client.onAdVideoStartEvent += onAdVideoStart;
// Ad video finished playing (some ad networks have this callback)
ATNativeAd.Instance.client.onAdVideoEndEvent += onAdVideoEnd;
// Ad video playback progress (some ad networks have this callback)
ATNativeAd.Instance.client.onAdVideoProgressEvent += onAdVideoProgress;
The method parameter definitions are as follows in the code (Note: The method name can follow the code below or be a custom method name, but the parameters must be consistent.):
// sender is the ad type object, erg is the returned information
// Ad loading succeeded
public void onAdLoad(object sender, ATAdEventArgs erg)
{
Debug.Log("Developer onAdLoaded------:" + erg.placementId);
}
// Ad loading failed
public void onAdLoadFail(object sender, ATAdEventArgs erg)
{
Debug.Log("Developer onAdLoadFail------:" + erg.placementId + "--code:" + erg.code + "--msg:" + erg.message);
}
// Ad display succeeded
public void onAdImpressed(object sender, ATAdEventArgs erg)
{
Debug.Log("Developer onAdImpressed------:" + erg.placementId);
}
// Ad clicked
public void onAdClicked(object sender, ATAdEventArgs erg)
{
Debug.Log("Developer onAdClicked------:" + erg.placementId);
}
// Ad video started playing (some ad networks have this callback)
public void onAdVideoStart(object sender, ATAdEventArgs erg)
{
Debug.Log("Developer onAdVideoStart------:" + erg.placementId);
}
// Ad video finished playing (some ad networks have this callback)
public void onAdVideoEnd(object sender, ATAdEventArgs erg)
{
Debug.Log("Developer onAdVideoEnd------:" + erg.placementId);
}
// Ad video playback progress (some ad networks have this callback)
public void onAdVideoProgress(object sender, ATAdProgressEventArgs erg)
{
Debug.Log("Developer onAdVideoProgress------:" + erg.placementId);
}
// Ad close button was clicked (some ad networks have this callback)
public void onAdCloseButtonClicked(object sender, ATAdEventArgs erg)
{
Debug.Log("Developer onAdCloseButtonClicked------:" + erg.placementId);
}