12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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<XRIcon3D>();
- if (obj)
- {
- rect3D = obj.GetComponent<RectTransform>();
- }
- }
- 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<RectTransform>();
- 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<PointerEventData>
- {
- }
- }
|