GameUI.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using Player.Wallet;
  2. using TMPro;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. public class GameUI : MonoBehaviour
  6. {
  7. [SerializeField] private GameObject winnerWrapper, loseWrapper;
  8. [SerializeField]
  9. private TextMeshProUGUI moneyDisplayText, rewardLoseDisplayText, rewardWinDisplayText, levelDisplayText;
  10. [SerializeField] private AudioSource coinAudioSource;
  11. private Wallet _wallet;
  12. private int _rewardLose;
  13. private int _rewardWin;
  14. private bool _isStop;
  15. private int _tempSettingID;
  16. private int _settingID;
  17. private void OnEnable()
  18. {
  19. _wallet = FindObjectOfType<Wallet>();
  20. _wallet.PlayerMoneyEvent += UpdateMoneyText;
  21. }
  22. private void OnDisable()
  23. {
  24. _wallet.PlayerMoneyEvent -= UpdateMoneyText;
  25. }
  26. private void Start()
  27. {
  28. _settingID = PlayerPrefs.GetInt("_settingID");
  29. _tempSettingID = PlayerPrefs.GetInt("_tempSettingID");
  30. print("SETTING ID - " + _settingID);
  31. print("_tempSetting ID - " + _tempSettingID);
  32. levelDisplayText.SetText(I2.Loc.LocalizationManager.GetTranslation("Level") + " " + (ComponentsManager.PlayerData.GetLevel + 1));
  33. }
  34. public void CoiAudioPlay()
  35. {
  36. coinAudioSource.pitch = Random.Range(.9f, 1.1f);
  37. coinAudioSource.Play();
  38. }
  39. public void SetRewards(int win, int lose)
  40. {
  41. _rewardLose = lose;
  42. _rewardWin = win;
  43. rewardLoseDisplayText.SetText("+" + lose);
  44. rewardWinDisplayText.SetText("+" + win);
  45. }
  46. public void PlayerWinner()
  47. {
  48. if (!_isStop)
  49. {
  50. winnerWrapper.SetActive(true);
  51. SetEndEvent();
  52. PlayerPrefs.DeleteKey("_stageLevel");
  53. _isStop = true;
  54. }
  55. }
  56. public void PlayerLose()
  57. {
  58. if (!_isStop)
  59. {
  60. loseWrapper.SetActive(true);
  61. _isStop = true;
  62. SetEndEvent();
  63. }
  64. }
  65. private void UpdateMoneyText(int value)
  66. {
  67. moneyDisplayText.SetText(value.ToString());
  68. }
  69. public void WinButton()
  70. {
  71. _wallet.AddMoney(_rewardWin);
  72. ComponentsManager.PlayerData.AddLevel();
  73. ChangeSetting();
  74. SceneManager.LoadScene(0);
  75. }
  76. public void LoseButton()
  77. {
  78. _wallet.AddMoney(_rewardLose);
  79. SceneManager.LoadScene(0);
  80. }
  81. private void SetEndEvent()
  82. {
  83. }
  84. private void ChangeSetting()
  85. {
  86. _tempSettingID++;
  87. if (_tempSettingID >= 2)
  88. {
  89. _tempSettingID = 0;
  90. if (_settingID >= 2)
  91. _settingID = 0;
  92. else
  93. _settingID++;
  94. PlayerPrefs.SetInt("_settingID", _settingID);
  95. }
  96. PlayerPrefs.SetInt("_tempSettingID", _tempSettingID);
  97. }
  98. }