unity admob
插件地址:https://github.com/unity-plugins/Unity-Admob
2017.04.11测试使用发现GoogleMobileAds.framework有问题,导致出现Undefined symbols for architecture等错误
以下是测试过的完整插件包:
链接:http://pan.baidu.com/s/1c1YL1mg 密码:vi8q
无出错的GoogleMobileAds.framework:
链接:http://pan.baidu.com/s/1jHNdXNg 密码:bwyk
unity 版本:5.6.f3
Target minimum iOS Version: 8.0
全屏广告需要在unity发布设置或xcode中把所有方向都勾上,再用代码决定要保留哪些方向,这样手持设备广告的方向才能显示正确
AdmobManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using admob; public class AdmobManager : MonoBehaviour {
public string bannerID="ca-app-pub-3940256099942544/2934735716";
public string fullID="ca-app-pub-3940256099942544/4411468910";
public string rewardVideoID="ca-app-pub-3940256099942544/xxxxxxxxxx"; public string nativeBannerID="ca-app-pub-3940256099942544/2562852117"; Admob ad;
private bool _isinited; public static AdmobManager instance {
get{
return GameObject.Find("AdmobManager").GetComponent<AdmobManager>();
}
} void Awake(){
Debug.Log("start unity demo-------------");
gameObject.name="AdmobManager";
initAdmob();
} void Start () { } void Update () {
//ad.showInterstitial();
} void initAdmob(){
//isAdmobInited = true;
ad = Admob.Instance();
ad.bannerEventHandler += onBannerEvent;
ad.interstitialEventHandler += onInterstitialEvent;
ad.rewardedVideoEventHandler += onRewardedVideoEvent;
ad.nativeBannerEventHandler += onNativeBannerEvent;
ad.initAdmob(bannerID,fullID);
//ad.setTesting(true);
ad.setGender(AdmobGender.MALE);
string[] keywords = { "game","crash","male game"};
ad.setKeywords(keywords);
Debug.Log("admob inited -------------");
} void onInterstitialEvent(string eventName, string msg){
Debug.Log("handler onAdmobEvent---" + eventName + " " + msg);
if (eventName == AdmobEvent.onAdLoaded){
Admob.Instance().showInterstitial();
}else if(eventName==AdmobEvent.onAdClosed){
//Admob.Instance().loadInterstitial();
}
}
void onBannerEvent(string eventName, string msg){
Debug.Log("handler onAdmobBannerEvent---" + eventName + " " + msg);
}
void onRewardedVideoEvent(string eventName, string msg){
Debug.Log("handler onRewardedVideoEvent---" + eventName + " " + msg);
}
void onNativeBannerEvent(string eventName, string msg){
Debug.Log("handler onAdmobNativeBannerEvent---" + eventName + " " + msg);
} public bool isInterstitialReady(){
return ad.isInterstitialReady();
}
public void loadInterstitial(){
ad.loadInterstitial();
} public void showInterstitial(){
ad.showInterstitial();
} public void showRewardVideo(){
if (ad.isRewardedVideoReady()) ad.showRewardedVideo();
else ad.loadRewardedVideo(rewardVideoID);
} public void showbanner(AdSize size/*=AdSize.SmartBanner*/, int pos/*=AdPosition.BOTTOM_CENTER*/,int marginY=){
Admob.Instance().showBannerRelative(size, pos,marginY);
}
public void showbannerABS(AdSize size/*=AdSize.Banner*/,int x=,int y=){
Admob.Instance().showBannerAbsolute(size, x, y);
}
public void removebanner(){
Admob.Instance().removeBanner();
} public void showNative(int pos/*=AdPosition.BOTTOM_CENTER*/,int width=,int height=,int marginY=){
Admob.Instance().showNativeBannerRelative(new AdSize(width,height), pos, marginY,nativeBannerID);
}
public void showNativeABS(int width=,int height=,int x=,int y=){
Admob.Instance().showNativeBannerAbsolute(new AdSize(width,height), x, y, nativeBannerID);
}
public void removeNative(){
Admob.Instance().removeNativeBanner();
} }
Editor文件夹下PBXProjectSetting.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode; public class PBXProjectSetting{ //该属性是在build完成后,被调用的callback
[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget buildTarget, string path){
// BuildTarget需为iOS
if (buildTarget != BuildTarget.iOS) return;
Debug.Log("===PostProcessBuildAttribute();==="); string projPath = PBXProject.GetPBXProjectPath(path);
PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromString(File.ReadAllText(projPath));
string target = pbxProject.TargetGuidByName("Unity-iPhone"); // 关闭Bitcode
pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); // 添加framework, admob需要的所有framework
pbxProject.AddFrameworkToProject(target, "AdSupport.framework", false);
pbxProject.AddFrameworkToProject(target, "EventKit.framework", false);
pbxProject.AddFrameworkToProject(target, "EventKitUI.framework", false);
pbxProject.AddFrameworkToProject(target, "CoreTelephony.framework", false);
pbxProject.AddFrameworkToProject(target, "StoreKit.framework", false);
pbxProject.AddFrameworkToProject(target, "MessageUI.framework", false); //保存到本地
File.WriteAllText(projPath,pbxProject.WriteToString());
}
}
unity admob的更多相关文章
- Unity3D添加Admob广告
重要提示: 貌似play2014年8月之后不会再支持admob的SDK方式的广告了.github上已经有了 Unity AdMob (Google Play Services) ...
- Unity3d开发集成Google Admob广告增加收入
在Unity游戏中植入广告是Unity 游戏产品增加收入的一种重要方式,常用的广告有谷歌Admob,百度ssp,腾讯广点通,unity公司的unityads等等,而使用的最多的应该属于谷歌Admob, ...
- unity接入谷歌ADMob注意事项
应用不显示广告,可能是广告sdk 依赖项没有注册 dependencies { implementation fileTree(dir: 'bin', include: ['*.jar']) impl ...
- 【Unity与Android】02-在Unity导出的Android工程中接入Google Admob广告
我在上一篇文章 [Unity与Android]01-Unity与Android交互通信的简易实现) 中介绍了Unity与Android通讯的基本方法. 这一篇开始进入应用阶段,这次要介绍的是如何在An ...
- Unity3D IOS IPhone添加Admob的方法
原地址:http://dong2008hong.blog.163.com/blog/static/4696882720140403119293/ 首先阅读官方文档https://developers. ...
- Unity3d Android程序嵌入Admob广告条
原地址:http://dong2008hong.blog.163.com/blog/static/4696882720140441353482/ Seems like using a simple A ...
- 2017年Unity游戏开发视频教程(入门到精通)
本文是我发布的一个Unity游戏开发的学习目录,以后我会持续发布一系列的游戏开发教程,都会更新在这个页面上,适合人群有下面的几种: 想要做独立游戏的人 想要找游戏开发相关工作的人 对游戏开发感兴趣的人 ...
- iOS平台添加Google Admob -1/2(Unity3D开发之七)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/?p=567 Unity调用iOS还是非 ...
- iOS平台添加Google Admob -2/2(Unity3D开发之八)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/?p=572 在上一篇文章中主要是编写了 ...
随机推荐
- vs2015 编译google v8
转自:http://blog.csdn.net/runningman2012/article/details/54692010 系统Win10 64位,vs2015 1. git 下载depot_to ...
- 在Docker中安装配置Oracle11g并实现数据持久化
1.拉取镜像 docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g 镜像详情:https://dev.aliyun.com/ ...
- javascript-回归原生基础
//添加事件监听兼容函数 function addHandler(target, eventType, handler){ if(target.addEventListener){//主流浏览器 ad ...
- mac gcc develop
1:check version gcc -v / g++ -v 2:compile gcc *.c / g++ *.cpp outfile: a.out 3:excute ./a.out ...
- SDOI2018IIIDX
/* 题目转换为 n个节点的一片森林,n个权值,要给每个节点分配一个权值,保证子节点的权值不小于父节点的权值,并且1~n的权值的字典序最大. 考场上的贪心很显然 建立出 树来 将所有数值从大到小排序 ...
- 添加删除mysql用户
create user 'hive_user'@'%' identified by '密码'; grant all privileges on hive.* to hive_user@'%'; cre ...
- linux:apt-get 如何安装,查询,解除依赖包
apt-cache search package 搜索包 apt-cache show package 获取包的相关信息,如说明.大小.版本等 sudo apt-get install package ...
- python学习之----导航树
findAll 函数通过标签的名称和属性来查找标签 .但是如果你需要通过标签在文档中的位 置来查找标签,该怎么办?这就是导航树(Navigating Trees)的作用.在第1 章里,我们 看过用单一 ...
- Ajax总结一下
一.什么是Ajax Ajax(Asynchronous JavaScript and XML),可以理解为JavaScript执行异步网络请求.通俗的理解的话就是,如果没有Ajax技术,改变网页的一小 ...
- 查询oracle约束所关联的表
ORA-02292: 违反完整约束条件 (ADMIN.FK_PROJECTP_RELATIONS_OFFICIAL) - 已找到子记录 遇到这样的错误,熟悉的话可能从约束名称看出是那张表的约束,因为名 ...