SDK_UnityMoney/Assets/Script/SDKManager/AdsSDKManager/Utils/AdPlayCountManager.cs

55 lines
1.5 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using Script.SDKManager.AdsSDKManager.Constant;
using Script.Utils;
using UnityEngine;
namespace Script.SDKManager.AdsSDKManager.Utils
{
public class AdPlayCountManager
{
private const string PLAY_COUNT_SUFFIX = "_PLAY_COUNT";
public static int GetAdPlayCount(AdsType adsType)
{
try
{
string key = GetPlayCountKey(adsType);
return PlayerPrefsUtils.GetPlayerPrefsInt(key, 0);
}
catch (Exception ex)
{
LoggerUtils.Error($"获取广告播放次数失败: {ex.Message}");
return 0;
}
}
public static void SetAdPlayCount(AdsType adsType, int count)
{
try
{
string key = GetPlayCountKey(adsType);
PlayerPrefsUtils.SavePlayerPrefsInt(key, count);
}
catch (Exception ex)
{
LoggerUtils.Error($"设置广告播放次数失败: {ex.Message}");
}
}
public static void IncrementAdPlayCount(AdsType adsType)
{
int currentCount = GetAdPlayCount(adsType);
SetAdPlayCount(adsType, currentCount + 1);
}
private static string GetPlayCountKey(AdsType adsType)
{
return $"{adsType}{PLAY_COUNT_SUFFIX}";
}
}
}