赞
踩
上篇介绍Unity小游戏发布抖音平台的开发者账号注册以及小游戏创建和申请。本篇介绍字节SDK接入Unity游戏项目中。
接入参考教程:Docs,下载bgdt.package包,并导入Unity项目工程。
打开ByteGame菜单,弹出字节工具面板。点击下载安装另外2个字节小游戏工具。
安装完毕后,ByteGame菜单下多了StarkSDKTools子菜单,子菜单下,又多了BuildingTool和PublishingTool工具,前者是运行调试工具,后者是发布工具。
关于调试和发布工具如何使用会在之后的文章中讲解,本篇主要介绍SDK接入。项目中制作个广告管理单例管理器
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- /*
- * Author:W
- * 字节跳动广告管理
- */
- public delegate void OnVideoAdCloseCallBack();
- public delegate void OnVideoAdErrorCallBack();
-
-
- public class ByteGameAdManager : MonoBehaviour
- {
- private static ByteGameAdManager _instance;
-
-
- public static ByteGameAdManager Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = new GameObject("ByteGameAdManager").AddComponent<ByteGameAdManager>();
- DontDestroyOnLoad(_instance.gameObject);
- }
-
- return _instance;
- }
- }
-
- private StarkSDKSpace.StarkAdManager starkAdManager;
-
-
- public const string LevelComplete_Video_Id = "mi5ag76n0bg4506577";
- public const string Back_Interstitial_Video_Id = "2efdh3aelb10i0q2ie";
- public const string Resume_Interstitial_Video_Id = "9e953k528dj5ljkcef";
- public const string Game_Banner_Id = "4f08ml2f1a81vsqvbg";
-
- private void Awake()
- {
- _instance = this;
- DontDestroyOnLoad(_instance.gameObject);
-
- starkAdManager = StarkSDKSpace.StarkSDK.API.GetStarkAdManager();
- }
-
- /// <summary>
- /// 播放激励视频广告
- /// </summary>
- /// <param name="adId"></param>
- /// <param name="closeCallBack"></param>
- /// <param name="errorCallBack"></param>
- public void ShowVideoAd(string adId,System.Action<bool> closeCallBack,System.Action<int,string> errorCallBack)
- {
- if (starkAdManager != null)
- starkAdManager.ShowVideoAdWithId(adId,closeCallBack,errorCallBack);
- }
-
- /// <summary>
- /// 播放插屏广告
- /// </summary>
- /// <param name="adId"></param>
- /// <param name="errorCallBack"></param>
- /// <param name="closeCallBack"></param>
- public void ShowInterstitialAd(string adId,System.Action<int,string> errorCallBack,System.Action closeCallBack)
- {
- if (starkAdManager != null)
- starkAdManager.CreateInterstitialAd(adId,errorCallBack,closeCallBack);
- }
-
- // Start is called before the first frame update
- void Start()
- {
-
- }
-
- // Update is called once per frame
- void Update()
- {
-
- }
- }
广告封装好后,可以在对应的广告位处调用对应广告的API并注册回调做相应的处理即可。
关于广告ID位申请,请前往字节小程序开发者后台注册。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。