常州网站建设网站dw做网站注册页代码
- 作者: 五速梦信息网
- 时间: 2026年03月21日 10:10
当前位置: 首页 > news >正文
常州网站建设网站,dw做网站注册页代码,如何搭建一个网站步骤,seo网站开发一、下载Google Admob的SDK插件
到Google Admob官网中#xff0c;切换到Unity平台
进来之后是这样#xff0c;注意后面有Unity标识#xff0c;然后点击下载#xff0c;跳转到github中#xff0c;下载最新的Admob插件sdk#xff0c;导入到Unity中
二、阅读官方文档切换到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 : SingletonAdManager
{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./// /summaryprivate 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~ 看到这里了觉得有用记得点赞收藏关注哦~
- 上一篇: 常州网站建设套餐昭通建网站
- 下一篇: 常州网站建设网站wordpress 推广返利
相关文章
-
常州网站建设套餐昭通建网站
常州网站建设套餐昭通建网站
- 技术栈
- 2026年03月21日
-
常州网站建设软件湖南网站制作收费标准
常州网站建设软件湖南网站制作收费标准
- 技术栈
- 2026年03月21日
-
常州网站建设平台wordpress 页面内链
常州网站建设平台wordpress 页面内链
- 技术栈
- 2026年03月21日
-
常州网站建设网站wordpress 推广返利
常州网站建设网站wordpress 推广返利
- 技术栈
- 2026年03月21日
-
常州网站建设网站江西建设工程信息网站
常州网站建设网站江西建设工程信息网站
- 技术栈
- 2026年03月21日
-
常州网站建设网站南昌手机模板建站
常州网站建设网站南昌手机模板建站
- 技术栈
- 2026年03月21日






