Admob Unity Plugin Admob Unity 插件提供了一种在 Unity3D Game 和 u3d 应用程序中集成 admob 广告的方法

网友投稿 3071 2022-11-04

Admob Unity Plugin Admob Unity 插件提供了一种在 Unity3D Game 和 u3d 应用程序中集成 admob 广告的方法

Admob Unity Plugin Admob Unity 插件提供了一种在 Unity3D Game 和 u3d 应用程序中集成 admob 广告的方法

Admob Unity Plugin

Admob Unity Plugin provides a way to integrate admob ads in Unity3D Game and u3d app. You can use it for Unity iOS and Android App with the same c# or js code.

Admob Unity3d Plugin Readme Contents

Admob Unity Plugin DescriptionUnity Admob Plugin FeaturesDownloads Admob Unity PluginInstallation Admob UnityUnity Plugin Wiki and DocumentationQuick StartUnity Admob Demo UsageImportant TipsScreenshotsLicense

Admob Unity Plugin Description

The Google Mobile Ads SDK is the latest generation in Google mobile advertising featuring refined ad formats and streamlined APIs for access to mobile ad networks and advertising solutions. The SDK enables Unity mobile app developers to maximize their monetization in native mobile apps.

This repository contains the source code for the Google Mobile Ads Unity plugin. This plugin enables Unity developers to easily serve Google Mobile Ads on Android and iOS apps without having to write Java or Objective-C code. The plugin provides a C# interface for requesting ads that is used by C# scripts in your Unity project.

Unity Admob Plugin Features

Platforms supported in one plugin :

Android, via SDK v18.3.0 (part of Google Play service platform) iOS, via SDK v7.53 Support all native events AdRequest targeting methods,such as children target,test mode Not need change Android package name Very simple API Support non personalize ad

Ad Types:

Banner(All Banner Type and Custom banner sizes) Interstitial (text, picture, video) Rewarded Video Advanced Native Ad

Downloads Admob Unity Plugin

AdmobPluginRes/GoogleMobileAds.framework and admob_unity_plugin.unitypackage is reqired Download those files from Admob Unity3d Plugin Project Home https://github.com/unity-plugins/Unity-Admob or Download all the Unity admob plugin project https://github.com/unity-plugins/Unity-Admob/archive/master.zip

Installation Admob Unity

Open your project in the Unity editor.Navigate to Assets -> Import Package -> Custom Package.Select the admob_unity_plugin.unitypackage file.Import all of the files except admobdemo.cs(a example script) by selecting Import. Make sure to check for any conflicts with files.

You can install by download and copy files in folder Plugins to your Unity3d project directly,

Unity Plugin Wiki and Documentation

TutorialAPIDocument

Quick Start

Edit AndroidManifest.xml and config Admob APP ID

This configuration is reqired by admob from version 17.0,APP will crash if not config .Add a meta-data tag in application and set value to your admob appid

Sample code

Edit Info.plist ,add appid

GADApplicationIdentifierca-app-pub-xxxxxxxxxxxxxxxxxxxxxx~xxxxxxxxxxxxxx

1.Init Admob Unity Plugin

Create A C# script ,drag the script to a object on scene , add the follow code in the script file

using admob;Admob.Instance().initSDK(new AdProperties());//admob id configed in meta,not support in code any more

You can set admob properties as follow ,you need set properties you want to set

AdProperties adProperties = new AdProperties(); adProperties.isTesting(true);//true for test ads adProperties.isAppMuted(true); adProperties.isUnderAgeOfConsent(false); adProperties.appVolume(100); adProperties.maxAdContentRating(AdProperties.maxAdContentRating_G); string[] keywords = { "key1", "key2", "key3" }; adProperties.keyworks(keywords);

2.Add Admob Banner in Unity App

Here is the minimal code needed to show admob banner.

Admob.Instance().showBannerRelative("your admob banner unit id",AdSize.BANNER, AdPosition.BOTTOM_CENTER, 0);

or you can create another banner by set banner name

Admob.Instance().showBannerAbsolute("ca-app-pub-3940256099942544/6300978111",AdSize.BANNER, 20, 220,"mybanner");

The AdPosition class specifies where to place the banner. AdSize specifies witch size banner to show

3.Remove Banner

By default, banners are visible. To hide a banner, call:

Admob.Instance().removeBanner();

4.How to integrate Interstitial into Unity 3d app?

Here is the minimal code to create an interstitial.

Admob.Instance().loadInterstitial("Your admob interstitial unit id");

Unlike banners, interstitials need to be explicitly shown. At an appropriate stopping point in your app, check that the interstitail is ready before showing it:

if (Admob.Instance().isInterstitialReady()) { Admob.Instance().showInterstitial();}

5.Custom Admob Banner Ad Sizes

In addition to constants on AdSize, you can also create a custom size:

//Create a 250x250 banner.AdSize adSize = new AdSize(250, 250);Admob.Instance().showBannerAbsolute("Your admob banner id",adSize,0,30,"bannerName");

6.How to integrate Admob Rewarded Video to Unity3d app?

Here is the minimal code to create an admob video.

Admob.Instance().loadRewardedVideo("ca-app-pub-3940256099942544/1712485313");

Simular with interstitial,video need to be explicitly shown at an appropriate stopping point in your app, check that the video is ready before showing it:

if (Admob.Instance().isRewardedVideoReady()) { Admob.Instance().showRewardedVideo();}

7.Show Admob Native Advanced Ad in IOS and Android App

Here is the minimal code needed to show admob banner. This is implemented with Admob Native Ads Advanced (Unified)

Admob.Instance().showNativeBannerRelative("Your native banner id",new AdSize(360,100), AdPosition.BOTTOM_CENTER);

8.Ad Events

Both Banner and Interstitial contain the same ad events that you can register for. Here we'll demonstrate setting ad events on a interstitial,and show interstitial when load success:

Admob.Instance().interstitialEventHandler += onInterstitialEvent;void onInterstitialEvent(string eventName, string msg){ Debug.Log("handler onAdmobEvent---" + eventName + " " + msg); if (eventName == AdmobEvent.onAdLoaded) { Admob.Instance().showInterstitial(); }}

You only need to register for the events you care about.

Unity Admob Demo Usage

import AdmobUnityPlugin.unitypackage to your Unity project copy admobdemo.cs from AdmobPluginRes to your unity project/assets dic attach admobdemo.cs to the main camera edit admob id in admobdemo.cs build and run this in your device add -ObjC flag in xcode Other Linker Flags 7 add meta app key in Xcode Info.plist GADApplicationIdentifier ca-app-pub-xxxxxxxxxxxxxxxxxx~xxxxxxxxxx

Important Tips

If you not config AndroidManifest.xml,app will crashIf you not add -ObjC flag App will crashIf you not add GADApplicationIdentifier in Info.plist ,App will crashAttach admob to Object on scene,init admob before call admob fun

Screenshots

License

Apache 2.0 License

Change Log

1.Update admob sdk,support admob 18.3

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:一个非常简单的Chrome扩展程序,它显示Facebook为您的图片生成的自动图像标记
下一篇:聊聊保证线程安全的 10 个小技巧
相关文章

 发表评论

暂时没有评论,来抢沙发吧~