update: 更新Banner广告初始化配置设置

deeplink
胡宇飞 2024-03-31 18:06:57 +08:00
parent e4ce0fb408
commit 754ea97fb4
6 changed files with 54 additions and 5 deletions

View File

@ -13,7 +13,7 @@ namespace Guru
/// <summary>
/// 版本号
/// </summary>
public static readonly string Version = "1.4.0";
public static readonly string Version = "1.6.0";
#region 初始化
@ -45,6 +45,7 @@ namespace Guru
_chanelMax = new AdChanelMax(); // 默认持有MAXChannel
_chanelMax.Initialize();
if(_initSpec != null) _chanelMax.SetBannerBackColor(_initSpec.bannerColorHex);
//------------ 以下为扩展的广告渠道 ------------------
// 请根据项目需求实现各渠道接入的逻辑

View File

@ -34,8 +34,8 @@ namespace Guru
public static Action OnRewardLoaded;
public static Action OnRewardFailed;
private AdsModel _model;
private AdsInitSpec _initSpec = null;
protected AdsModel _model;
protected AdsInitSpec _initSpec = null;
public AdsModel Model
{
@ -228,6 +228,12 @@ namespace Guru
public virtual void RequestBannerAD()
{
_backColor = Color.clear;
if (_initSpec != null)
{
_backColor = GuruSDKUtils.HexToColor(_initSpec.bannerColorHex);
}
LoadMaxBannerAd();
}

View File

@ -1,5 +1,9 @@
namespace Guru
{
using UnityEngine;
public class AdsInitSpec
{
public bool loadBanner;
@ -7,10 +11,11 @@ namespace Guru
public bool loadRewarded;
public bool autoLoad;
public bool isDebug;
public string bannerColorHex;
public static AdsInitSpec Build(bool loadBanner = true, bool loadInterstitial = true, bool loadReward = true,
bool autoLoad = true, bool isDebug = false)
bool autoLoad = true, bool isDebug = false, string bannerColorHex = "#00000000")
{
return new AdsInitSpec
{
@ -18,7 +23,8 @@ namespace Guru
loadInterstitial = loadInterstitial,
loadRewarded = loadReward,
autoLoad = autoLoad,
isDebug = isDebug
isDebug = isDebug,
bannerColorHex = bannerColorHex
};
}

View File

@ -14,6 +14,7 @@ namespace Guru
public string Name => ChanelName;
public bool IsEnabled => true;
public Color BannerBackColor { get; set; }
#endregion
@ -56,6 +57,12 @@ namespace Guru
Analytics.ADBadsLoad(AdParams.Build(MaxBannerSlotID));
}
public void SetBannerBackColor(string hex)
{
if (string.IsNullOrEmpty(hex)) return;
_backColor = GuruSDKUtils.HexToColor(hex);
}
#endregion
#region Interstitial

View File

@ -0,0 +1,26 @@
namespace Guru
{
using UnityEngine;
public static class GuruSDKUtils
{
public static Color HexToColor(string hexString)
{
if(string.IsNullOrEmpty(hexString)) return Color.clear;
var hex = hexString.Replace("#", "");
if(hex.Length < 6) return Color.clear;
byte r = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
byte g = byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
byte b = byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
byte a = 255;
if (hex.Length >= 8)
{
a = byte.Parse(hex.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);
}
return new Color(r, g, b, a);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d4d6bd46cf16425a8914750598dcecc5
timeCreated: 1711879071