Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

107 wiersze
2.5 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Diagnostics;
  4. using System.Globalization;
  5. using SUISS.Core;
  6. using UnityEngine;
  7. namespace SUISS.Promo
  8. {
  9. public sealed class SparkSocGamesPopupScheduler : SingletonMonobehaviour<SparkSocGamesPopupScheduler>
  10. {
  11. public TimeSpan TimeBetweenPromoPopup
  12. {
  13. get
  14. {
  15. return this._timeBetweenPromoPopup;
  16. }
  17. set
  18. {
  19. this._timeBetweenPromoPopup = value;
  20. }
  21. }
  22. public void DidShowPromo()
  23. {
  24. this.LastPromoPopupDay = DateTime.UtcNow;
  25. }
  26. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  27. public event Action ShowPromoPopup;
  28. protected override void OnDestroy()
  29. {
  30. if (this._isValidNewInstance)
  31. {
  32. base.OnDestroy();
  33. }
  34. if (this._promoRoutine != null)
  35. {
  36. base.StopCoroutine(this._promoRoutine);
  37. this._promoRoutine = null;
  38. }
  39. }
  40. protected override void Awake()
  41. {
  42. base.Awake();
  43. if (!this._isValidNewInstance)
  44. {
  45. return;
  46. }
  47. base.StartCoroutine(this._promoRoutine = this.InGameCrossSellingPromoRoutine());
  48. if (base.transform.parent != null)
  49. {
  50. base.transform.parent = null;
  51. }
  52. UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
  53. }
  54. private IEnumerator InGameCrossSellingPromoRoutine()
  55. {
  56. for (;;)
  57. {
  58. if (this.TimeToNextPopup < 1f && this.ShowPromoPopup != null)
  59. {
  60. this.ShowPromoPopup();
  61. }
  62. yield return new WaitForSeconds(5f);
  63. }
  64. yield break;
  65. }
  66. private float TimeToNextPopup
  67. {
  68. get
  69. {
  70. return (float)(this.LastPromoPopupDay + this.TimeBetweenPromoPopup - DateTime.UtcNow).TotalSeconds;
  71. }
  72. }
  73. private DateTime LastPromoPopupDay
  74. {
  75. get
  76. {
  77. long ticks;
  78. if (PlayerPrefs.HasKey("SparkSocGames.LastPromoPopup2") && long.TryParse(PlayerPrefs.GetString("SparkSocGames.LastPromoPopup2"), out ticks))
  79. {
  80. return new DateTime(ticks, DateTimeKind.Utc);
  81. }
  82. ticks = (DateTime.UtcNow - this._timeBetweenPromoPopup).Ticks;
  83. PlayerPrefs.SetString("SparkSocGames.LastPromoPopup2", ticks.ToString(CultureInfo.InvariantCulture));
  84. return new DateTime(ticks, DateTimeKind.Utc);
  85. }
  86. set
  87. {
  88. PlayerPrefs.SetString("SparkSocGames.LastPromoPopup2", value.Ticks.ToString(CultureInfo.InvariantCulture));
  89. }
  90. }
  91. private TimeSpan _timeBetweenPromoPopup = TimeSpan.FromDays(2.0);
  92. private IEnumerator _promoRoutine;
  93. private const string LastPromoPopupKey = "SparkSocGames.LastPromoPopup2";
  94. }
  95. }