HurtNumberAnim.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. public class HurtNumberAnim : MonoBehaviour
  5. {
  6. private void Start()
  7. {
  8. this._label = base.GetComponentInChildren<UILabel>();
  9. this._widget = base.GetComponent<UIWidget>();
  10. this._widget.transform.position += new Vector3(UnityEngine.Random.Range(-0.15f, 0.15f), UnityEngine.Random.Range(-0.15f, 0.15f));
  11. this._fontSize = this._label.fontSize;
  12. this._label.fontSize = 0;
  13. base.StartCoroutine(this.AnimationCoroutine());
  14. }
  15. private IEnumerator AnimationCoroutine()
  16. {
  17. while (this._widget.alpha < 1f || this._label.fontSize < this._fontSize)
  18. {
  19. if (!WorldTime.IsPausing)
  20. {
  21. if (this._widget.alpha < 1f)
  22. {
  23. this._widget.alpha += 8f * Time.deltaTime;
  24. }
  25. if (this._label.fontSize < this._fontSize)
  26. {
  27. HurtNumberAnim.TypeEnum typeEnum = this.type;
  28. if (typeEnum != HurtNumberAnim.TypeEnum.Normal)
  29. {
  30. if (typeEnum == HurtNumberAnim.TypeEnum.Crit)
  31. {
  32. this._label.fontSize += 30;
  33. }
  34. }
  35. else
  36. {
  37. this._label.fontSize += 40;
  38. }
  39. }
  40. }
  41. yield return null;
  42. }
  43. for (int i = 0; i < 30; i++)
  44. {
  45. if (!WorldTime.IsPausing)
  46. {
  47. this._widget.transform.position += new Vector3(0f, Time.deltaTime * 0.5f);
  48. }
  49. else
  50. {
  51. i--;
  52. }
  53. yield return null;
  54. }
  55. while (this._widget.alpha > 0f)
  56. {
  57. if (!WorldTime.IsPausing)
  58. {
  59. this._widget.alpha -= 4f * Time.deltaTime;
  60. HurtNumberAnim.TypeEnum typeEnum2 = this.type;
  61. if (typeEnum2 != HurtNumberAnim.TypeEnum.Normal)
  62. {
  63. if (typeEnum2 == HurtNumberAnim.TypeEnum.Crit)
  64. {
  65. this._label.fontSize -= 40;
  66. }
  67. }
  68. else
  69. {
  70. this._widget.transform.position += new Vector3(0f, Time.deltaTime * 5f);
  71. this._label.fontSize -= 10;
  72. }
  73. }
  74. yield return null;
  75. }
  76. yield break;
  77. }
  78. [SerializeField]
  79. private HurtNumberAnim.TypeEnum type;
  80. private UILabel _label;
  81. private UIWidget _widget;
  82. private Vector3 _lastRandomDelta = Vector3.zero;
  83. private int _fontSize;
  84. private enum TypeEnum
  85. {
  86. Normal,
  87. Crit
  88. }
  89. }