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

多云管理“拦路虎”:深入解析网络互联、身份同步与成本可视化的技术复杂度​

一、引言&#xff1a;多云环境的技术复杂性本质​​ 企业采用多云策略已从技术选型升维至生存刚需。当业务系统分散部署在多个云平台时&#xff0c;​​基础设施的技术债呈现指数级积累​​。网络连接、身份认证、成本管理这三大核心挑战相互嵌套&#xff1a;跨云网络构建数据…...

深入浅出Asp.Net Core MVC应用开发系列-AspNetCore中的日志记录

ASP.NET Core 是一个跨平台的开源框架&#xff0c;用于在 Windows、macOS 或 Linux 上生成基于云的新式 Web 应用。 ASP.NET Core 中的日志记录 .NET 通过 ILogger API 支持高性能结构化日志记录&#xff0c;以帮助监视应用程序行为和诊断问题。 可以通过配置不同的记录提供程…...

Leetcode 3576. Transform Array to All Equal Elements

Leetcode 3576. Transform Array to All Equal Elements 1. 解题思路2. 代码实现 题目链接&#xff1a;3576. Transform Array to All Equal Elements 1. 解题思路 这一题思路上就是分别考察一下是否能将其转化为全1或者全-1数组即可。 至于每一种情况是否可以达到&#xf…...

中南大学无人机智能体的全面评估!BEDI:用于评估无人机上具身智能体的综合性基准测试

作者&#xff1a;Mingning Guo, Mengwei Wu, Jiarun He, Shaoxian Li, Haifeng Li, Chao Tao单位&#xff1a;中南大学地球科学与信息物理学院论文标题&#xff1a;BEDI: A Comprehensive Benchmark for Evaluating Embodied Agents on UAVs论文链接&#xff1a;https://arxiv.…...

【JVM】- 内存结构

引言 JVM&#xff1a;Java Virtual Machine 定义&#xff1a;Java虚拟机&#xff0c;Java二进制字节码的运行环境好处&#xff1a; 一次编写&#xff0c;到处运行自动内存管理&#xff0c;垃圾回收的功能数组下标越界检查&#xff08;会抛异常&#xff0c;不会覆盖到其他代码…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个医院查看报告小程序

一、开发环境准备 ​​工具安装​​&#xff1a; 下载安装DevEco Studio 4.0&#xff08;支持HarmonyOS 5&#xff09;配置HarmonyOS SDK 5.0确保Node.js版本≥14 ​​项目初始化​​&#xff1a; ohpm init harmony/hospital-report-app 二、核心功能模块实现 1. 报告列表…...

Spring数据访问模块设计

前面我们已经完成了IoC和web模块的设计&#xff0c;聪明的码友立马就知道了&#xff0c;该到数据访问模块了&#xff0c;要不就这俩玩个6啊&#xff0c;查库势在必行&#xff0c;至此&#xff0c;它来了。 一、核心设计理念 1、痛点在哪 应用离不开数据&#xff08;数据库、No…...

C++课设:简易日历程序(支持传统节假日 + 二十四节气 + 个人纪念日管理)

名人说:路漫漫其修远兮,吾将上下而求索。—— 屈原《离骚》 创作者:Code_流苏(CSDN)(一个喜欢古诗词和编程的Coder😊) 专栏介绍:《编程项目实战》 目录 一、为什么要开发一个日历程序?1. 深入理解时间算法2. 练习面向对象设计3. 学习数据结构应用二、核心算法深度解析…...

python爬虫——气象数据爬取

一、导入库与全局配置 python 运行 import json import datetime import time import requests from sqlalchemy import create_engine import csv import pandas as pd作用&#xff1a; 引入数据解析、网络请求、时间处理、数据库操作等所需库。requests&#xff1a;发送 …...

从“安全密码”到测试体系:Gitee Test 赋能关键领域软件质量保障

关键领域软件测试的"安全密码"&#xff1a;Gitee Test如何破解行业痛点 在数字化浪潮席卷全球的今天&#xff0c;软件系统已成为国家关键领域的"神经中枢"。从国防军工到能源电力&#xff0c;从金融交易到交通管控&#xff0c;这些关乎国计民生的关键领域…...