当前位置:网站首页>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
边栏推荐
- 基于矩阵计算的线性回归分析方程中系数的估计
- Happy, 9/28 scene collection
- mysql学习总结 & 索引
- Based on the matrix calculation in the linear regression equation of the coefficient estimates
- Detailed explanation of MATLAB drawing function fplot
- word方框怎么打勾?
- 剑指offer:反转链表
- 第三十章:普通树的存储和遍历
- Redis common interview questions
- couldn't find 'libflutter.so' --flutter
猜你喜欢
随机推荐
LeetCode 2343. 裁剪数字后查询第 K 小的数字 暴力+语法考察
LeetCode 2344. 使数组可以被整除的最少删除次数 最大公约数
Golang 垃圾回收机制详解
【STM32学习1】基础知识与概念明晰
推开机电的大门《电路》(一):电压,电流,参考方向
pygame绘制弧线
Mysql之MVCC
MATLAB绘制平面填充图入门详解
What should I do if the Win10 system sets the application identity to automatically prompt for access denied?
General code for pytorch model to libtorch and onnx format
背包问题-动态规划-理论篇
一篇文章彻底理解Redis的持久化:RDB、AOF
jest test, component test
Detailed introduction to the hierarchical method of binary tree creation
MATLAB绘图函数fplot详解
Mysql lock
Open the door to electricity "Circuit" (3): Talk about different resistance and conductance
第二十九章:树的基本概念和性质
模板系列-二分
Please make sure you have the correct access rights and the repository exists. Problem solved









