之前的文章介绍了OneWay广告的注册和测试设备的添加,这篇文章主要介绍如何将OneWay广告集成到游戏项目中去。由于我的游戏是使用Unity引擎开发的,所以主要介绍Unity版SDK的集成过程。
登录OneWay后台,点击技术对接,点击下载Unity版SDK。

压缩包解压后如下:

将OneWaySDK-Unity 2.3.5.unitypackage资源导入到项目工程中

但会报一个关于ios平台的错


由于我只出Android的apk,因此,将其报错误的脚本关于iOS的代码注释掉即可。

Android平台需要添加Android v4支持库到项目中,因此需要检查导入的SDK中是否有这份jar包

如此SDK导入工作完成,接下来开始封装调用广告的API。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/** Author:W* OneWay广告管理*///激励视频广告回调
public delegate void OnRewardedAdReadyEvent();
public delegate void OnRewardedAdShowEvent(string placementId);
public delegate void OnRewardedAdClickEvent(string placementId);
public delegate void OnRewardedAdCloseEvent(string placementId,string state);//插屏视频广告回调
public delegate void OnInterstitialAdReadyEvent();
public delegate void OnInterstitialAdShowEvent(string placementId);
public delegate void OnInterstitialAdClickEvent(string placementId);
public delegate void OnInterstitialAdCloseEvent(string placementId, string state);//插屏图片广告回调
public delegate void OnInterstitialImageAdReadyEvent();
public delegate void OnInterstitialImageAdShowEvent(string placementId);
public delegate void OnInterstitialImageAdClickEvent(string placementId);
public delegate void OnInterstitialImageAdCloseEvent(string placementId, string state);public class OneWayAdManager : MonoBehaviour
{private static OneWayAdManager _instance;public static OneWayAdManager Instance{get{if (_instance == null){_instance = new GameObject("OneWayAdManager").AddComponent<OneWayAdManager>();DontDestroyOnLoad(_instance.gameObject);}return _instance;}}#region 相关申请的ID//Android 应用 idpublic const string PublishID_Android = "ed2ba792d70941f8";//后台申请的激励视频广告IDpublic const string RewardAd_XXX = "T12WE4T93KK67QMX";public const string RewardAd_CCC = "T12WE4T93KK67QMX";//后台申请的插屏视频广告IDpublic const string InterAd_XXX = "WLFJFVFI54OLEQJX";public const string InterAd_CCC = "WLFJFVFI54OLEQJX";//后台申请的插屏图片广告IDpublic const string InterImgAd_XXX = "C4QT9THWMMR8Y14B";public const string InterImgAd_CCC = "C4QT9THWMMR8Y14B";#endregion#region  广告相关回调public OnRewardedAdReadyEvent OnRewardedAdReadyEvent;public OnRewardedAdShowEvent OnRewardedAdShowEvent;public OnRewardedAdClickEvent OnRewardedAdClickEvent;public OnRewardedAdCloseEvent OnRewardedAdCloseEvent;public OnInterstitialAdReadyEvent OnInterstitialAdReadyEvent;public OnInterstitialAdShowEvent OnInterstitialAdShowEvent;public OnInterstitialAdClickEvent OnInterstitialAdClickEvent;public OnInterstitialAdCloseEvent OnInterstitialAdCloseEvent;public OnInterstitialImageAdReadyEvent OnInterstitialImageAdReadyEvent;public OnInterstitialImageAdShowEvent OnInterstitialImageAdShowEvent;public OnInterstitialImageAdClickEvent OnInterstitialImageAdClickEvent;public OnInterstitialImageAdCloseEvent OnInterstitialImageAdCloseEvent;#endregionvoid Awake(){_instance = this;DontDestroyOnLoad(_instance.gameObject);InitSDK();}/// <summary>/// SDK初始化/// </summary>private void InitSDK(){//PublishId :您在我们的开发者平台创建时应用后,所获得的唯一应用ID(区分 iOS/Android)。OneWaySDK.configure("PublishID_iOS", PublishID_Android);//初始化激励广告【如果需要】OneWaySDK.initRewardedAd();OneWaySDK.onRewardedAdReadyEvent += () => {Debug.Log("OneWaySDK RewardedAd Ready");if (OnRewardedAdReadyEvent != null)OnRewardedAdReadyEvent();};OneWaySDK.onRewardedAdShowEvent += (placeId) => {Debug.Log("OneWaySDK RewardedAd Show for tag: " + placeId);if (OnRewardedAdShowEvent != null)OnRewardedAdShowEvent(placeId);};OneWaySDK.onRewardedAdClickEvent += (placeId) => {Debug.Log("OneWaySDK RewardedAd Click for tag: " + placeId);if (OnRewardedAdClickEvent != null)OnRewardedAdClickEvent(placeId);};OneWaySDK.onRewardedAdCloseEvent += (placeId, state) => {Debug.Log("OneWaySDK RewardedAd Close for tag: " + placeId + " state is: " + state);if (OnRewardedAdCloseEvent != null)OnRewardedAdCloseEvent(placeId, state);};//初始化插屏视频广告【如果需要】OneWaySDK.initInterstitialAd();OneWaySDK.onInterstitialAdReadyEvent += () => {Debug.Log("OneWaySDK InterstitialAd Ready ");if (OnInterstitialAdReadyEvent != null)OnInterstitialAdReadyEvent();};OneWaySDK.onInterstitialAdShowEvent += (placeId) => {Debug.Log("OneWaySDK InterstitialAd Show for tag: " + placeId);if (OnInterstitialAdShowEvent != null)OnInterstitialAdShowEvent(placeId);};OneWaySDK.onInterstitialAdClickEvent += (placeId) => {Debug.Log("OneWaySDK InterstitialAd Click for tag: " + placeId);if (OnInterstitialAdClickEvent != null)OnInterstitialAdClickEvent(placeId);};OneWaySDK.onInterstitialAdCloseEvent += (placeId, state) => {Debug.Log("OneWaySDK InterstitialAd Close for tag: " + placeId + " state is: " + state);if (OnInterstitialAdCloseEvent != null)OnInterstitialAdCloseEvent(placeId, state);};//初始化插屏图片广告【如果需要】OneWaySDK.initInterstitialImageAd();OneWaySDK.onInterstitialImageAdReadyEvent += () => {Debug.Log("OneWaySDK InterstitialImageAd Ready ");if (OnInterstitialImageAdReadyEvent != null)OnInterstitialImageAdReadyEvent();};OneWaySDK.onInterstitialImageAdShowEvent += (placeId) => {Debug.Log("OneWaySDK InterstitialImageAd Show for tag: " + placeId);if (OnInterstitialImageAdShowEvent != null)OnInterstitialImageAdShowEvent(placeId);};OneWaySDK.onInterstitialImageAdClickEvent += (placeId) => {Debug.Log("OneWaySDK InterstitialImageAd Click for tag: " + placeId);if (OnInterstitialImageAdClickEvent != null)OnInterstitialImageAdClickEvent(placeId);};OneWaySDK.onInterstitialImageAdCloseEvent += (placeId, state) => {Debug.Log("OneWaySDK InterstitialImageAd Close for tag: " + placeId + " state is: " + state);if (OnInterstitialImageAdCloseEvent != null)OnInterstitialImageAdCloseEvent(placeId, state);};//SDK错误事件监听OneWaySDK.onOneWaySDKDidErrorEvent += (err, msg) => {Debug.LogError("OneWaySDK is err: " + err + " , message: " + msg);};}/// <summary>/// 播放激励广告/// placementId:用于给开发者标记广告,在代理回调时会带上此参数, 默认为 "default"。/// </summary>public void ShowRewardedAd(string placementId= "default"){//判断激励广告是否可以播放if (OneWaySDK.isRewardedAdReady()){           OneWaySDK.showRewardedAd(placementId);                                  }}/// <summary>/// 播放插屏视频广告/// placementId : 用于给开发者标记广告,在代理回调时会带上此参数, 默认为 "default"./// </summary>/// <param name="placementId"></param>public void ShowInterstitialAd(string placementId = "default"){//判断插屏视频广告是否可以播放if (OneWaySDK.isInterstitialAdReady()){OneWaySDK.showInterstitialAd(placementId);}}/// <summary>/// 播放插屏广告/// placementId : 用于给开发者标记广告,在代理回调时会带上此参数, 默认为 "default"./// </summary>/// <param name="placementId"></param>public void ShowInterstitialImageAd(string placementId = "default"){//判断插屏图片广告是否可以播放if (OneWaySDK.isInterstitialImageAdReady()){OneWaySDK.showInterstitialImageAd(placementId);}}
}


