SDK_UnityMoney/Assets/Script/SDKManager/AdsSDKManager/KwaiAdsManager/KwaiAdsManager.cs

206 lines
7.7 KiB
C#
Raw Normal View History

using System;
2025-08-30 04:15:48 +00:00
using System.Collections;
using System.Collections.Generic;
using System.Linq;
2025-08-30 04:15:48 +00:00
using KwaiAds.Scripts.Api.Interstitial;
using KwaiAds.Scripts.Api.Reward;
using UnityEngine;
2025-09-01 10:32:50 +00:00
namespace WZ
2025-08-30 04:15:48 +00:00
{
public class KwaiAdsManager : NormalSingleton<KwaiAdsManager>, IAdService
2025-08-30 04:15:48 +00:00
{
2025-09-01 10:32:50 +00:00
//目前都是测试id
private string _appId = "";
private string _token = "";
public string _rewardAdUnitId = "";
public string _interstitialAdUnitId = "";
public double _rewardAdRevenue = 0;
public double _interstitiaAdRevenue = 0;
private IRewardAdController _rewardAdController;
private IInterstitialAdController _interstitialAdController;
public string _rvPos;
public string _ivPos;
public Action<bool, double> _rvCloseCallback = null;
public Action<double> _ivCloseCallback = null;
public Action _rvShowFailedCallback = null;
public int _rewardRetryAttempt;
public int _interRetryAttempt;
public float _rvStartLoadTime = 0;
public float _ivStartLoadTime = 0;
public string ClientName => "Kwai";
public PlatformType Platfrom => PlatformType.Kwai;
public void Initialize()
2025-08-30 04:15:48 +00:00
{
if (string.IsNullOrEmpty(_appId) || string.IsNullOrEmpty(_token)) return;
2025-09-01 10:32:50 +00:00
var kwaiAdConfig = new KwaiAds.Scripts.Api.KwaiAdConfig.Builder()
.SetAppId(_appId)
.SetToken(_token)
.SetDebugLog(false)
2025-09-01 10:32:50 +00:00
.Build();
KwaiAds.Scripts.Api.KwaiAdsSdk.Initialize(kwaiAdConfig, new InitResultCallbackImpl());
2025-08-30 04:15:48 +00:00
}
public void RefreshAdsData()
{
_appId = AdConfigParser.GetKwaiAppId();
_token = AdConfigParser.GetKwaiAppToken();
_rewardAdUnitId = AdConfigParser.GetKwaiAdUnits(AdsType.Rewarded).FirstOrDefault();
_interstitialAdUnitId = AdConfigParser.GetKwaiAdUnits(AdsType.Interstitial).FirstOrDefault();
}
2025-09-01 10:32:50 +00:00
#region 广
public void LoadRewarded()
2025-08-30 04:15:48 +00:00
{
if (string.IsNullOrEmpty(_rewardAdUnitId)) return;
if (_rewardAdController != null)
2025-09-01 10:32:50 +00:00
{
_rewardAdController.Destroy();
_rewardAdController = null;
_rewardAdRevenue = 0;
2025-09-01 10:32:50 +00:00
}
_rewardAdController = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getRewardAdController();
KwaiRewardAdRequest kwaiRewardAdRequest = new KwaiRewardAdRequest(_rewardAdUnitId);
_rewardAdController.Load(kwaiRewardAdRequest, new RewardAdListener(), new RewardAdLoadListener());
AdsActionEvents.TrackAdStartLoad(Platfrom, "", "", AdsType.Rewarded);
_ivStartLoadTime = Time.realtimeSinceStartup;
2025-08-30 04:15:48 +00:00
}
2025-09-01 10:32:50 +00:00
public bool IsRewardedAvailable()
2025-08-30 04:15:48 +00:00
{
if (string.IsNullOrEmpty(_rewardAdUnitId)) return false;
return _rewardAdController != null && _rewardAdController.IsReady();
}
public void DisplayRewarded(string _adPos, Action<bool, double> _rewardCallback = null, Action _showFailedCallback = null)
{
_adPos = _rvPos;
_rvCloseCallback = _rewardCallback;
_rvShowFailedCallback = _showFailedCallback;
if (_rewardAdController != null)
2025-09-01 10:32:50 +00:00
{
_rewardAdController.Show();
2025-09-01 10:32:50 +00:00
}
else
{
_showFailedCallback?.Invoke();
LoadRewarded();
2025-09-01 10:32:50 +00:00
}
2025-08-30 04:15:48 +00:00
}
public double GetRewardedRevenue()
2025-09-01 10:32:50 +00:00
{
return _rewardAdRevenue;
2025-09-01 10:32:50 +00:00
}
#endregion
2025-08-30 04:15:48 +00:00
2025-09-01 10:32:50 +00:00
#region
public void LoadInterstitial()
2025-08-30 04:15:48 +00:00
{
if (string.IsNullOrEmpty(_interstitialAdUnitId)) return;
if (_interstitialAdController != null)
2025-09-01 10:32:50 +00:00
{
_interstitialAdController.Destroy();
_interstitialAdController = null;
_interstitiaAdRevenue = 0;
2025-09-01 10:32:50 +00:00
}
_interstitialAdController = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getInterstitialAdController();
KwaiInterstitialAdRequest kwaiInterstitialAdRequest = new KwaiInterstitialAdRequest(_interstitialAdUnitId);
_interstitialAdController.Load(kwaiInterstitialAdRequest, new InterstitialAdListener(), new InterstitialAdLoadListener());
AdsActionEvents.TrackAdStartLoad(Platfrom, "", "", AdsType.Interstitial);
_ivStartLoadTime = Time.realtimeSinceStartup;
}
public bool IsInterstitialAvailable()
{
if (string.IsNullOrEmpty(_interstitialAdUnitId)) return false;
return _interstitialAdController != null && _interstitialAdController.IsReady();
2025-08-30 04:15:48 +00:00
}
public void DisplayInterstitial(string _adPos, IvType _IvType = IvType.IV1, Action<double> _closeCallback = null)
2025-08-30 04:15:48 +00:00
{
_ivCloseCallback = _closeCallback;
if (_interstitialAdController != null)
2025-09-01 10:32:50 +00:00
{
_interstitialAdController.Show();
2025-09-01 10:32:50 +00:00
}
else
{
_closeCallback?.Invoke(0);
LoadInterstitial();
2025-09-01 10:32:50 +00:00
}
2025-08-30 04:15:48 +00:00
}
2025-09-01 10:32:50 +00:00
public double GetInterstitialRevenue()
2025-08-30 04:15:48 +00:00
{
return _interstitiaAdRevenue;
}
#endregion
#region 广
public void LoadBanner() { }
public bool IsBannerAvailable() { return false; }
public void DisplayBanner() { }
public void HideBanner() { }
public double GetBannerRevenue() { return 0; }
#endregion
#region 广
public void LoadSplash() { }
public bool IsSplashAvailable() { return false; }
public void DisplaySplash() { }
public double GetSplashRevenue() { return 0; }
#endregion
2025-09-01 10:32:50 +00:00
#region 广
public void LoadNative() { }
public bool IsNativeAvailable(string adUnitId) { return false; }
public void DisplayNative(string _adPos, string adUnitId, NativeAdPosition position) { }
public void RemoveNative(string adUnitId) { }
public double GetNativeRevenue(string adUnitId) { return 0; }
#endregion
#region
public void TrackAdImpression(AdsType type)
{
AdjustTrackEvent.Instance.TrackAdEvent(type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue,
ClientName,
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId,
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId);
FireBaseAnalyticsManager.Instance.OnAdRevenueEvent(ClientName,
ClientName,
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId,
type,
type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue,
type == AdsType.Rewarded ? _rvPos : "",
AdPlayCountManager.GetAdPlayCount(type));
ShuShuEvent.Instance.OnAdRevenueEvent(ClientName,
ClientName,
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId,
type.ToString(),
type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue,
type == AdsType.Rewarded ? _rvPos : "",
AdPlayCountManager.GetAdPlayCount(type));
AdsActionEvents.TrackAdImpression(Platfrom,
ClientName,
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId,
type,
type == AdsType.Rewarded ? _rvPos : "",
type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue);
2025-08-30 04:15:48 +00:00
}
2025-09-01 10:32:50 +00:00
#endregion
}
2025-08-30 04:15:48 +00:00
2025-09-01 10:32:50 +00:00
}