using UnityEngine.UI;
using UnityEngine.EventSystems;
public class scroll : MonoBehaviour, IBeginDragHandler, IEndDragHandler
{
private ScrollRect a;
private float[] window = { 0, 0.33f, 0.67f, 1.01f, 1.32f };//最终的4个页面的,最终x坐标
private float solider = 0;//将本脚本用的数据都写成private模式(这里用solider存储具体的页码,用于lerp计算)
void Awake()
{
a = this.gameObject.GetComponent<ScrollRect>();
}
public void OnBeginDrag(PointerEventData eventData)//当拖曳开始
{
}
public void OnEndDrag(PointerEventData eventData)//当拖曳结束
{
float thistime = a.horizontalNormalizedPosition;//水平方向上的标准化坐标即x坐标,实时x坐标
int ye = 0;//页码
float maintime = Mathf.Abs(thistime - window[ye]);//左边长
for (int i = 0; i < window.Length; ++i)
{
float timetemp = Mathf.Abs(thistime - window[i]);//右边长
if (maintime > timetemp)//左边>右边(如果左边不再大于右边