测试脚本如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/** Author:W* 广告测试*/
public class TestAd : MonoBehaviour
{public Button RewardAdBtn;public Button InterAdBtn;public Button InterImgAdBtn;void Awake(){RewardAdBtn.onClick.AddListener(OnRewardAdBtnClick);InterAdBtn.onClick.AddListener(OnInterAdBtnClick);InterImgAdBtn.onClick.AddListener(OnInterImgAdBtnClick);}void OnDestroy(){RewardAdBtn.onClick.RemoveListener(OnRewardAdBtnClick);InterAdBtn.onClick.RemoveListener(OnInterAdBtnClick);InterImgAdBtn.onClick.RemoveListener(OnInterImgAdBtnClick);}private void OnRewardAdBtnClick(){Debug.Log("激励视频广告点击");OneWayAdManager.Instance.ShowRewardedAd(OneWayAdManager.RewardAd_CCC);}private void OnInterAdBtnClick(){Debug.Log("插屏视频广告点击");OneWayAdManager.Instance.ShowInterstitialAd(OneWayAdManager.InterAd_CCC);}private void OnInterImgAdBtnClick(){Debug.Log("插屏图片广告点击");OneWayAdManager.Instance.ShowInterstitialImageAd(OneWayAdManager.InterImgAd_CCC);}
}

打出apk,测试结果如下

