HudText.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Collections;
  5. public class HudText : Regist
  6. {
  7. #region 变量
  8. public Text Text
  9. {
  10. get
  11. {
  12. if (Text_ == null)
  13. {
  14. Text_ = GetComponent<Text>();
  15. }
  16. return Text_;
  17. }
  18. set { Text_ = value; }
  19. }
  20. public Text Text_;
  21. public float Speed;
  22. public float StayTimer;
  23. public bool Lock;
  24. #endregion
  25. public override bool RegistImmed()
  26. {
  27. if (base.RegistImmed())
  28. {
  29. return true;
  30. }
  31. enabled = true;
  32. return false;
  33. }
  34. private void FixedUpdate()
  35. {
  36. StayTimer -= Time.fixedDeltaTime;
  37. if (StayTimer < 0)
  38. {
  39. if (!Lock)
  40. {
  41. Lock = true;
  42. Text.TweenForCG();
  43. }
  44. transform.position += new Vector3(0, Speed * Time.fixedDeltaTime, 0);
  45. }
  46. }
  47. public void Show(string str, Color color, int size, float speed, float time, float stay)
  48. {
  49. Text.text = str;
  50. Text.color = color;
  51. Text.fontSize = size;
  52. Lock = false;
  53. Speed = speed;
  54. StayTimer = stay;
  55. TweenCG tween = Text.CreateTweenCG(1, 0, time, true, true, Curve.EaseOutQuad);
  56. tween.CanvasGroup.alpha = 1;
  57. tween.AddEventOnetime
  58. (
  59. EventType.ForwardFinish,
  60. () =>
  61. {
  62. ManaReso.Save(gameObject);
  63. }
  64. );
  65. }
  66. }