当前位置: 首页 > news >正文

【Unity】Unity中接入Admob聚合广告平台,可通过中介接入 AppLovin,Unity Ads,Meta等渠道的广告

一、下载Google Admob的SDK插件

到Google Admob官网中,切换到Unity平台在这里插入图片描述

进来之后是这样,注意后面有Unity标识,然后点击下载,跳转到github中,下载最新的Admob插件sdk,导入到Unity中在这里插入图片描述

二、阅读官方文档,了解广告加载流程

通过阅读官方文档,我们可以了解到其中有针对各类广告的Ios和Android的测试广告单元id,这对我们刚接入时测试阶段很有必要
在这里插入图片描述

然后我们以激励广告为例,可以看到接入激励广告的详细流程,官方下面也提供了所有流程的详细代码,其实如果没有特殊需求,官方的代码可以直接复制到我们的项目中就能使用
在这里插入图片描述

三、通过中介接入各渠道的广告

通过Admob中的中介就能接入各渠道的广告,当展示广告时候,他们会自动竞价,展示价格最高的广告。这里我们点击图中箭头,就可以下载对应渠道的最新版本的SDK插件,然后导入到Unity中即可,不需要任何设置,聚合平台会自动调取对应的广告渠道进行展示
在这里插入图片描述
下面是我导入到Unity中的所有插件
在这里插入图片描述
好了,到这里前端的准备基本结束了,相关的插件也都导入完毕了,如果是个人做游戏的话,自己到Admob后台注册对应的账号和Appid以及各个广告位的广告id,以及中介平台的各种广告id和相关联的功能,公司做游戏的话,这些各种id让对应的后台运营人员给到自己就好了,这里只介绍前端程序的相关内容,具体的id申请自行到后台操作一下

四、代码接入

该代码仅在测试阶段,通过官方的测试广告单元id全部通过,展示了出来,包括Banner,激励广告,插屏广告,详细内容根据自己的项目而定

