using System; using SUISS.Core; using SUISS.Promo; using SUISSEngine; using UnityEngine; public class PromoPopupState : PopupBaseState { private void OnDestroy() { if (SingletonMonobehaviour.IsAvailable) { SingletonMonobehaviour.Instance.ShowPromoPopup -= this.TryShowPromoPopup; } } public override void Init() { base.Init(); this.PreloadPromo(); if (SingletonMonobehaviour.IsAvailable) { SparkSocGamesPopupScheduler instance = SingletonMonobehaviour.Instance; instance.TimeBetweenPromoPopup = TimeSpan.FromHours(1.0); instance.ShowPromoPopup += this.TryShowPromoPopup; } } public override void Enter(State oldState, bool openView) { base.Enter(oldState, openView); ((PromoPopupView)this.View).SetSparkSocGame(this._game); } public override void ClosePopup(Action callback, bool animate, bool synchronous) { base.ClosePopup(callback, animate, synchronous); this.PreloadPromo(); } public void OpenPromoInStore() { if (this._game != null) { this._game.OpenInAppStore(); } } private void TryShowPromoPopup() { if (this.IsPreloaded && Time.timeSinceLevelLoad > 60f && SingletonMonobehaviour.IsAvailable && !SingletonMonobehaviour.Instance.IsVisible && SingletonMonobehaviour.IsAvailable && SingletonMonobehaviour.Instance.Level >= 8) { SingletonMonobehaviour.Instance.RequestPopup(null); if (SingletonMonobehaviour.IsAvailable) { SingletonMonobehaviour.Instance.DidShowPromo(); this._ssGames.DidShowPromo(this._game); } } } private void PreloadPromo() { this._game = null; this._ssGames.GetPromoItem(delegate(SparkSocGame promoGame) { this._game = promoGame; }); } private bool IsPreloaded { get { return this._game != null; } } [SerializeField] private SparkSocGames _ssGames; private SparkSocGame _game; }