using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace WZ { [Serializable] public class AdTypeBidState { public AdsType AdType; public DateTime LastBidSuccessTime; public AdTypeBidState(AdsType adType) { AdType = adType; LastBidSuccessTime = DateTime.MinValue; } public bool IsBidExpired(int expireInSec) { // 如果功能关闭,则不视为过期 if (expireInSec == -1) return false; // 如果从未成功竞价过,则视为过期 // if (LastBidSuccessTime == DateTime.MinValue) return true; // 检查是否超过过期时间 TimeSpan timeSinceLastBid = DateTime.Now - LastBidSuccessTime; return timeSinceLastBid.TotalSeconds > expireInSec; } } [Serializable] public class BidPlatformState { public PlatformType PlatformName; public bool IsEnabled = true; // 每种广告类型的竞价状态 public Dictionary AdTypeStates = new Dictionary(); public BidPlatformState(PlatformType platformName) { PlatformName = platformName; // 初始化所有广告类型的状态 foreach (AdsType adType in Enum.GetValues(typeof(AdsType))) { AdTypeStates.Add(adType, new AdTypeBidState(adType)); } } // 记录特定广告类型的竞价成功 public void RecordBidSuccess(AdsType adType) { if (AdTypeStates.TryGetValue(adType, out var state)) { state.LastBidSuccessTime = DateTime.Now; Debug.Log($"{PlatformName} 平台 {adType} 广告竞价成功,记录时间: {state.LastBidSuccessTime}"); } } // 检查特定广告类型的竞价是否过期 public bool IsBidExpired(AdsType adType, int expireInSec) { if (!IsEnabled || expireInSec == -1) return false; if (AdTypeStates.TryGetValue(adType, out var state)) { return state.IsBidExpired(expireInSec); } return false; } // 获取所有过期的广告类型 public List GetExpiredAdTypes(int expireInSec) { List expiredAdTypes = new List(); if (!IsEnabled || expireInSec == -1) return expiredAdTypes; foreach (var kvp in AdTypeStates) { if (kvp.Value.IsBidExpired(expireInSec)) { expiredAdTypes.Add(kvp.Key); } } return expiredAdTypes; } } public class BidPlatformManager : D_MonoSingleton { private Dictionary _platformStates = new Dictionary(); private int _bidExpireInSec = -1; public void InitializePlatformStates(int expireInSec) { _bidExpireInSec = expireInSec; _platformStates.Clear(); _platformStates.Add(PlatformType.Admob, new BidPlatformState(PlatformType.Admob)); _platformStates.Add(PlatformType.Topon, new BidPlatformState(PlatformType.Topon)); _platformStates.Add(PlatformType.AppLovin, new BidPlatformState(PlatformType.AppLovin)); _platformStates.Add(PlatformType.Bigo, new BidPlatformState(PlatformType.Bigo)); _platformStates.Add(PlatformType.Kwai, new BidPlatformState(PlatformType.Kwai)); } // 记录平台竞价成功 public void RecordBidSuccess(PlatformType platformName, AdsType adType) { if (_platformStates.TryGetValue(platformName, out var state)) { state.RecordBidSuccess(adType); } } // 获取所有过期平台 public Dictionary> GetExpiredBids() { Dictionary> expiredBids = new Dictionary>(); if (_bidExpireInSec == -1) return expiredBids; foreach (var kvp in _platformStates) { List expiredAdTypes = kvp.Value.GetExpiredAdTypes(_bidExpireInSec); if (expiredAdTypes.Count > 0) { expiredBids.Add(kvp.Key, expiredAdTypes); } } return expiredBids; } } }