123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using System;
- using UnityEngine.EventSystems;
- namespace UnityEngine.UI
- {
- [RequireComponent(typeof(RectTransform))]
- public class uGUISliderMoveButton : UIBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler, IEventSystemHandler
- {
- public Slider targetSlider
- {
- get
- {
- return this.m_TargetSlider;
- }
- set
- {
- this.m_TargetSlider = value;
- }
- }
- public float moveSpeed
- {
- get
- {
- return this.m_MoveSpeed;
- }
- set
- {
- this.m_MoveSpeed = value;
- }
- }
- private bool isUpdateSlider { get; set; }
- private bool isAccel { get; set; }
- private float speed { get; set; }
- public float decelerationRate
- {
- get
- {
- return this.m_DecelerationRate;
- }
- set
- {
- this.m_DecelerationRate = value;
- }
- }
- protected override void Start()
- {
- base.Start();
- }
- protected virtual void LateUpdate()
- {
- if (this.m_TargetSlider == null)
- {
- return;
- }
- if (this.isAccel)
- {
- this.speed += (this.moveSpeed - this.speed) * Time.unscaledDeltaTime * Time.unscaledDeltaTime;
- }
- this.speed *= Mathf.Pow(this.decelerationRate, Time.unscaledDeltaTime);
- if (Mathf.Abs(this.speed) <= 0.01f * Time.unscaledDeltaTime)
- {
- this.isUpdateSlider = false;
- return;
- }
- if (!this.isUpdateSlider)
- {
- return;
- }
- this.m_TargetSlider.value += this.speed;
- }
- public void OnPointerDown(PointerEventData eventData)
- {
- this.isUpdateSlider = true;
- this.isAccel = true;
- }
- public void OnPointerUp(PointerEventData eventData)
- {
- this.isAccel = false;
- }
- public void OnDrag(PointerEventData eventData)
- {
- }
- protected void OnReset()
- {
- if (this.targetSlider == null)
- {
- this.targetSlider = base.GetComponentInParent<Slider>();
- }
- }
- [SerializeField]
- private Slider m_TargetSlider;
- [SerializeField]
- private float m_MoveSpeed;
- [SerializeField]
- private float m_DecelerationRate = 0.1f;
- }
- }
|