当前位置:网站首页>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
边栏推荐
- 推开机电的大门《电路》(二):功率计算与判断
- Mapreduce环境详细搭建和案例实现
- Use tencent cloud builds a personal blog
- 第三十章:普通树的存储和遍历
- MATLAB drawing command fimplicit detailed introduction to drawing implicit function graphics
- Win11 system cannot find dll file how to fix
- Fast advanced TypeScript
- 第三十二章:二叉树的存储与遍历
- Introduction to MATLAB drawing functions ezplot explanation
- mysql的索引结构为什么选用B+树?
猜你喜欢

Introduction to C language function parameter passing mode

Win11 system cannot find dll file how to fix

cmake配置libtorch报错Failed to compute shorthash for libnvrtc.so

STM32LL库——USART中断接收不定长信息

Redis common interview questions

STM32LL库使用——SPI通信

4. Publish Posts, Comment on Posts

将SSE指令转换为ARM NEON指令

MATLAB绘图函数ezplot入门详解

Based on the matrix calculation in the linear regression equation of the coefficient estimates
随机推荐
Codeforces Round #605 (Div. 3)
Network Security Packet Capture
Compilation error D8021: Invalid numeric argument '/Wextra' cl command line error d8021 invalid numeric argument '/Wextra'
Open the door of power and electricity "Circuit" (2): Power Calculation and Judgment
模板系列-二分
测试用例练习
关于混淆的问题
STM32LL库使用——SPI通信
Detailed introduction to the hierarchical method of binary tree creation
二叉排序树与 set、map
LeetCode 2354. 优质数对的数目 二进制01表示和集合之间的转换
MATLAB制作简易小动画入门详解
2021-06-06
Mapreduce环境详细搭建和案例实现
MATLAB drawing command fimplicit detailed introduction to drawing implicit function graphics
Test case exercises
cmake configure libtorch error Failed to compute shorthash for libnvrtc.so
【离散化+前缀和】Acwing802. 区间和
General code for pytorch model to libtorch and onnx format
计算机导论——数据库