当前位置:网站首页>Unity-Ads广告插件
Unity-Ads广告插件
2022-08-02 14:11:00 【莉萝爱萝莉】
1. 开始准备
- 在包管理器中,选择 Advertisement 并导入,将广告插件引入工程。
- 在官方的平台 链接 上,登录自己的unity账号
- 为你的创建一个工程,并设定是否针对13岁以下儿童展示。
- 点击左下角的 monetization (ad Units),点击 Enable Abs 启用广告。
Mediation Partner 设定是否除了Unity广告外还囊括了其他广告 - 编译器内点击右上角 云 ,选择广告。随后 使用现有账户->用户->工程->连接!
这时便已经开启了广告功能
2. 编写脚本
// 添加广告的事件监听
public class ADManager : MonoBehaviour, IUnityAdsListener
{
// 不同环境使用不同ID
#if UNITY_IOS
string gameId = "4655802";
string myPlacementId = "Rewarded_iOS";
string myBannerId = "Banner_iOS";
#elif UNITY_ANDROID
string gameId = "4655803";
string myPlacementId = "Rewarded_Android";
string myBannerId = "Banner_Android";
#endif
[SerializeField] Button btn_fullad;
void Start()
{
// 初始化广告插件
Advertisement.AddListener(this);
Advertisement.Initialize(gameId, true);
btn_fullad.interactable = Advertisement.IsReady(myPlacementId);
btn_fullad.onClick.AddListener(ShowFullVideo);
ShowHorizontalVideo();
}
public void OnUnityAdsDidError(string message) {
}
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
switch (showResult)
{
case ShowResult.Failed:
Debug.Log("显示错误");
break;
case ShowResult.Skipped:
Debug.Log("广告跳过");
break;
case ShowResult.Finished:
Debug.Log("广告结束");
break;
default:
break;
}
}
public void OnUnityAdsDidStart(string placementId){
}
public void OnUnityAdsReady(string placementId)
{
Debug.Log("准备完毕");
btn_fullad.interactable = Advertisement.IsReady(myPlacementId);
}
// 全屏广告
public void ShowFullVideo()
{
Advertisement.Show(myPlacementId);
}
// 条幅广告
public async void ShowHorizontalVideo()
{
await UniTask.WaitUntil(() => Advertisement.IsReady(myBannerId));
Advertisement.Banner.SetPosition(BannerPosition.TOP_CENTER);
Advertisement.Banner.Show(myBannerId);
}
}
3. 将测试广告转变为真实广告
- 在 monetization (Settings)中,将 Test mode 的 Play Store 设置为 Override client test mode -> Force test mode OFF (i.e. use real ads) for all devices
边栏推荐
猜你喜欢
随机推荐
Summarize computer network super comprehensive test questions
pygame图像连续旋转
动态规划理论篇
远程连接Ubuntu中的Mysql
Mysql的锁
Redis common interview questions
MATLAB图形加标注的基本方法入门简介
What should I do if Windows 10 cannot connect to the printer?Solutions for not using the printer
Codeforces Round #605 (Div. 3)
MATLAB绘图函数fplot详解
pygame image rotate continuously
线性结构,顺序结构
模板系列-并查集
推开机电的大门《电路》(一):电压,电流,参考方向
What are IPV4 and IPV6?
Spark及相关生态组件安装配置——快速回忆
What should I do if I install a solid-state drive in Win10 and still have obvious lags?
Introduction to in-order traversal (non-recursive, recursive) after binary tree traversal
What should I do if the Win10 system sets the application identity to automatically prompt for access denied?
基于最小二乘法的线性回归分析方程中系数的估计