FaceBook原生广告接入——最白话,手把手教你做系列。
2017-12-19 16:40
489 查看
接入FaceBook原生广告(Native广告)申请广告不做赘述。
接入原生广告三个步骤。
第一步,导入SDK文件。下载地址
找到下载好的文件中的audience-network-unity-sdk-4.22.0.unitypackage文件,导入项目中。
会出现下面的文件。
Samples是各种广告的事例。每种广告都有对应的场景和代码。
第一步结束。
Banner,插屏和视频广告和Admob的广告基本相似。
这里讲一下没讲过的NativeAd(原生广告)。
第二步,代码部分。
原生广告主要的部分在于原生广告可以作为一个页面显示也可以作为UI的一部分显示。可以在显示该页面或者包含该广告的页面的时候调用LoadAd ();我这里直接在Start方法里调用了。
第二步结束。
第三步,页面布局和代码挂载。
广告页面所需元素如图所示。代码只需要的挂在对应的panel上面即可
最后,将对应的物体拖到代码对应位置即可。
所以UI元素位置和大小都可以按自己的需求变动。
以上。
接入原生广告三个步骤。
第一步,导入SDK文件。下载地址
找到下载好的文件中的audience-network-unity-sdk-4.22.0.unitypackage文件,导入项目中。
会出现下面的文件。
Samples是各种广告的事例。每种广告都有对应的场景和代码。
第一步结束。
Banner,插屏和视频广告和Admob的广告基本相似。
这里讲一下没讲过的NativeAd(原生广告)。
第二步,代码部分。
using UnityEngine; using UnityEngine.UI; using System; using System.Collections; using System.Collections.Generic; using AudienceNetwork; using UnityEngine.SceneManagement; [RequireComponent (typeof(CanvasRenderer))] [RequireComponent (typeof(RectTransform))] public class NativeAdTest : MonoBehaviour { private NativeAd nativeAd; // UI elements in scene //以下部分为UI对应的一些组件 [Header("Text:")] //广告标题名 public Text title; //广告描述文字 public Text socialContext; [Header("Images:")] //广告大图 public Image coverImage; //广告的Icon public Image iconImage; [Header("Buttons:")] //跳转按钮对应文字 public Text callToAction; //广告跳 4000 转按钮 public Button callToActionButton; void Awake () { this.Log ("Native ad ready to load."); } void Start () { LoadAd (); } void OnGUI () { // Update GUI from native ad if (nativeAd != null && nativeAd.CoverImage != null) { coverImage.sprite = nativeAd.CoverImage; } if (nativeAd != null && nativeAd.IconImage != null) { iconImage.sprite = nativeAd.IconImage; } } void OnDestroy () { // Dispose of native ad when the scene is destroyed if (this.nativeAd) { this.nativeAd.Dispose (); } Debug.Log ("NativeAdTest was destroyed!"); } // Load Ad button即为展示广告方法 public void LoadAd () { // Create a native ad request with a unique placement ID (generate your own on the Facebook app settings). // Use different ID for each ad placement in your app.这里填写你的原生广告ID NativeAd nativeAd = new AudienceNetwork.NativeAd ("YOUR_PLACEMENT_ID"); this.nativeAd = nativeAd; // Wire up GameObject with the native ad; the specified buttons will be clickable. nativeAd.RegisterGameObjectForImpression (gameObject, new Button[] { callToActionButton }); // Set delegates to get notified on changes or when the user interacts with the ad. nativeAd.NativeAdDidLoad = (delegate() { this.Log ("Native ad loaded."); Debug.Log ("Loading images..."); // Use helper methods to load images from native ad URLs StartCoroutine (nativeAd.LoadIconImage (nativeAd.IconImageURL)); StartCoroutine (nativeAd.LoadCoverImage (nativeAd.CoverImageURL)); Debug.Log ("Images loaded."); title.text = nativeAd.Title; socialContext.text = nativeAd.SocialContext; callToAction.text = nativeAd.CallToAction; }); //广告对应事件 nativeAd.NativeAdDidFailWithError = (delegate(string error) { this.Log ("Native ad failed to load with error: " + error); //加载失败,这里可以执行请求失败的逻辑。比如你可以把图片 文字 和 链接替换成自己需求的。 }); nativeAd.NativeAdWillLogImpression = (delegate() { this.Log ("Native ad logged impression."); }); nativeAd.NativeAdDidClick = (delegate() { this.Log ("Native ad clicked."); }); // Initiate a request to load an ad. nativeAd.LoadAd (); this.Log ("Native ad loading..."); } private void Log(string s) { Debug.Log (s); } }
原生广告主要的部分在于原生广告可以作为一个页面显示也可以作为UI的一部分显示。可以在显示该页面或者包含该广告的页面的时候调用LoadAd ();我这里直接在Start方法里调用了。
第二步结束。
第三步,页面布局和代码挂载。
广告页面所需元素如图所示。代码只需要的挂在对应的panel上面即可
最后,将对应的物体拖到代码对应位置即可。
所以UI元素位置和大小都可以按自己的需求变动。
以上。
相关文章推荐
- 谷歌AdMob广告接入——最白话,手把手教你做系列。
- Mobvista广告接入——最白话,手把手教你做系列。
- Vungle激励广告接入——最白话,手把手教你做系列。
- 谷歌AdMob广告接入2——最白话,手把手教你做系列。
- 谷歌排行榜接入————最白话,手把手教你做系列。
- android开发步步为营之68:Facebook原生广告接入总结
- 多平台开发 JavaScript 接入ios原生 inMobi 广告
- Unity中接入原生广告(UnityAds)和 GoogleAdmob 和 Vungle
- 广点通sdk接入 _原生广告
- Facebook广告API系列 2 - Audience Management
- Facebook广告API系列 Business Manager
- Unity IAP 谷歌支付,ios支付——最白话,手把手教你做系列。
- Facebook广告API系列 1
- Facebook广告API系列 3 Ads Management
- Unity内IAP支付二次验证/服务器验证————最白话,手把手教你做系列。
- Mac下如何把项目提交、更新到GitHub上——最白话,手把手教你做系列。
- Android app中添加facebook原生广告,应该注意的坑
- 接入广告App 教你如何赚取你的第一桶金 - 2048(含源码)
- Zookeeper系列三:Zookeeper客户端的使用(Zookeeper原生API如何进行调用、ZKClient、Curator)
- 白话经典算法系列之二 直接插入排序的三种实现