UIHitsGradeController.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using DG.Tweening;
  3. using UnityEngine;
  4. public class UIHitsGradeController : MonoBehaviour
  5. {
  6. private void Start()
  7. {
  8. }
  9. private void Update()
  10. {
  11. if (this.hitNum < 40)
  12. {
  13. this._demageText.alpha = 0f;
  14. }
  15. else
  16. {
  17. this._demageText.alpha = 1f;
  18. if (this.hitNum < 80)
  19. {
  20. this._infoLabel.text = "+10%";
  21. }
  22. else if (this.hitNum < 120)
  23. {
  24. this._infoLabel.text = "+20%";
  25. }
  26. else
  27. {
  28. this._infoLabel.text = "+50%";
  29. }
  30. }
  31. }
  32. public void BeHited()
  33. {
  34. if (!this.hitsNumLabel.isActiveAndEnabled && !this.hitBar.isActiveAndEnabled && this.hitNum == 1)
  35. {
  36. this.hitsNumLabel.gameObject.SetActive(true);
  37. this.hitBar.gameObject.SetActive(true);
  38. }
  39. this.hitNum++;
  40. this.hitsNumLabel.text = this.hitNum.ToString();
  41. if (!DOTween.IsTweening(this.hitsNumLabel.transform, false))
  42. {
  43. this.hitsNumLabel.transform.DOShakePosition(0.2f, (float)this.shakeRange * Vector3.one, 100, 90f, false, true).OnStart(delegate
  44. {
  45. this.hitsNumLabel.color = Color.yellow;
  46. }).OnComplete(delegate
  47. {
  48. this.hitsNumLabel.color = Color.white;
  49. });
  50. }
  51. }
  52. public void HideHitNumAndBar()
  53. {
  54. this.hitNum = 0;
  55. this.hitsNumLabel.gameObject.SetActive(false);
  56. this.hitBar.gameObject.SetActive(false);
  57. }
  58. public float Hitbar
  59. {
  60. get
  61. {
  62. return this.hitBar.value;
  63. }
  64. set
  65. {
  66. this.hitBar.value = Mathf.Clamp01(value);
  67. }
  68. }
  69. [SerializeField]
  70. private UILabel hitsNumLabel;
  71. [SerializeField]
  72. private UIProgressBar hitBar;
  73. [SerializeField]
  74. private UILabel _demageText;
  75. [SerializeField]
  76. private UILabel _infoLabel;
  77. [SerializeField]
  78. [Range(0f, 100f)]
  79. private int shakeRange;
  80. private int hitNum;
  81. }