|
- using System;
- using SUISS.Core;
- using SUISS.Promo;
- using SUISSEngine;
- using UnityEngine;
-
- public class PromoPopupState : PopupBaseState
- {
- private void OnDestroy()
- {
- if (SingletonMonobehaviour<SparkSocGamesPopupScheduler>.IsAvailable)
- {
- SingletonMonobehaviour<SparkSocGamesPopupScheduler>.Instance.ShowPromoPopup -= this.TryShowPromoPopup;
- }
- }
-
- public override void Init()
- {
- base.Init();
- this.PreloadPromo();
- if (SingletonMonobehaviour<SparkSocGamesPopupScheduler>.IsAvailable)
- {
- SparkSocGamesPopupScheduler instance = SingletonMonobehaviour<SparkSocGamesPopupScheduler>.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<WorldMap>.IsAvailable && !SingletonMonobehaviour<WorldMap>.Instance.IsVisible && SingletonMonobehaviour<CIGGameState>.IsAvailable && SingletonMonobehaviour<CIGGameState>.Instance.Level >= 8)
- {
- SingletonMonobehaviour<PopupManager>.Instance.RequestPopup<PromoPopupState>(null);
- if (SingletonMonobehaviour<SparkSocGamesPopupScheduler>.IsAvailable)
- {
- SingletonMonobehaviour<SparkSocGamesPopupScheduler>.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;
-
- }
|