From 3549e7719386bcc73894cd902dfdf4bb4910f242 Mon Sep 17 00:00:00 2001 From: juncong lee Date: Mon, 15 Sep 2025 18:41:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E6=88=90RequestId=EF=BC=8C=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E6=AC=A1=E6=95=B0=EF=BC=8C=E6=AF=8F=E4=B8=AAunit?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/KwaiAdsConfigParser.cs | 2 +- .../KwaiAdsManager/KwaiFloorIvManager.cs | 77 ++++++++++++++++++- .../KwaiAdsManager/KwaiFloorRvManager.cs | 75 +++++++++++++++++- Assets/Script/Test.cs | 5 ++ 4 files changed, 152 insertions(+), 7 deletions(-) diff --git a/Assets/Script/SDKManager/AdsSDKManager/KwaiAdsManager/Data/KwaiAdsConfigParser.cs b/Assets/Script/SDKManager/AdsSDKManager/KwaiAdsManager/Data/KwaiAdsConfigParser.cs index 816d094..1a9641c 100644 --- a/Assets/Script/SDKManager/AdsSDKManager/KwaiAdsManager/Data/KwaiAdsConfigParser.cs +++ b/Assets/Script/SDKManager/AdsSDKManager/KwaiAdsManager/Data/KwaiAdsConfigParser.cs @@ -107,7 +107,7 @@ namespace WZ { public string id; public string unite_id; - public int price; + public float price; } [System.Serializable] diff --git a/Assets/Script/SDKManager/AdsSDKManager/KwaiAdsManager/KwaiFloorIvManager.cs b/Assets/Script/SDKManager/AdsSDKManager/KwaiAdsManager/KwaiFloorIvManager.cs index 4ddd5a2..5e266ee 100644 --- a/Assets/Script/SDKManager/AdsSDKManager/KwaiAdsManager/KwaiFloorIvManager.cs +++ b/Assets/Script/SDKManager/AdsSDKManager/KwaiAdsManager/KwaiFloorIvManager.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using GoogleMobileAds.Common; using JetBrains.Annotations; +using KwaiAds.Scripts.Api; using KwaiAds.Scripts.Api.Interstitial; using KwaiAds.Scripts.Api.Reward; using UnityEngine; @@ -21,8 +22,11 @@ namespace WZ private bool _isRequestingFloors = false; private List _currentRequestBatch = new List(); private FloorConfig _successfulFloor = null; - public float _ivStartLoadTime = 0; + private int _waterfallRequestCount = 0; // waterfall请求次数 + private Dictionary _uniteIdRequestCounts = new Dictionary(); // 每个unite_id的请求次数 + private string _currentRequestId; // 当前waterfall请求的ID + public void InitializeWithFloors() { @@ -52,6 +56,9 @@ namespace WZ _successfulFloor = null; _isRequestingFloors = true; + // 增加waterfall请求计数 + _waterfallRequestCount++; + // 清理之前的广告控制器 foreach (var controller in _ivFloorAdControllers.Values) { @@ -97,10 +104,24 @@ namespace WZ private void RequestFloorAd(FloorConfig floor) { - IInterstitialAdController controller = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getInterstitialAdController();; + // 更新unite_id请求计数 + if (!_uniteIdRequestCounts.ContainsKey(floor.unite_id)) + { + _uniteIdRequestCounts[floor.unite_id] = 0; + } + _uniteIdRequestCounts[floor.unite_id]++; + + // 获取当前楼层在排序列表中的位置 + int floorIndex = GetFloorIndex(floor.id); + _currentRequestId = GenerateRequestId(); + LoggerUtils.Debug($"[kwai] floor inter Requesting floor {floor.id} (index: {floorIndex}), unite_id {floor.unite_id} has been requested {_uniteIdRequestCounts[floor.unite_id]} times, request id: {_currentRequestId}"); + + IInterstitialAdController controller = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getInterstitialAdController(); ; _ivFloorAdControllers[floor.id] = controller; KwaiInterstitialAdRequest kwaiInterstitialAdRequest = new KwaiInterstitialAdRequest(floor.unite_id); + kwaiInterstitialAdRequest.ExtParams[Constants.Request.BID_FLOOR_PRICE] = floor.price.ToString(); + controller.Load(kwaiInterstitialAdRequest, new FloorInterAdListener(this, floor), new FloorInterAdLoadListener(this, floor)); @@ -111,7 +132,10 @@ namespace WZ { if (!_isRequestingFloors || _successfulFloor != null) return; - LoggerUtils.Debug($"[kwai] floor inter Floor ad loaded: {floor.id} with price: {floor.price}"); + // 获取当前楼层在排序列表中的位置 + int floorIndex = GetFloorIndex(floor.id); + LoggerUtils.Debug($"[kwai] floor reward Floor ad loaded: {floor.id} (index: {floorIndex}) with price: {floor.price}, unite_id {floor.unite_id} has been requested {_uniteIdRequestCounts[floor.unite_id]} times"); + // 暂停其他并行请求 _successfulFloor = floor; @@ -177,6 +201,53 @@ namespace WZ _action?.Invoke(); } } + + /// + /// 获取当前waterfall请求次数 + /// + public int GetWaterfallRequestCount() + { + return _waterfallRequestCount; + } + + /// + /// 获取当前waterfall请求次数 + /// + public int GetUniteIdRequestCount(string unitId) + { + return _uniteIdRequestCounts.TryGetValue(unitId, out var time) ? time : 0; + } + + /// + /// 根据floor.id获取其在排序后的楼层列表中的索引位置 + /// + public int GetFloorIndex(string floorId) + { + for (int i = 0; i < _sortedFloors.Count; i++) + { + if (_sortedFloors[i].id == floorId) + { + return i; + } + } + return -1; // 未找到 + } + + /// + /// 获取当前Request ID + /// + public string GetCurrentRequestId() + { + return _currentRequestId; + } + + /// + /// 生成唯一的Request ID + /// + private string GenerateRequestId() + { + return Guid.NewGuid().ToString("N"); + } } } diff --git a/Assets/Script/SDKManager/AdsSDKManager/KwaiAdsManager/KwaiFloorRvManager.cs b/Assets/Script/SDKManager/AdsSDKManager/KwaiAdsManager/KwaiFloorRvManager.cs index 338750b..c72dfcc 100644 --- a/Assets/Script/SDKManager/AdsSDKManager/KwaiAdsManager/KwaiFloorRvManager.cs +++ b/Assets/Script/SDKManager/AdsSDKManager/KwaiAdsManager/KwaiFloorRvManager.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; +using KwaiAds.Scripts.Api; using KwaiAds.Scripts.Api.Reward; using UnityEngine; using static WZ.KwaiAdsConfigParser; @@ -19,8 +20,10 @@ namespace WZ private bool _isRequestingFloors = false; private List _currentRequestBatch = new List(); private FloorConfig _successfulFloor = null; - public float _rvStartLoadTime = 0; + private int _waterfallRequestCount = 0; // waterfall请求次数 + private Dictionary _uniteIdRequestCounts = new Dictionary(); // 每个unite_id的请求次数 + private string _currentRequestId; // 当前waterfall请求的ID public void InitializeWithFloors() { @@ -52,6 +55,9 @@ namespace WZ _successfulFloor = null; _isRequestingFloors = true; + + // 增加waterfall请求计数 + _waterfallRequestCount++; // 清理之前的广告控制器 foreach (var controller in _rvFloorAdControllers.Values) { @@ -97,10 +103,24 @@ namespace WZ private void RequestFloorAd(FloorConfig floor) { + // 更新unite_id请求计数 + if (!_uniteIdRequestCounts.ContainsKey(floor.unite_id)) + { + _uniteIdRequestCounts[floor.unite_id] = 0; + } + _uniteIdRequestCounts[floor.unite_id]++; + + // 获取当前楼层在排序列表中的位置 + int floorIndex = GetFloorIndex(floor.id); + _currentRequestId = GenerateRequestId(); + LoggerUtils.Debug($"[kwai] floor reward Requesting floor {floor.id} (index: {floorIndex}), unite_id {floor.unite_id} has been requested {_uniteIdRequestCounts[floor.unite_id]} times, request id: {_currentRequestId}"); + IRewardAdController controller = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getRewardAdController(); _rvFloorAdControllers[floor.id] = controller; KwaiRewardAdRequest kwaiRewardAdRequest = new KwaiRewardAdRequest(floor.unite_id); + kwaiRewardAdRequest.ExtParams[Constants.Request.BID_FLOOR_PRICE] = floor.price.ToString(); + controller.Load(kwaiRewardAdRequest, new FloorRewardAdListener(this, floor), new FloorRewardAdLoadListener(this, floor)); @@ -111,7 +131,9 @@ namespace WZ { if (!_isRequestingFloors || _successfulFloor != null) return; - LoggerUtils.Debug($"[kwai] floor reward ad loaded: {floor.id} with price: {floor.price}"); + // 获取当前楼层在排序列表中的位置 + int floorIndex = GetFloorIndex(floor.id); + LoggerUtils.Debug($"[kwai] floor reward Floor ad loaded: {floor.id} (index: {floorIndex}) with price: {floor.price}, unite_id {floor.unite_id} has been requested {_uniteIdRequestCounts[floor.unite_id]} times"); // 暂停其他并行请求 _successfulFloor = floor; @@ -165,7 +187,7 @@ namespace WZ } public void ShowRewarded(Action _action) - { + { if (_successfulFloor != null && _rvFloorAdControllers.ContainsKey(_successfulFloor.id) && _rvFloorAdControllers[_successfulFloor.id] != null) @@ -177,6 +199,53 @@ namespace WZ _action?.Invoke(); } } + + /// + /// 获取当前waterfall请求次数 + /// + public int GetWaterfallRequestCount() + { + return _waterfallRequestCount; + } + + /// + /// 获取当前waterfall请求次数 + /// + public int GetUniteIdRequestCount(string unitId) + { + return _uniteIdRequestCounts.TryGetValue(unitId, out var time) ? time : 0; + } + + /// + /// 根据floor.id获取其在排序后的楼层列表中的索引位置 + /// + public int GetFloorIndex(string floorId) + { + for (int i = 0; i < _sortedFloors.Count; i++) + { + if (_sortedFloors[i].id == floorId) + { + return i; + } + } + return -1; // 未找到 + } + + /// + /// 获取当前Request ID + /// + public string GetCurrentRequestId() + { + return _currentRequestId; + } + + /// + /// 生成唯一的Request ID + /// + private string GenerateRequestId() + { + return Guid.NewGuid().ToString("N"); + } } } diff --git a/Assets/Script/Test.cs b/Assets/Script/Test.cs index cf17a3d..2499730 100644 --- a/Assets/Script/Test.cs +++ b/Assets/Script/Test.cs @@ -17,7 +17,12 @@ public class Test : MonoBehaviour { small = gameObject.transform.Find("NativeAd-small").GetComponent(); medium = gameObject.transform.Find("NativeAd-medium").GetComponent(); + RushSDKManager.Instance.SetUserSourceListener((bool success, string source) => + { + LoggerUtils.Debug("adjust callback: "+success+" adnetwork:"+source); + }); RushSDKManager.Instance.InitializeSdk(null, true); + } public void OnShowAd()