OneWay广告Unity版SDK接入相关推荐

  1. 【记录】穿山甲广告iOS版SDK接入记录

    官方接入文档 获取 framework 文件 (平台接入模块->SDK下载与接入文档),要先注册 其他参考 Creator iOS接入穿山甲SDK 1.集成SDK 这里采用pod pod Ads ...

  2. Unity接入穿山甲广告(使用unity插件SDK接入)看这一篇就够了

    自己做的小游戏需要接广告,之前尝试过UnityAds和AdMob,但是都有点小问题.UnityAds对国内本土支持不好,Banner广告经常没有内容.Admob基本上都要对接到googlePlay,国 ...

  3. unity 接入巨量引擎今日头条广告投放分包SDK

    巨量引擎今日头条广告投放分包SDK 在接入分包SDK时,一般也会同时接入今日头条上报SDK Unity 接入巨量引擎 头条上报SDK 1. 分包SDK下载 2.下载完之后,导入到导出的android ...

  4. GoogleAdMob广告 SDK接入(Android)

    1.发包平台 需要一个能够打Andoird包的环境. 2.获取广告ID (注:需要有一个Google账号.) 1.登录连接:AdMob官方 2.添加应用 3.这里看具体项目选择,此处选否 4.输入应用 ...

  5. 三分钟集成 TapTap 防沉迷 SDK(Unity 版)

    三分钟集成 Tap 防沉迷 SDK(Unity 版) 一.SDK 介绍 基于国家对上线所有游戏必须增加防沉迷功能的政策下,TapTap 推出防沉迷 SDK,供游戏开发者进行接入:允许未成年用户在周五. ...

  6. 踩坑!穿山甲广告Android SDK接入

    随着流量变现的兴起,越来越多的广告SDK汹涌而来,除了字节的穿山甲,还有腾讯的优量汇.百度的广告联盟,其他的例如AdView和万普世纪已经逐渐退出历史的舞台. 本篇文章将基于com.pangle.cn ...

  7. Android MIntegral广告SDK接入

    目测MIntegral 广告SDK国内接入的资源比较少,特此做个demo出来分享,仅供学习! 特别说明: MIntegral SDK 是分国内,国外的,广告接口相同,资源库不同.详情请参考MInteg ...

  8. 三分钟集成 TapTap 登录 SDK(Unity 版)

    三分钟集成 Tap 登录 SDK(Unity 版) 一.SDK 介绍 Tap 登录分为两种类型: 基于内建账户系统 单纯 TapTap 用户认证 以上两种方式功能区别可以参考官方文档介绍,本文档就不再 ...

  9. Unity 和 Android Studio的SDK接入(新手心得)

    AndroidManifest.xml前言 刚大学毕业入职不到三个月,让接SDK,就在网上学习查找了一些.肯定有很多不足之处,请多多指教 写的这篇文章呢,只适合没有方向的,不知道怎么开始的(我就是,学 ...

  10. 渠道广告联盟SDK接入思路总结

    前言 1.国内安卓硬核渠道,例如华为.OPPO.ViVo.小米.4399都有自家的广告联盟SDK,要到对应开放平台下载对应广告SDK. 2.其他渠道例如应用宝.TapTap.好游快爆.爱奇艺.233. ...

最新文章

  1. How to include html native content to UI5 page - 直接在xml view里添加html namespace
  2. cdn需要备案吗_cdn需要备案么
  3. python将一组数据转化为列表_Pandas将列表(List)转换为数据框(Dataframe)
  4. Java面试的基础题20190000
  5. 522. 最长特殊序列 II
  6. 2016考研数学三复习计划
  7. virtualxposed使用教程_VirtualXposed
  8. EDI 助力 VMI 加固供应链三道防线
  9. 交通银行一直显示服务器繁忙,交通银行信用卡人工服务一直繁忙
  10. 学籍管理系统c语言项目作业,C语言实现学生学籍管理系统
  11. 带有Lowe’s算法的SURF特征提取和匹配
  12. python3查找元素在数组位置_Python:查找数组中元素的位置
  13. 10大耗油,10大省油。
  14. 如何去除Word中的波浪线?这三种方法很实用!
  15. 2022.09.01 最新配置maven阿里云仓库配置
  16. 电话号码的正则表达式
  17. 强大的iOS开发必备工具
  18. ACwing每日一题3565暴力 绝对值不等式 中位数思维
  19. Python爬虫项目:爬取JSON数据存储Excel表格与存储图片
  20. 快递100快递java_使用快递100 查询链接实现快速查询的示例

热门文章

  1. 如何通过反向代理实现伪装IP?
  2. 2010提升你幽默感的语句
  3. UGUI优化之路- Image的Sliced优化
  4. Docker - 常见操作命令篇
  5. [应用广播], 一览华夏文化,诗词三万首震撼上线
  6. java 接口耗时分析_性能优化案例(2019-案例78)-接口性能耗时问题分析
  7. php随浏览器大小变化,如何在将图像显示到浏览器之前使用php重新调整图像大小?...
  8. java打印长方形、平行四边形、三角形、菱形
  9. html做成avi格式文件,制作HTML网页插入视频Mp 4格式可以播放,AVI格式为何不可以播放...
  10. 上市公司股息红利差别化个人所得税政策