using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace WZ { public class AdPlayCountManager { private const string PLAY_COUNT_SUFFIX = "_PLAY_COUNT"; #region 关键事件数据 public static int GetKeyEventPlayCount(string key) { try { return PlayerPrefsUtils.GetPlayerPrefsInt(key, 0); } catch (Exception ex) { return 0; } } public static void SetKeyEventPlayCount(string key, int count) { try { PlayerPrefsUtils.SavePlayerPrefsInt(key, count); } catch (Exception ex) { } } public static void IncrementKeyEventPlayCount(string key) { int currentCount = GetKeyEventPlayCount(key); SetKeyEventPlayCount(key, currentCount + 1); } #endregion #region 关键事件加载次数 public static int GetKeyEventFPUCount(string key) { try { return PlayerPrefsUtils.GetPlayerPrefsInt(key, 0); } catch (Exception ex) { return 0; } } public static void SetKeyEventFPUCount(string key, int count) { try { PlayerPrefsUtils.SavePlayerPrefsInt(key, count); } catch (Exception ex) { } } public static void IncrementKeyEventFPUCount(string key) { int currentCount = GetKeyEventFPUCount(key); SetKeyEventFPUCount(key, currentCount + 1); } #endregion #region 关键事件总revenue public static float GetKeyEventTotalRevenue(string key) { try { return PlayerPrefsUtils.GetPlayerPrefsFloat(key, 0); } catch (Exception ex) { return 0; } } public static void SetKeyEventTotalRevenue(string key, float count) { try { PlayerPrefsUtils.SavePlayerPrefsFloat(key, count); } catch (Exception ex) { } } public static void IncrementKeyEventTotalRevenue(string key, float revenue) { float currentCount = GetKeyEventTotalRevenue(key); SetKeyEventTotalRevenue(key, currentCount + revenue); } public static void ResetKeyEventTotalRevenue(string key) { SetKeyEventTotalRevenue(key, 0); } #endregion 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}"; } } }