HudTextPlus.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public class HudTextPlus : MonoBehaviour
  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 Outline Outline
  21. {
  22. get
  23. {
  24. if (Outline_ == null)
  25. {
  26. Outline_ = GetComponent<Outline>();
  27. }
  28. return Outline_;
  29. }
  30. set { Outline_ = value; }
  31. }
  32. public Text Text_;
  33. public Outline Outline_;
  34. public float Speed;
  35. public Mode MoveMode;
  36. public Vector3 Direction;
  37. #endregion
  38. public enum Mode
  39. {
  40. Position,
  41. Direction,
  42. }
  43. public void Update()
  44. {
  45. if (MoveMode == Mode.Direction)
  46. {
  47. transform.position += Direction * Speed * Time.deltaTime;
  48. }
  49. }
  50. public void SetTween(float time, Color origin, Color dest)
  51. {
  52. TweenRoot tween = Text.CreateTweenGra(origin, dest, time, false, false, Curve.EaseOutQuad);
  53. tween.StartForward();
  54. tween.OnForwardFinish = () =>
  55. {
  56. ResourceManager.Save(gameObject);
  57. };
  58. TextPlus textPlus = Text.GetComponent<TextPlus>();
  59. if (textPlus != null)
  60. {
  61. if (textPlus.ImagePlus.Draw)
  62. {
  63. Color color = textPlus.ImagePlus.color;
  64. textPlus.ImagePlus.CreateTweenGra(color*origin, color*dest, time, true, true, Curve.EaseOutQuad);
  65. }
  66. }
  67. }
  68. public void SetOutline(Color color, Vector2 size)
  69. {
  70. Outline.effectColor = color;
  71. Outline.effectDistance = size;
  72. }
  73. public void SetDirection(Vector3 direction)
  74. {
  75. Direction = direction;
  76. }
  77. public void Show(string str, int size, float speed)
  78. {
  79. MoveMode = Mode.Direction;
  80. Outline.enabled = false;
  81. Text.text = str;
  82. Text.color = Color.white;
  83. Text.fontSize = size;
  84. Speed = speed;
  85. Direction = Vector3.up;
  86. }
  87. public void Show(string str, int size, float time, Vector3 dest)
  88. {
  89. MoveMode = Mode.Position;
  90. Outline.enabled = false;
  91. Text.text = str;
  92. Text.color = Color.white;
  93. Text.fontSize = size;
  94. Direction = Vector3.up;
  95. TweenRoot tween = Text.CreateTweenVec2D(dest, time, false, true, true, Curve.EaseOutQuad);
  96. tween.StartForward();
  97. }
  98. public void Show(string str, int size, float time, Vector3 origin, Vector3 dest)
  99. {
  100. MoveMode = Mode.Position;
  101. Outline.enabled = false;
  102. Text.text = str;
  103. Text.fontSize = size;
  104. Direction = Vector3.up;
  105. TweenRoot tween = Text.CreateTweenVec2D(origin, dest, time, false, true, true, Curve.EaseOutQuad);
  106. tween.StartForward();
  107. }
  108. }