生成RequestId,请求次数,每个unit请求次数
This commit is contained in:
parent
65e5cec021
commit
3549e77193
|
@ -107,7 +107,7 @@ namespace WZ
|
|||
{
|
||||
public string id;
|
||||
public string unite_id;
|
||||
public int price;
|
||||
public float price;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
|
|
@ -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<FloorConfig> _currentRequestBatch = new List<FloorConfig>();
|
||||
private FloorConfig _successfulFloor = null;
|
||||
|
||||
public float _ivStartLoadTime = 0;
|
||||
private int _waterfallRequestCount = 0; // waterfall请求次数
|
||||
private Dictionary<string, int> _uniteIdRequestCounts = new Dictionary<string, int>(); // 每个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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前waterfall请求次数
|
||||
/// </summary>
|
||||
public int GetWaterfallRequestCount()
|
||||
{
|
||||
return _waterfallRequestCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前waterfall请求次数
|
||||
/// </summary>
|
||||
public int GetUniteIdRequestCount(string unitId)
|
||||
{
|
||||
return _uniteIdRequestCounts.TryGetValue(unitId, out var time) ? time : 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据floor.id获取其在排序后的楼层列表中的索引位置
|
||||
/// </summary>
|
||||
public int GetFloorIndex(string floorId)
|
||||
{
|
||||
for (int i = 0; i < _sortedFloors.Count; i++)
|
||||
{
|
||||
if (_sortedFloors[i].id == floorId)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1; // 未找到
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前Request ID
|
||||
/// </summary>
|
||||
public string GetCurrentRequestId()
|
||||
{
|
||||
return _currentRequestId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成唯一的Request ID
|
||||
/// </summary>
|
||||
private string GenerateRequestId()
|
||||
{
|
||||
return Guid.NewGuid().ToString("N");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<FloorConfig> _currentRequestBatch = new List<FloorConfig>();
|
||||
private FloorConfig _successfulFloor = null;
|
||||
|
||||
public float _rvStartLoadTime = 0;
|
||||
private int _waterfallRequestCount = 0; // waterfall请求次数
|
||||
private Dictionary<string, int> _uniteIdRequestCounts = new Dictionary<string, int>(); // 每个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;
|
||||
|
@ -177,6 +199,53 @@ namespace WZ
|
|||
_action?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前waterfall请求次数
|
||||
/// </summary>
|
||||
public int GetWaterfallRequestCount()
|
||||
{
|
||||
return _waterfallRequestCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前waterfall请求次数
|
||||
/// </summary>
|
||||
public int GetUniteIdRequestCount(string unitId)
|
||||
{
|
||||
return _uniteIdRequestCounts.TryGetValue(unitId, out var time) ? time : 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据floor.id获取其在排序后的楼层列表中的索引位置
|
||||
/// </summary>
|
||||
public int GetFloorIndex(string floorId)
|
||||
{
|
||||
for (int i = 0; i < _sortedFloors.Count; i++)
|
||||
{
|
||||
if (_sortedFloors[i].id == floorId)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1; // 未找到
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前Request ID
|
||||
/// </summary>
|
||||
public string GetCurrentRequestId()
|
||||
{
|
||||
return _currentRequestId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成唯一的Request ID
|
||||
/// </summary>
|
||||
private string GenerateRequestId()
|
||||
{
|
||||
return Guid.NewGuid().ToString("N");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,12 @@ public class Test : MonoBehaviour
|
|||
{
|
||||
small = gameObject.transform.Find("NativeAd-small").GetComponent<RectTransform>();
|
||||
medium = gameObject.transform.Find("NativeAd-medium").GetComponent<RectTransform>();
|
||||
RushSDKManager.Instance.SetUserSourceListener((bool success, string source) =>
|
||||
{
|
||||
LoggerUtils.Debug("adjust callback: "+success+" adnetwork:"+source);
|
||||
});
|
||||
RushSDKManager.Instance.InitializeSdk(null, true);
|
||||
|
||||
}
|
||||
|
||||
public void OnShowAd()
|
||||
|
|
Loading…
Reference in New Issue