AdMobEngagement.cs 869 B

12345678910111213141516171819202122232425
  1. using UnityEngine;
  2. /// <summary>
  3. /// Tracks completed level runs for ad pacing. Stored in PlayerPrefs so Reset Save does not clear it.
  4. /// </summary>
  5. public static class AdMobEngagement
  6. {
  7. public const int MinRoundsBeforeNonRewardedAds = 10;
  8. const string RoundsPlayedKey = "CrazyFruit.AdMob.RoundsPlayed";
  9. public static int RoundsPlayed => PlayerPrefs.GetInt(RoundsPlayedKey, 0);
  10. public static bool NonRewardedAdsEnabled => RoundsPlayed >= MinRoundsBeforeNonRewardedAds;
  11. /// <summary>Call when a level run ends (win or final loss).</summary>
  12. public static bool RecordRoundCompleted()
  13. {
  14. int before = RoundsPlayed;
  15. int after = before + 1;
  16. PlayerPrefs.SetInt(RoundsPlayedKey, after);
  17. PlayerPrefs.Save();
  18. return before < MinRoundsBeforeNonRewardedAds && after >= MinRoundsBeforeNonRewardedAds;
  19. }
  20. }