uTweenTimer.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace uTools
  6. {
  7. public class uTweenTimer : uTweenValue
  8. {
  9. private Text m_text;
  10. public Text Text
  11. {
  12. get
  13. {
  14. if (null == m_text)
  15. {
  16. m_text = GetComponent<Text>();
  17. }
  18. return m_text;
  19. }
  20. }
  21. [SerializeField]
  22. string format;
  23. [SerializeField]
  24. int digitSize;
  25. System.Text.StringBuilder sb = new System.Text.StringBuilder(256);
  26. const string size1 = ":<size=";
  27. const string size2 = ">";
  28. const string size3 = "</size>";
  29. const string zero = "0";
  30. protected override void ValueUpdate(float value, bool isFinished)
  31. {
  32. string[] result = value.ToString(format).Split('.');
  33. sb.Length = 0;
  34. if (value < 10)
  35. {
  36. sb.Append(zero);
  37. }
  38. sb.Append(result[0]);
  39. sb.Append(size1);
  40. sb.Append(digitSize);
  41. sb.Append(size2);
  42. sb.Append(result[1]);
  43. sb.Append(size3);
  44. Text.text = sb.ToString();
  45. }
  46. public void SetValue(float value)
  47. {
  48. this.value = value;
  49. ValueUpdate(value, false);
  50. }
  51. }
  52. }