UIFlashController.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using DG.Tweening;
  3. using ExtensionMethods;
  4. using UnityEngine;
  5. public class UIFlashController : MonoBehaviour
  6. {
  7. private void Start()
  8. {
  9. this._currentFlashLevel = R.Player.Attribute.flashLevel;
  10. if (R.Player.Attribute.flashLevel > 1)
  11. {
  12. this._flashItems[3].gameObject.SetActive(true);
  13. this._flashItems[4].gameObject.SetActive(true);
  14. }
  15. else
  16. {
  17. this._flashItems[3].gameObject.SetActive(false);
  18. this._flashItems[4].gameObject.SetActive(false);
  19. }
  20. }
  21. private void Update()
  22. {
  23. if (this._isShown)
  24. {
  25. float? lastTimeFilled = this._lastTimeFilled;
  26. if (lastTimeFilled != null)
  27. {
  28. float? lastTimeFilled2 = this._lastTimeFilled;
  29. if (((lastTimeFilled2 == null) ? null : new float?(Time.time - lastTimeFilled2.GetValueOrDefault())) > 5f)
  30. {
  31. this._lastTimeFilled = null;
  32. this.Disappear();
  33. }
  34. }
  35. }
  36. if (this._currentFlashLevel != R.Player.Attribute.flashLevel)
  37. {
  38. if (R.Player.Attribute.flashLevel > 1)
  39. {
  40. this._flashItems[3].gameObject.SetActive(true);
  41. this._flashItems[4].gameObject.SetActive(true);
  42. }
  43. else
  44. {
  45. this._flashItems[3].gameObject.SetActive(false);
  46. this._flashItems[4].gameObject.SetActive(false);
  47. }
  48. this._grid.Reposition();
  49. this._currentFlashLevel = R.Player.Attribute.flashLevel;
  50. }
  51. }
  52. public void OnFlash(int id)
  53. {
  54. this.Appear();
  55. this._flashItems[id].Disapper();
  56. }
  57. public void OnRecover(int id, bool isFilled)
  58. {
  59. this._flashItems[id].Appear();
  60. if (isFilled)
  61. {
  62. this._lastTimeFilled = new float?(Time.time);
  63. }
  64. else
  65. {
  66. this._lastTimeFilled = null;
  67. }
  68. }
  69. public void RecoverAll(int count)
  70. {
  71. for (int i = 0; i < count; i++)
  72. {
  73. this._flashItems[i].Appear();
  74. }
  75. }
  76. private void Appear()
  77. {
  78. if (this._appearTweener != null && this._appearTweener.IsPlaying())
  79. {
  80. return;
  81. }
  82. if (this._disappearTweener != null && this._disappearTweener.IsPlaying())
  83. {
  84. this._disappearTweener.Kill(false);
  85. this._isShown = false;
  86. }
  87. if (this._isShown)
  88. {
  89. return;
  90. }
  91. this._appearTweener = this._widget.DOFade(1f, 0.5f).OnComplete(delegate
  92. {
  93. this._isShown = true;
  94. });
  95. }
  96. private void Disappear()
  97. {
  98. this._disappearTweener = this._widget.DOFade(0f, 0.5f).OnComplete(delegate
  99. {
  100. this._isShown = false;
  101. });
  102. }
  103. [SerializeField]
  104. private UIWidget _widget;
  105. [SerializeField]
  106. private UIGrid _grid;
  107. [SerializeField]
  108. private UIFlashItem[] _flashItems;
  109. private const int AutoDisappearDelay = 5;
  110. private float? _lastTimeFilled;
  111. private bool _isShown;
  112. private int _currentFlashLevel;
  113. private Tweener _appearTweener;
  114. private Tweener _disappearTweener;
  115. }