using GoogleMobileAds.Api;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class AdManager : Singleton<AdManager>
{private int sdkInitializedState = -1;//0--unconsent 1--consenprivate string ADMobRewardUnit = "ca-app-pub-3940256099942544/5224354917";private string ADMobInterstitialUnit = "ca-app-pub-3940256099942544/1033173712";private string ADMobBannerUnit = "ca-app-pub-3940256099942544/6300978111";private RewardedAd _rewardedAd = null;private InterstitialAd _interstitialAd = null;private BannerView _bannerView;private int tryInteTimes = 0;private int loadInteTimes = 1;private int tryTimes = 0;private int maxTryTimes = 0;private int loadTimes = 1;private void Start(){Init();}public void Init(){MobileAds.RaiseAdEventsOnUnityMainThread = true;MobileAds.Initialize((InitializationStatus initStatus) =>{// This callback is called once the MobileAds SDK is initialized.sdkInitializedState = 1;PrepareRewardAds();PrepareInterAds();});}private void PrepareRewardAds(){if (sdkInitializedState < 0)return;if (_rewardedAd != null){_rewardedAd.Destroy();_rewardedAd = null;}var adRequest = new AdRequest();RewardedAd.Load(ADMobRewardUnit, adRequest,(RewardedAd ad, LoadAdError error) =>{// if error is not null, the load request failed.if (error != null || ad == null){Debug.LogError("Rewarded ad failed to load an ad with error : " + error);return;}Debug.Log("Rewarded ad loaded with response : " + ad.GetResponseInfo());_rewardedAd = ad;});}private void PrepareInterAds(){if (sdkInitializedState < 0)return;if (_interstitialAd != null){_interstitialAd.Destroy();_interstitialAd = null;}// create our request used to load the ad.var adRequest = new AdRequest();// send the request to load the ad.InterstitialAd.Load(ADMobInterstitialUnit, adRequest,(InterstitialAd ad, LoadAdError error) =>{// if error is not null, the load request failed.if (error != null || ad == null){Debug.LogError("interstitial ad failed to load an ad with error : " + error);return;}Debug.Log("Interstitial ad loaded with response : " + ad.GetResponseInfo());_interstitialAd = ad;});}[ContextMenu("测试Banner")]public void LoadBannerAd(){// create an instance of a banner view first.if (_bannerView == null){CreateBannerView();}// create our request used to load the ad.var adRequest = new AdRequest();// send the request to load the ad.Debug.Log("Loading banner ad.");_bannerView.LoadAd(adRequest);}/// <summary>/// Creates a 320x50 banner view at top of the screen./// </summary>private void CreateBannerView(){Debug.Log("Creating banner view");// If we already have a banner, destroy the old one.if (_bannerView != null){_bannerView.Destroy();}// Create a 320x50 banner at top of the screen_bannerView = new BannerView(ADMobBannerUnit, AdSize.Banner, AdPosition.Bottom);}[ContextMenu("测试插屏广告")]public void ShowInterAD(){if (_interstitialAd != null && _interstitialAd.CanShowAd()){// SetAdmobInterstitialListener(_interstitialAd);_interstitialAd.Show();}else{if (++this.tryInteTimes >= this.maxTryTimes){this.loadInteTimes = 3;this.PrepareInterAds();this.tryInteTimes = 0;}return;}}public void ShowRewardAD(Action successCallback){if (_rewardedAd != null && _rewardedAd.CanShowAd()){SetAdmobRewardListener(_rewardedAd);_rewardedAd.Show((Reward reward) =>{successCallback();});}}private void SetAdmobRewardListener(RewardedAd ad){// Raised when a click is recorded for an ad.ad.OnAdClicked += () =>{//RewardedAdClicked();};// Raised when an ad opened full screen content.ad.OnAdFullScreenContentOpened += () =>{Debug.Log("Rewarded ad full screen content opened.");};// Raised when the ad closed full screen content.ad.OnAdFullScreenContentClosed += () =>{PrepareRewardAds();//RewardedAdClosed();};// Raised when the ad failed to open full screen content.ad.OnAdFullScreenContentFailed += (AdError error) =>{Debug.LogError("Rewarded ad failed to open full screen content with error : " + error);// RewardedAdFailed();PrepareRewardAds();};}private void SetAdmobInterstitialListener(InterstitialAd interstitialAd){// Raised when a click is recorded for an ad.interstitialAd.OnAdClicked += () =>{Debug.Log("Interstitial ad was clicked.");//InterstitialAdClicked();};// Raised when an ad opened full screen content.interstitialAd.OnAdFullScreenContentOpened += () =>{Debug.Log("Interstitial ad full screen content opened.");// InterstitialAdDisplayed();};// Raised when the ad closed full screen content.interstitialAd.OnAdFullScreenContentClosed += () =>{Debug.Log("Interstitial ad full screen content closed.");//InterstitialAdClosed();PrepareInterAds();};// Raised when the ad failed to open full screen content.interstitialAd.OnAdFullScreenContentFailed += (AdError error) =>{Debug.LogError("Interstitial ad failed to open full screen content with error : " + error);//InterstitialAdFailed();PrepareInterAds();};}[ContextMenu("测试激励广告")]public void TestShowRewardAd(){ShowRewardAD(() => {Debug.LogError("激励广告回调");});}}

测试方法也在里面,直接挂到Unity实体上运行,右击代码就可以进行测试,展示对应的广告
Over~
看到这里了,觉得有用记得点赞收藏关注哦~

相关文章:

【Unity】Unity中接入Admob聚合广告平台,可通过中介接入 AppLovin,Unity Ads,Meta等渠道的广告

一、下载Google Admob的SDK插件 到Google Admob官网中&#xff0c;切换到Unity平台 进来之后是这样&#xff0c;注意后面有Unity标识&#xff0c;然后点击下载&#xff0c;跳转到github中&#xff0c;下载最新的Admob插件sdk&#xff0c;导入到Unity中 二、阅读官方文档&…...

PythonExcel批量pingIP地址

问题&#xff1a; 作为一个电气工程师&#xff08;PLC&#xff09;&#xff0c;当设备掉线的时候&#xff0c;需要用ping工具来检查网线物理层是否可靠连接&#xff0c;当项目体量过大时&#xff0c;就不能一个手动输入命令了。 解决方案一&#xff1a; 使用CMD命令 for /L %…...

软媒市场新蓝海:软文媒体自助发布与自助发稿的崛起

在信息时代的浪潮中,软媒市场以其独特的魅力和无限的潜力,成为了企业营销的新宠。随着互联网的飞速发展,软文媒体自助发布平台应运而生,为企业提供了更加高效、便捷的营销方式。而自助发稿功能的加入,更是让软媒市场的蓝海变得更加广阔。 软媒市场的独特价值 软媒市场之所以能…...

【笔记】Day2.5.1查询运费模板列表(未完

&#xff08;一&#xff09;代码编写 1.阅读需求&#xff0c;确保理解其中的每一个要素&#xff1a; 获取全部运费模板&#xff1a;这意味着我需要从数据库中查询所有运费模板数据。按创建时间倒序排序&#xff1a;这意味着查询结果需要根据模板的创建时间进行排序&#xff0…...

阿基米德螺旋线等距取点

曲线公式 极坐标形式&#xff1a; 笛卡尔坐标形式&#xff1a; 弧长公式 对极坐标形式积分可得弧长为&#xff1a; 将上式转换为一元二次方程&#xff1a; 解此一元二次方程可得&#xff1a; 等距取点 弧长L等距递增&#xff0c;代入公式&#xff0c;再利用笛卡尔坐标公式即…...

2024年全球增强现实(AR)市场分析报告

一、增强现实统计数据(2024) 市场价值:2024年,全球AR市场价值超过320亿美元,并预计到2027年将突破500亿美元。用户基础:目前约有14亿活跃的AR用户设备,这一数字预计将在2024年增长至17.3亿。消费者认知:大约四分之三的44岁以下成年人对AR有所了解。购物体验:基于AR的购物…...

探索 NetworkX:Python中的网络分析利器

文章目录 **探索 NetworkX&#xff1a;Python中的网络分析利器**一、背景介绍二、NetworkX是什么&#xff1f;三、如何安装NetworkX&#xff1f;四、NetworkX的五个简单函数五、NetworkX的三个应用场景六、常见问题及解决方案七、总结 探索 NetworkX&#xff1a;Python中的网络…...

Python知识点:基于Python技术,如何使用AirSim进行无人机模拟

开篇&#xff0c;先说一个好消息&#xff0c;截止到2025年1月1日前&#xff0c;翻到文末找到我&#xff0c;赠送定制版的开题报告和任务书&#xff0c;先到先得&#xff01;过期不候&#xff01; 如何使用Python和AirSim进行无人机模拟 无人机技术的发展为许多行业带来了革命性…...

《中国林业产业》是什么级别的期刊?是正规期刊吗?能评职称吗?

​问题解答 问&#xff1a;《中国林业产业》是不是核心期刊&#xff1f; 答&#xff1a;不是&#xff0c;是知网收录的正规学术期刊。 问&#xff1a;《中国林业产业》级别&#xff1f; 答&#xff1a;国家级。主管单位&#xff1a;国家林业和草原局 …...

私域流量下的白酒新传奇:半年破五千万的营销策略揭秘

在当今的数字化浪潮中&#xff0c;某白酒品牌独树一帜&#xff0c;摒弃了实体店和传统电商的常规路径&#xff0c;仅凭其精心构建的私域流量生态&#xff0c;在短短六个月内创造了超过五千万元的销售额奇迹。这一非凡成就背后&#xff0c;蕴含着一套独特的营销策略。 重塑营销&…...

Tomcat 配置:方便运行 Java Web 项目

目录 一、作用 二、安装 三、配置环境 四、启动 五、访问 一、作用 是一个轻量级的web服务器&#xff0c;可使用Tomcat运行Java Web项目。 二、安装 1. 基于JDK&#xff08;安装Tomcat之前&#xff0c;先安装JDK&#xff0c;并配置环境变量JAVA_HOME&#xff09; 2. apache-tom…...

Spring Boot知识管理:机器学习与AI集成

5系统详细实现 5.1 管理员模块的实现 5.1.1 用户管理 知识管理系统的管理员可以对用户新增&#xff0c;修改&#xff0c;删除&#xff0c;查询操作。具体界面的展示如图5.1所示。 图5.1 用户管理管理界面 5.1.2 文章分类 管理员登录可以在文章分类新增&#xff0c;修改&#…...

Superset SQL模板使用

使用背景 有时想让表的时间索引生效&#xff0c;而不是在最外层配置报表时&#xff0c;再套多一层时间范围。这时可以使用SQL模板 参考官方文档 https://superset.apache.org/docs/configuration/sql-templating/#:~:textSQL%20Lab%20and%20Explore%20supports%20Jinja 我…...

算法工程师重生之第二十七天(合并区间 单调递增的数字 监控二叉树 总结)

参考文献 代码随想录 一、合并区间 以数组 intervals 表示若干个区间的集合&#xff0c;其中单个区间为 intervals[i] [starti, endi] 。请你合并所有重叠的区间&#xff0c;并返回 一个不重叠的区间数组&#xff0c;该数组需恰好覆盖输入中的所有区间 。 示例 1&#xff1a…...

前端开发基础NodeJS+NPM基本使用(零基础入门)

文章目录 1、Nodejs基础1.1、NodeJs简介1.2、下载安装文件1.3、安装NodeJS1.4、验证安装2、Node.js 创建第一个应用2.1、说明2.2、创建服务脚本2.3、执行运行代码2.4、测试访问3、npm 基本使用3.1、测试安装3.2、配置淘宝npm镜像3.3.1、本地安装3.3.2、全局安装3.4、查看安装信…...

深度学习 nd.random.normal()

nd.random.normal() 是 MXNet 中用于生成符合正态分布&#xff08;高斯分布&#xff09;随机数的函数。它允许用户指定均值、标准差以及生成的随机数的形状。 函数签名 mx.nd.random.normal(loc0.0, scale1.0, shape(1,)) 参数 loc: 生成的随机数的均值&#xff0c;默认为 …...

Redis Geo 数据类型解析:基于 ZSET 的高效地理位置管理0708

根据官网介绍&#xff1a; Bitmaps are not an actual data type, but a set of bit-oriented operations defined on the String type which is treated like a bit vector. Since strings are binary safe blobs and their maximum length is 512 MB, they are suitable to s…...

爬虫post收尾以及cookie加代理

爬虫post收尾以及cookie加代理 目录 1.post请求收尾 2.cookie加代理 post收尾 post请求传参有两种格式&#xff0c;载荷中有请求载荷和表单参数&#xff0c;我们需要做不同的处理。 1.表单数据&#xff1a;data字典传参 content-type: application/x-www-form-urlencoded; …...

c++STL——map与set的使用及介绍

目录 前言&#xff1a; 1. 关联式容器 2. 键值对 3. 树形结构的关联式容器 3.1 set 3.1.1 set的介绍 3.1.2 set的使用 1. set的模板参数列表 2. set的构造 3. set的迭代器 4. set的容量 5. set修改操作 6. set的使用举例 3.2 map 3.2.1 map的介绍 3.2.2 map的…...

Vxe UI vue vxe-table select 下拉框选项列表数据量超大过大时卡顿解决方法

Vxe UI vue vxe-table vxe-grid select 下拉框选项列表数据量超大过大时卡顿解决方法 查看 github vxe-table 官网 vxe-table 本身支持虚拟滚动&#xff0c;数据量大也是支持的&#xff0c;但是如果在可编辑表格中使用下拉框&#xff0c;下拉框的数据量超大时&#xff0c;可能…...

python 基础笔记(其实有点内容的)

print(math.gamma(n)) # 求 (n-1) 的阶乘 数值, 数值计算 format(50, “b”) bin(50)[2:]&#xff0c; 这个“b” 就代表的是 binary format(14, ‘b’) ------> ‘1110’ 去除 0b 去掉前导零 str(000001) # 只适合python2.x ‘1’ “00000001”.lstrip(“0”) # python3…...

(39)MATLAB生成高斯脉冲及其频谱

文章目录 前言一、MATLAB仿真代码二、仿真结果画图 前言 高斯脉冲在通信中是很重要的调制符号波形&#xff0c;本文使用MATLAB生成高斯脉冲&#xff0c;并使用FFT变换给出其频谱。 一、MATLAB仿真代码 代码如下&#xff1a; % 信号参数 fs 100; % 采样…...

35岁前端开发者:转型还是坚守?

在互联网行业&#xff0c;35岁似乎成了一个敏感的年龄分水岭。很多前端开发者开始思考&#xff1a;到了35岁&#xff0c;是不是都要转型&#xff1f;本文将探讨这个话题&#xff0c;希望能为面临这一困惑的前端开发者提供一些参考。 一、35岁焦虑&#xff1a;现实还是误解&…...

对MVC详细解读

一、MVC模式的详细组成部分 1. 模型&#xff08;Model&#xff09; 数据结构&#xff1a; 模型通常使用类或结构来定义应用程序的数据结构。例如&#xff0c;在Ruby on Rails中&#xff0c;模型通常与数据库表相对应&#xff0c;使用Active Record模式。 数据访问层&#xff1…...

centos系列图形化 VNC server配置,及VNC viewer连接,2024年亲测有效

centos系列图形化 VNC server配置&#xff0c;及VNC viewer连接 0.VNC服务介绍 VNC英文全称为Virtual Network Computing&#xff0c;可以位操作系统提供图形接口连接方式&#xff0c;简单的来说就是一款桌面共享应用&#xff0c;类似于qq的远程连接。该服务是基于C/S模型的。…...

STL序列式容器之string的基本用法及实现

1.string类 在使用string类时&#xff0c;必须包含<string>头文件以及using namespace std&#xff1b; 接下来我们看看string类是如何被声明的&#xff1a; typedef basic_string<char> string; 可以看到&#xff1a;string类是被类模板basic_string用数据类型…...

lua脚本使用cjson转换json时,空数组[]变成了空对象{}

一、前言 项目lua使用工具&#xff1a;cjson 问题&#xff1a;reids中部分数据的json key存在为[]的值&#xff0c;使用cjson进行解析的时候将原本空数组[]解析成了空对象{} 目标&#xff1a;原本[] 转 [] 二、解决方案 在使用cjson类库时&#xff0c;先配置json转换要求 -…...

ImportError: /../lib/libstdc++.so.6: version `GLIBCXX_3.4.29解决方案

今天跑实验遇到了一个头疼的报错&#xff0c;完全看不懂&#xff0c;上网查了一下成功解决&#xff0c;但是网上的指令没法直接拿来用&#xff0c;所以在这里记录一下自己的解决方案。 报错信息&#xff1a; Traceback (most recent call last):File "/home/shizhiyuan/c…...

java-实现一个简单的httpserver-0.6.0

2024年10月14日14:17:07—0.6.0 java-实现一个简单的httpserver-0.6.0 背景功能具体代码打印 背景 通常写了一些接口&#xff0c;需要通过临时的http访问&#xff0c;又不需要spring这么厚重的框架 功能 设置并发监控并发两个get请求一个是根路径&#xff0c;一个是other增加…...

【论文#码率控制】ADAPTIVE RATE CONTROL FOR H.264

目录 摘要1.前言2.基本知识2.1 蛋鸡悖论2.2 基本单元的定义2.3 线性MAD预测模型 3.GOP级码率控制3.1 总比特数3.2 初始化量化参数 4.帧级码率控制4.1 非存储图像的量化参数4.2 存储图像的目标比特 5.基本单元级码率控制6.实验结果7.结论 《ADAPTIVE RATE CONTROL FOR H.264》 A…...