TestUiSlider.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using DG.Tweening;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using TMPro;
  5. using UnityEngine;
  6. public class TestUiSlider : MonoBehaviour
  7. {
  8. public Transform parten;
  9. public Transform left;
  10. public Transform right;
  11. public TextMeshProUGUI txt_left;
  12. public TextMeshProUGUI txt_Right;
  13. // Start is called before the first frame update
  14. void Start()
  15. {
  16. }
  17. public void Leftinit(double value, double upper, double lower = 0)
  18. {
  19. if (left == null)
  20. {
  21. return;
  22. }
  23. if (txt_left != null)
  24. {
  25. txt_left.text = value.ToString();
  26. }
  27. if (value > upper )
  28. {
  29. value = upper;
  30. //Êý¾ÝÒì³£
  31. }
  32. if (value < lower)
  33. {
  34. value = lower;
  35. }
  36. float date = (float)(value - lower);
  37. float data = (float)(upper - lower);
  38. float height = parten.GetComponent<RectTransform>().rect.height;
  39. float y = (float)(date / data) * height;
  40. left.DOLocalMoveY(y, 0.5f);
  41. }
  42. public void Rightinit(double value, double upper,double lower = 0)
  43. {
  44. if (right == null )
  45. {
  46. return;
  47. }
  48. if (txt_Right != null)
  49. {
  50. txt_Right.text = value.ToString();
  51. }
  52. if (value>upper)
  53. {
  54. value = upper;
  55. //Êý¾ÝÒì³£
  56. }
  57. if (value < lower)
  58. {
  59. value = lower;
  60. }
  61. float date =(float) (value - lower);
  62. float data = (float)(upper - lower);
  63. float height = parten.GetComponent<RectTransform>().rect.height;
  64. float y = (float)(date / data) * height;
  65. right.DOLocalMoveY(y, 0.5f);
  66. }
  67. }