NoLivesLeftDetector.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. public class NoLivesLeftDetector : MonoBehaviour
  5. {
  6. public static NoLivesLeftDetector Instance;
  7. public ScreenBase noLivesLeftScreen;
  8. public ScreenBase noLivesLeftScreenTime;
  9. public ScreenBase NoLivesAddFriendForOneLiveGameOver;
  10. void Awake()
  11. {
  12. Instance = this;
  13. NotificationCenter.AddListener(OnTriedPlayingWithoutLivesLeft, NotificationType.TriedPlayingWithoutLivesLeft);
  14. }
  15. void OnDestroy()
  16. {
  17. NotificationCenter.RemoveListener(OnTriedPlayingWithoutLivesLeft, NotificationType.TriedPlayingWithoutLivesLeft);
  18. }
  19. void OnTriedPlayingWithoutLivesLeft(Notification note)
  20. {
  21. var curLive = LivesManager.Instance.Lives;
  22. //Debug.Log(curLive);
  23. if (curLive == 0)
  24. {
  25. var countLifeInDay = PlayerPrefs.GetInt("CounterLifeInDay");
  26. Debug.Log("countLifeInDay " + countLifeInDay);
  27. if (countLifeInDay < 1)
  28. {
  29. NoLivesLeftDetector.Instance.NoLivesAddFriendForOneLiveGameOver.Show();
  30. }
  31. else if (countLifeInDay == 1)
  32. {
  33. MenuManager._instance.NoLivesShowAdInGame.Show();
  34. }
  35. else
  36. {
  37. LivesManager.Instance.AddLife();
  38. PlayerPrefs.SetInt("CounterLifeInDay",0);
  39. PlayerPrefs.SetInt("Level", 1);
  40. PlayerPrefs.Save();
  41. //LivesManager.Instance.RechargeLife();
  42. }
  43. //FacebookHelper.Instance.commonInfoDialog.SetTitleAndText("wait.title".ToUpper(), string.Format(Localization.instance.Get("wait.text"),LivesManager.Instance.TimeForLife.Hours, LivesManager.Instance.TimeForLife.Minutes));
  44. //FacebookHelper.Instance.commonInfoDialog.Show();
  45. //MenuManager._instance.NoLivesShowAdInGame.Show();
  46. }
  47. else if (curLive == 1)
  48. {
  49. noLivesLeftScreen.Show();
  50. MenuManager._instance.UpdateCircle();
  51. //PlayerPrefs.SetInt("Live", 2);
  52. }
  53. else
  54. {
  55. LivesManager.Instance.RechargeLife();
  56. //PlayerPrefs.SetInt("Level", 0);
  57. PlayerPrefs.SetInt("Live", 0);
  58. PlayerPrefs.Save();
  59. noLivesLeftScreenTime.Show();
  60. }
  61. }
  62. }