当前位置:网站首页>Unity-Ads广告插件
Unity-Ads广告插件
2022-08-02 14:11:00 【莉萝爱萝莉】
1. 开始准备
- 在包管理器中,选择 Advertisement 并导入,将广告插件引入工程。
- 在官方的平台 链接 上,登录自己的unity账号
- 为你的创建一个工程,并设定是否针对13岁以下儿童展示。
- 点击左下角的 monetization (ad Units),点击 Enable Abs 启用广告。
Mediation Partner 设定是否除了Unity广告外还囊括了其他广告 - 编译器内点击右上角 云 ,选择广告。随后 使用现有账户->用户->工程->连接!
这时便已经开启了广告功能
2. 编写脚本
// 添加广告的事件监听
public class ADManager : MonoBehaviour, IUnityAdsListener
{
// 不同环境使用不同ID
#if UNITY_IOS
string gameId = "4655802";
string myPlacementId = "Rewarded_iOS";
string myBannerId = "Banner_iOS";
#elif UNITY_ANDROID
string gameId = "4655803";
string myPlacementId = "Rewarded_Android";
string myBannerId = "Banner_Android";
#endif
[SerializeField] Button btn_fullad;
void Start()
{
// 初始化广告插件
Advertisement.AddListener(this);
Advertisement.Initialize(gameId, true);
btn_fullad.interactable = Advertisement.IsReady(myPlacementId);
btn_fullad.onClick.AddListener(ShowFullVideo);
ShowHorizontalVideo();
}
public void OnUnityAdsDidError(string message) {
}
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
switch (showResult)
{
case ShowResult.Failed:
Debug.Log("显示错误");
break;
case ShowResult.Skipped:
Debug.Log("广告跳过");
break;
case ShowResult.Finished:
Debug.Log("广告结束");
break;
default:
break;
}
}
public void OnUnityAdsDidStart(string placementId){
}
public void OnUnityAdsReady(string placementId)
{
Debug.Log("准备完毕");
btn_fullad.interactable = Advertisement.IsReady(myPlacementId);
}
// 全屏广告
public void ShowFullVideo()
{
Advertisement.Show(myPlacementId);
}
// 条幅广告
public async void ShowHorizontalVideo()
{
await UniTask.WaitUntil(() => Advertisement.IsReady(myBannerId));
Advertisement.Banner.SetPosition(BannerPosition.TOP_CENTER);
Advertisement.Banner.Show(myBannerId);
}
}
3. 将测试广告转变为真实广告
- 在 monetization (Settings)中,将 Test mode 的 Play Store 设置为 Override client test mode -> Force test mode OFF (i.e. use real ads) for all devices
边栏推荐
- 推开机电的大门《电路》(一):电压,电流,参考方向
- TCP三次握手、四次挥手
- 将SSE指令转换为ARM NEON指令
- LeetCode 2344. 使数组可以被整除的最少删除次数 最大公约数
- 测试用例练习
- Win7 encounters an error and cannot boot into the desktop normally, how to solve it?
- 专硕与学硕
- How to update Win11 sound card driver?Win11 sound card driver update method
- 奇技淫巧-位运算
- Yolov5 official code reading - prior to transmission
猜你喜欢
随机推荐
pygame image rotate continuously
[System Design and Implementation] Flink-based distracted driving prediction and data analysis system
cmake configure libtorch error Failed to compute shorthash for libnvrtc.so
Redis common interview questions
flink+sklearn——使用jpmml实现flink上的机器学习模型部署
第三十一章:二叉树的概念与性质
专硕与学硕
KiCad常用快捷键
Detailed introduction to drawing complex surfaces using the plot_surface command
第二十七章:时间复杂度与优化
二叉树的遍历:递归法/ 迭代法/ 统一迭代法(强QAQ)
Article pygame drag the implementation of the method
奇技淫巧-位运算
推开机电的大门《电路》(三):说说不一样的电阻与电导
深入理解Golang之Map
Problems related to prime numbers - small notes
Open the door to electricity "Circuit" (3): Talk about different resistance and conductance
4.发布帖子,评论帖子
Letter combination of LeetCode2 phone number
Cmd Markdown 公式指导手册