using System; using System.Collections; using System.Diagnostics; using System.Globalization; using SUISS.Core; using UnityEngine; namespace SUISS.Promo { public sealed class SparkSocGamesPopupScheduler : SingletonMonobehaviour { public TimeSpan TimeBetweenPromoPopup { get { return this._timeBetweenPromoPopup; } set { this._timeBetweenPromoPopup = value; } } public void DidShowPromo() { this.LastPromoPopupDay = DateTime.UtcNow; } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event Action ShowPromoPopup; protected override void OnDestroy() { if (this._isValidNewInstance) { base.OnDestroy(); } if (this._promoRoutine != null) { base.StopCoroutine(this._promoRoutine); this._promoRoutine = null; } } protected override void Awake() { base.Awake(); if (!this._isValidNewInstance) { return; } base.StartCoroutine(this._promoRoutine = this.InGameCrossSellingPromoRoutine()); if (base.transform.parent != null) { base.transform.parent = null; } UnityEngine.Object.DontDestroyOnLoad(base.gameObject); } private IEnumerator InGameCrossSellingPromoRoutine() { for (;;) { if (this.TimeToNextPopup < 1f && this.ShowPromoPopup != null) { this.ShowPromoPopup(); } yield return new WaitForSeconds(5f); } yield break; } private float TimeToNextPopup { get { return (float)(this.LastPromoPopupDay + this.TimeBetweenPromoPopup - DateTime.UtcNow).TotalSeconds; } } private DateTime LastPromoPopupDay { get { long ticks; if (PlayerPrefs.HasKey("SparkSocGames.LastPromoPopup2") && long.TryParse(PlayerPrefs.GetString("SparkSocGames.LastPromoPopup2"), out ticks)) { return new DateTime(ticks, DateTimeKind.Utc); } ticks = (DateTime.UtcNow - this._timeBetweenPromoPopup).Ticks; PlayerPrefs.SetString("SparkSocGames.LastPromoPopup2", ticks.ToString(CultureInfo.InvariantCulture)); return new DateTime(ticks, DateTimeKind.Utc); } set { PlayerPrefs.SetString("SparkSocGames.LastPromoPopup2", value.Ticks.ToString(CultureInfo.InvariantCulture)); } } private TimeSpan _timeBetweenPromoPopup = TimeSpan.FromDays(2.0); private IEnumerator _promoRoutine; private const string LastPromoPopupKey = "SparkSocGames.LastPromoPopup2"; } }