本指南适用于希望通过 Unity 应用获利的发布商。
要展示 Atmosplay 广告并赚取收入,第一步是将 Atmosplay 广告 Unity 插件集成到应用中(本页将介绍如何进行此项操作)。
完成集成后,您可以选择一种广告格式,如原生广告或激励视频广告,以获取详细的植入步骤。
借助 Atmosplay 移动广告 Unity 插件,Unity 开发者无需编写 Java 或 Objective-C 代码,即可轻松地在 Android 和 iOS 应用上投放 Atmosplay 移动广告。
该插件提供了一个 C# 界面,用于请求 Unity 项目中 C# 脚本使用的广告。
请通过如下链接下载该插件的 Unity 软件包,或在 GitHub 上查看其代码。
在 Unity 编辑器中打开您的项目,然后依次选择 Assets > Import Package > Custom Package,并找到您下载的 AtmosplayAds.unitypackage 文件。
确保选择所有文件,然后点击 Import。
Atmosplay 移动广告 Unity 插件随 Unity Play 服务解析器库一起发布。 此库旨在供需要访问 Android 特定库(例如 AAR)或 iOS CocoaPods 的所有 Unity 插件使用。它为 Unity 插件提供了声明依赖项的功能,然后依赖项会被自动解析并复制到 Unity 项目中。
请按照下列步骤操作,确保您的项目包含移动广告 SDK。
要使Atmosplay SDK能够使用MSA SDK获取OAID值,请将MSA SDK(AAR文件)复制到项目的Assets/Plugins/Android目录中。 您还需要将supplierconfig.json复制到项目的Assets/Plugins/Android/assets目录中。
MSA SDK详细说明和下载地址,请查看
您无需执行其他步骤即可将移动广告 SDK 加入 Unity 项目中。
注意:iOS 依赖项的标识是通过 CocoaPods 完成的,而 CocoaPods 是构建过程完成后的一个运行步骤。
在 Unity 编辑器中,依次选择 Assets > Play Services Resolver > Android Resolver > Resolve。
Unity Play 服务解析器库会将声明的依赖项复制到 Unity 应用的 Assets/Plugins/Android 目录中。
注意:Atmosplay 移动广告 Unity 插件依赖项位于 Assets/AtmosplayAds/Editor/AtmosplayAdsDependencies.xml 中
using System;
using UnityEngine;
using AtmosplayAds.Api;
using AtmosplayAds.Common;
public class AtmosplayAdsDemoScript : MonoBehaviour
{
#if UNITY_ANDROID
const string AtmosplayAds_App_ID = "Your_AtmosplayAds_App_ID_Android";
const string AtmosplayAds_AdUnit_ID = "Your_AtmosplayAds_AdUnit_ID_Android";
#elif UNITY_IOS
const string AtmosplayAds_App_ID = "Your_AtmosplayAds_App_ID_iOS";
const string AtmosplayAds_AdUnit_ID = "Your_AtmosplayAds_AdUnit_ID_iOS";
#else
const string AtmosplayAds_App_ID = "unexpected_platform";
const string AtmosplayAds_AdUnit_ID = "unexpected_platform";
#endif
BannerView bannerView;
void Start()
{
BannerViewOptions bannerOptions = new BannerViewOptionsBuilder()
.setAdPosition(AdPosition.BOTTOM)
.setChannelID(GlobleSettings.GetChannelId)
.setBannerSize(BannerAdSize.BANNER_AD_SIZE_320x50)
.Build();
bannerView = new BannerView(AtmosplayAds_App_ID, AtmosplayAds_AdUnit_ID, bannerOptions);
bannerView.OnAdLoaded += HandleBannerAdLoaded;
bannerView.OnAdFailedToLoad += HandleBannerAdFailedToLoad;
bannerView.OnAdClicked += HandleBannerClicked;
}
#region Banner callback handlers
public void HandleBannerAdLoaded(object sender, EventArgs args)
{
print("===> HandleBannerAdLoaded event received");
}
public void HandleBannerAdFailedToLoad(object sender, AdFailedEventArgs args)
{
print("===> HandleBannerAdFailedToLoad event received with message: " + args.Message);
}
public void HandleBannerClicked(object sender, EventArgs args)
{
print("===> HandleBannerClicked event received.");
}
#endregion
}
if (bannerView != null)
{
bannerView.LoadAd();
}
if (bannerView != null)
{
bannerView.Hide();
}
if (bannerView != null)
{
bannerView.Show();
}
if (bannerView != null)
{
bannerView.Destroy();
bannerView = null;
}
using System;
using UnityEngine;
using AtmosplayAds.Api;
using AtmosplayAds.Common;
public class AtmosplayAdsDemoScript : MonoBehaviour
{
#if UNITY_Android
const string AtmosplayAds_App_ID_Interstitial = "Your_AtmosplayAds_App_ID_Interstitial_Android";
const string AtmosplayAds_AdUnit_ID_Interstitial = "Your_AtmosplayAds_AdUnit_ID_Interstitial_Android";
#elif UNITY_IOS
const string AtmosplayAds_App_ID_Interstitial = "Your_AtmosplayAds_App_ID_Interstitial_iOS";
const string AtmosplayAds_AdUnit_ID_Interstitial = "Your_AtmosplayAds_AdUnit_ID_Interstitial_iOS";
#else
const string AtmosplayAds_App_ID_Interstitial = "unexpected_platform";
const string AtmosplayAds_AdUnit_ID_Interstitial = "unexpected_platform";
#endif
InterstitialAd interstitial;
void Start()
{
AdOptions adOptions = new AdOptionsBuilder()
.SetChannelId("")
.SetAutoLoadNext(true)
.build();
interstitial = new InterstitialAd(AtmosplayAds_App_ID_Interstitial, AtmosplayAds_AdUnit_ID_Interstitial, adOptions);
interstitial.OnAdLoaded += HandleInterstitialLoaded;
interstitial.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
interstitial.OnAdStarted += HandleInterstitialStart;
interstitial.OnAdClicked += HandleInterstitialClicked;
interstitial.OnAdClosed += HandleInterstitialClosed;
}
#region Interstitial callback handlers
public void HandleInterstitialLoaded(object sender, EventArgs args)
{
print("===> HandleInterstitialLoaded event received");
}
public void HandleInterstitialFailedToLoad(object sender, AdFailedEventArgs args)
{
print("===> HandleInterstitialFailedToLoad event received with message: " + args.Message);
}
public void HandleInterstitialStart(object sender, EventArgs args)
{
print("===> HandleInterstitialStart event received.");
}
public void HandleInterstitialClicked(object sender, EventArgs args)
{
print("===> HandleInterstitialClicked event received.");
}
public void HandleInterstitialClosed(object sender, EventArgs args)
{
print("===> HandleInterstitialClosed event received.");
}
#endregion
}
interstitial.LoadAd(AtmosplayAds_AdUnit_ID_Interstitial);
interstitial.IsReady(AtmosplayAds_AdUnit_ID_Interstitial)
if(interstitial.IsReady(AtmosplayAds_AdUnit_ID_Interstitial))
{
interstitial.Show(AtmosplayAds_AdUnit_ID_Interstitial);
}
using System;
using UnityEngine;
using AtmosplayAds.Api;
using AtmosplayAds.Common;
public class AtmosplayAdsDemoScript : MonoBehaviour
{
#if UNITY_ANDROID
const string AtmosplayAds_App_ID_Rewarded = "Your_AtmosplayAds_App_ID_Rewarded_Android";
const string AtmosplayAds_AdUnit_ID_Rewarded = "Your_AtmosplayAds_AdUnit_ID_Rewarded_Android";
#elif UNITY_IOS
const string AtmosplayAds_App_ID_Rewarded = "Your_AtmosplayAds_App_ID_Rewarded_iOS";
const string AtmosplayAds_AdUnit_ID_Rewarded = "Your_AtmosplayAds_AdUnit_ID_Rewarded_iOS";
#else
const string AtmosplayAds_App_ID_Rewarded = "unexpected_platform";
const string AtmosplayAds_AdUnit_ID_Rewarded = "unexpected_platform";
#endif
RewardVideoAd rewardVideo;
void Start()
{
AdOptions adOptions = new AdOptionsBuilder()
.SetChannelId("")
.SetAutoLoadNext(true)
.build();
rewardVideo = new RewardVideoAd(AtmosplayAds_App_ID_Rewarded, AtmosplayAds_AdUnit_ID_Rewarded, adOptions);
rewardVideo.OnAdLoaded += HandleRewardVideoLoaded;
rewardVideo.OnAdFailedToLoad += HandleRewardVideoFailedToLoad;
rewardVideo.OnAdStarted += HandleRewardVideoStart;
rewardVideo.OnAdClicked += HandleRewardVideoClicked;
rewardVideo.OnAdRewarded += HandleRewardVideoRewarded;
rewardVideo.OnAdClosed += HandleRewardVideoClosed;
}
#region RewardVideo callback handlers
public void HandleRewardVideoLoaded(object sender, EventArgs args)
{
print("===> HandleRewardVideoLoaded event received");
}
public void HandleRewardVideoFailedToLoad(object sender, AdFailedEventArgs args)
{
print("===> HandleRewardVideoFailedToLoad event received with message: " + args.Message);
}
public void HandleRewardVideoStart(object sender, EventArgs args)
{
print("===> HandleRewardVideoStart event received.");
}
public void HandleRewardVideoClicked(object sender, EventArgs args)
{
print("===> HandleRewardVideoClicked event received.");
}
public void HandleRewardVideoRewarded(object sender, EventArgs args)
{
print("===> HandleRewardVideoRewarded event received.");
}
public void HandleRewardVideoClosed(object sender, EventArgs args)
{
print("===> HandleRewardVideoClosed event received.");
}
#endregion
}
rewardVideo.LoadAd(AtmosplayAds_AdUnit_ID_Rewarded);
rewardVideo.IsReady(AtmosplayAds_AdUnit_ID_Rewarded)
if(rewardVideo.IsReady(AtmosplayAds_AdUnit_ID_Rewarded))
{
rewardVideo.Show(AtmosplayAds_AdUnit_ID_Rewarded);
}
using System;
using UnityEngine;
using AtmosplayAds.Api;
using AtmosplayAds.Common;
public class AtmosplayFloatAdSceneScript : MonoBehaviour
{
#if UNITY_ANDROID
const string AtmosplayAds_App_ID_FloatAd = "Your_AtmosplayAds_App_ID_FloatAd_Android";
const string AtmosplayAds_AdUnit_ID_FloatAd = "Your_AtmosplayAds_AdUnit_ID_FloatAd_Android";
#elif UNITY_IOS
const string AtmosplayAds_App_ID_FloatAd = "Your_AtmosplayAds_App_ID_FloatAd_iOS";
const string AtmosplayAds_AdUnit_ID_FloatAd = "Your_AtmosplayAds_AdUnit_ID_FloatAd_iOS";
#else
const string AtmosplayAds_App_ID_FloatAd = "unexpected_platform";
const string AtmosplayAds_AdUnit_ID_FloatAd = "unexpected_platform";
#endif
FloatAd floatAd;
void Start()
{
AdOptions adOptions = new AdOptionsBuilder()
.SetChannelId("")
.SetAutoLoadNext(true)
.build();
//After creating the FloatAd object, the SDK will start requesting ads
floatAd = new FloatAd(AtmosplayAds_App_ID_FloatAd, AtmosplayAds_AdUnit_ID_FloatAd, gameObject, adOptions);
floatAd.OnAdLoaded += HandleFloatAdLoaded;
floatAd.OnAdFailedToLoad += HandleFloatAdFailedToLoad;
floatAd.OnAdStarted += HandleFloatAdStart;
floatAd.OnAdClicked += HandleFloatAdClicked;
floatAd.OnAdRewarded += HandleFloatAdRewarded;
floatAd.OnAdClosed += HandleFloatAdClosed;
}
#region FloatAd callback handlers
public void HandleFloatAdLoaded(object sender, EventArgs args)
{
print("atmosplay---HandleFloatAdLoaded");
}
public void HandleFloatAdFailedToLoad(object sender, AdFailedEventArgs args)
{
print("atmosplay---HandleFloatAdFailedToLoad:" + args.Message);
}
public void HandleFloatAdStart(object sender, EventArgs args)
{
print("atmosplay---HandleFloatAdStart");
}
public void HandleFloatAdClicked(object sender, EventArgs args)
{
print("atmosplay---HandleFloatAdClicked");
}
public void HandleFloatAdRewarded(object sender, EventArgs args)
{
print("atmosplay---HandleFloatAdRewarded");
}
public void HandleFloatAdClosed(object sender, EventArgs args)
{
print("atmosplay---HandleFloatAdClosed");
}
#endregion
}
if (floatAd != null)
{
floatAd.IsReady(AtmosplayAds_AdUnit_ID_FloatAd)
}
首先请在游戏中需要展示浮标广告的位置创建一个floatAdView GameObjet:
if (floatAd != null)
{
floatAd.SetPointAndWidth(floatAdView.transform);
}
注意:
初始化后的第一次展示调用此方法。
如需更新位置,请调用 UpdatePointAndWidth
,
如隐藏后再次展示,请调用 ShowAgainAfterHiding
。
if (floatAd != null)
{
if(floatAd.IsReady(AtmosplayAds_AdUnit_ID_FloatAd))
{
floatAd.Show(AtmosplayAds_AdUnit_ID_FloatAd);
}
}
//如果你想更新浮标广告的位置和大小,请先更新游戏中floatAdView GameObject的位置和大小,然后使用下面的接口将浮标广告更新到新的位置
if (floatAd != null)
{
floatAd.UpdatePointAndWidth(floatAdView.transform);
}
if (floatAd != null)
{
floatAd.Hide();
}
注意: 此方法仅适用于隐藏之后再次展示。
if (floatAd != null)
{
floatAd.ShowAgainAfterHiding();
}
if (floatAd != null)
{
floatAd.Destroy();
floatAd = null;
}
using System;
using UnityEngine;
using AtmosplayAds.Api;
using AtmosplayAds.Common;
public class AtmosplayWindowAdSceneScript : MonoBehaviour
{
#if UNITY_ANDROID
const string AtmosplayAds_App_ID_WindowAd = "Your_AtmosplayAds_App_ID_WindowAd_Android";
const string AtmosplayAds_AdUnit_ID_WindowAd = "Your_AtmosplayAds_AdUnit_ID_WindowAd_Android";
#elif UNITY_IOS
const string AtmosplayAds_App_ID_WindowAd = "Your_AtmosplayAds_App_ID_WindowAd_iOS";
const string AtmosplayAds_AdUnit_ID_WindowAd = "Your_AtmosplayAds_AdUnit_ID_WindowAd_iOS";
#else
const string AtmosplayAds_App_ID_WindowAd = "unexpected_platform";
const string AtmosplayAds_AdUnit_ID_WindowAd = "unexpected_platform";
#endif
WindowAd windowAd;
void Start()
{
AdOptions adOptions = new AdOptionsBuilder()
.SetChannelId("")
.build();
//After creating the WindowAd object, the SDK will start requesting ads
windowAd = new WindowAd(AtmosplayAds_App_ID_WindowAd, AtmosplayAds_AdUnit_ID_WindowAd, gameObject, adOptions);
windowAd.OnAdLoaded += HandleWindowAdLoaded;
windowAd.OnAdFailedToLoad += HandleWindowAdFailedToLoad;
windowAd.OnAdStarted += HandleWindowAdStart;
windowAd.OnAdClicked += HandleWindowAdClicked;
windowAd.OnAdFinished += HandleWindowAdFinished;
windowAd.OnAdClosed += HandleWindowAdClosed;
windowAd.OnAdFailToShow += HandleWindowAdFailToShow;
}
#region WindowAd callback handlers
public void HandleWindowAdLoaded(object sender, EventArgs args)
{
print("atmosplay---HandleWindowAdLoaded");
}
public void HandleWindowAdFailedToLoad(object sender, AdFailedEventArgs args)
{
print("atmosplay---HandleWindowAdFailedToLoad:" + args.Message);
}
public void HandleWindowAdStart(object sender, EventArgs args)
{
print("atmosplay---HandleWindowAdStart");
}
public void HandleWindowAdClicked(object sender, EventArgs args)
{
print("atmosplay---HandleWindowAdClicked");
}
public void HandleWindowAdFinished(object sender, EventArgs args)
{
print("atmosplay---HandleWindowAdFinished");
}
public void HandleWindowAdClosed(object sender, EventArgs args)
{
print("atmosplay---HandleWindowAdClosed");
}
public void HandleWindowAdFailToShow(object sender, EventArgs args)
{
print("atmosplay---HandleWindowAdFailToShow");
}
#endregion
}
if (windowAd != null)
{
windowAd.IsReady()
}
首先请在游戏中需要展示窗口广告的位置创建一个GameObjet:
注意:
展示后会自动加载下一条广告。
if (windowAd != null)
{
if(windowAd.IsReady())
{
// 1. 您所创建GameObject的transform
// 2. 窗口广告倾斜角度,仅iOS支持
windowAd.Show(windowAdView.transform, angleNumber);
}
}
if (windowAd != null)
{
windowAd.Close();
}
if (windowAd != null)
{
windowAd.Destroy();
windowAd = null;
}
OS | Ad Format | App_ID | Ad_Unit_ID |
---|---|---|---|
iOS | Banner | A650AB0D-7BFC-2A81-3066-D3170947C3DA | A49521F3-339D-994F-FC80-F9C4170AA0CF |
iOS | Rewarded Video | A650AB0D-7BFC-2A81-3066-D3170947C3DA | BAE5DAAC-04A2-2591-D5B0-38FA846E45E7 |
iOS | Interstitial | A650AB0D-7BFC-2A81-3066-D3170947C3DA | 0868EBC0-7768-40CA-4226-F9924221C8EB |
iOS | FloatAd | A650AB0D-7BFC-2A81-3066-D3170947C3DA | CF41E96F-D020-2AD1-9144-396D2585915E |
iOS | WindowAd | A650AB0D-7BFC-2A81-3066-D3170947C3DA | 5D6D4B21-45B0-F76E-580C-F975B47C0388 |
Android | Banner | 5C5419C7-A2DE-88BC-A311-C3E7A646F6AF | F22F347B-3D57-0C70-0B13-EFCFDF402EBA |
Android | Rewarded Video | 5C5419C7-A2DE-88BC-A311-C3E7A646F6AF | 3FBEFA05-3A8B-2122-24C7-A87D0BC9FEEC |
Android | Interstitial | 5C5419C7-A2DE-88BC-A311-C3E7A646F6AF | 19393189-C4EB-3886-60B9-13B39407064E |
Android | FloatAd | 5C5419C7-A2DE-88BC-A311-C3E7A646F6AF | 6324B007-21F2-963D-8514-977390BBD341 |
Android | WindowAd | 5C5419C7-A2DE-88BC-A311-C3E7A646F6AF | 86B87233-E2EF-C428-A35B-C736E23C8515 |