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;
	}
}
