当前位置: 首页 > 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;可能…...

【Linux】C语言执行shell指令

在C语言中执行Shell指令 在C语言中&#xff0c;有几种方法可以执行Shell指令&#xff1a; 1. 使用system()函数 这是最简单的方法&#xff0c;包含在stdlib.h头文件中&#xff1a; #include <stdlib.h>int main() {system("ls -l"); // 执行ls -l命令retu…...

【OSG学习笔记】Day 16: 骨骼动画与蒙皮(osgAnimation)

骨骼动画基础 骨骼动画是 3D 计算机图形中常用的技术&#xff0c;它通过以下两个主要组件实现角色动画。 骨骼系统 (Skeleton)&#xff1a;由层级结构的骨头组成&#xff0c;类似于人体骨骼蒙皮 (Mesh Skinning)&#xff1a;将模型网格顶点绑定到骨骼上&#xff0c;使骨骼移动…...

Mac下Android Studio扫描根目录卡死问题记录

环境信息 操作系统: macOS 15.5 (Apple M2芯片)Android Studio版本: Meerkat Feature Drop | 2024.3.2 Patch 1 (Build #AI-243.26053.27.2432.13536105, 2025年5月22日构建) 问题现象 在项目开发过程中&#xff0c;提示一个依赖外部头文件的cpp源文件需要同步&#xff0c;点…...

10-Oracle 23 ai Vector Search 概述和参数

一、Oracle AI Vector Search 概述 企业和个人都在尝试各种AI&#xff0c;使用客户端或是内部自己搭建集成大模型的终端&#xff0c;加速与大型语言模型&#xff08;LLM&#xff09;的结合&#xff0c;同时使用检索增强生成&#xff08;Retrieval Augmented Generation &#…...

视觉slam十四讲实践部分记录——ch2、ch3

ch2 一、使用g++编译.cpp为可执行文件并运行(P30) g++ helloSLAM.cpp ./a.out运行 二、使用cmake编译 mkdir build cd build cmake .. makeCMakeCache.txt 文件仍然指向旧的目录。这表明在源代码目录中可能还存在旧的 CMakeCache.txt 文件,或者在构建过程中仍然引用了旧的路…...

使用Spring AI和MCP协议构建图片搜索服务

目录 使用Spring AI和MCP协议构建图片搜索服务 引言 技术栈概览 项目架构设计 架构图 服务端开发 1. 创建Spring Boot项目 2. 实现图片搜索工具 3. 配置传输模式 Stdio模式&#xff08;本地调用&#xff09; SSE模式&#xff08;远程调用&#xff09; 4. 注册工具提…...

免费PDF转图片工具

免费PDF转图片工具 一款简单易用的PDF转图片工具&#xff0c;可以将PDF文件快速转换为高质量PNG图片。无需安装复杂的软件&#xff0c;也不需要在线上传文件&#xff0c;保护您的隐私。 工具截图 主要特点 &#x1f680; 快速转换&#xff1a;本地转换&#xff0c;无需等待上…...

AirSim/Cosys-AirSim 游戏开发(四)外部固定位置监控相机

这个博客介绍了如何通过 settings.json 文件添加一个无人机外的 固定位置监控相机&#xff0c;因为在使用过程中发现 Airsim 对外部监控相机的描述模糊&#xff0c;而 Cosys-Airsim 在官方文档中没有提供外部监控相机设置&#xff0c;最后在源码示例中找到了&#xff0c;所以感…...

【JavaSE】多线程基础学习笔记

多线程基础 -线程相关概念 程序&#xff08;Program&#xff09; 是为完成特定任务、用某种语言编写的一组指令的集合简单的说:就是我们写的代码 进程 进程是指运行中的程序&#xff0c;比如我们使用QQ&#xff0c;就启动了一个进程&#xff0c;操作系统就会为该进程分配内存…...

【LeetCode】算法详解#6 ---除自身以外数组的乘积

1.题目介绍 给定一个整数数组 nums&#xff0c;返回 数组 answer &#xff0c;其中 answer[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积 。 题目数据 保证 数组 nums之中任意元素的全部前缀元素和后缀的乘积都在 32 位 整数范围内。 请 不要使用除法&#xff0c;且在 O…...