UISliderScroll.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. [RequireComponent(typeof(Slider))]
  5. public class UISliderScroll : MonoBehaviour
  6. {
  7. private Slider slider
  8. {
  9. get
  10. {
  11. if (this.m_Slider == null)
  12. {
  13. this.m_Slider = base.GetComponent<Slider>();
  14. }
  15. return this.m_Slider;
  16. }
  17. }
  18. public void SetSliderValue(Vector2 position)
  19. {
  20. this.slider.value = ((!this.m_IsXValue) ? position.y : position.x);
  21. if (this.m_ScrollRect == null)
  22. {
  23. return;
  24. }
  25. RectTransform component = this.m_ScrollRect.GetComponent<RectTransform>();
  26. Rect rect = component.rect;
  27. Rect rect2 = this.m_ScrollRect.content.rect;
  28. float num;
  29. if (this.m_IsXValue)
  30. {
  31. num = rect2.width - rect.width;
  32. }
  33. else
  34. {
  35. num = rect2.height - rect.height;
  36. }
  37. this.m_SliderObject.SetActive(num > 0f);
  38. }
  39. [SerializeField]
  40. [Tooltip("スクロールの必要がないときに非表示にするゲームオブジェクトの参照")]
  41. private GameObject m_SliderObject;
  42. [SerializeField]
  43. private ScrollRect m_ScrollRect;
  44. public bool m_IsXValue;
  45. private Slider m_Slider;
  46. }