using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.UI; using XRTool.Util; namespace XRTool.WorldUI { public class XRSlider : Slider { private SliderPointEvent onSliderDown; private SliderPointEvent onSliderUp; private RectTransform body; private RectTransform rect3D; public RectTransform Rect3D { get { if (!rect3D) { var obj = fillRect.GetComponentInChildren(); if (obj) { rect3D = obj.GetComponent(); } } return rect3D; } set => rect3D = value; } public SliderPointEvent OnSliderDown { get { if (onSliderDown == null) { onSliderDown = new SliderPointEvent(); } return onSliderDown; } } public SliderPointEvent OnSliderUp { get { if (onSliderUp == null) { onSliderUp = new SliderPointEvent(); } return onSliderUp; } } protected override void Awake() { base.Awake(); body = GetComponent(); onValueChanged.AddListener((float f)=>{ UpdateSlider(); }); } public override void OnPointerDown(PointerEventData eventData) { base.OnPointerDown(eventData); onSliderDown?.Invoke(eventData); } public override void OnPointerUp(PointerEventData eventData) { base.OnPointerUp(eventData); OnSliderUp?.Invoke(eventData); } public void UpdateSlider() { Vector2 tmp = Rect3D.rect.size; tmp.x = value * body.rect.size.x; Rect3D.sizeDelta = tmp; } } public class SliderPointEvent : UnityEvent { } }