游戏引擎 c# Unity ugui 学习记录(一) ScrollView实现分页滚动功能 - ListenerAutoScroll()
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
一、ScrollView实现分页滚动功能
二、ScrollView实现分页滚动缩放功能
一、ScrollView实现分页滚动功能
代码如下:
using System;
using System.Collections;
using System.Collections.Generic; 拼多多帮助力入口
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public enum PageScrollType {
Horizontal,
Vertical
}
public class PageScrollView : MonoBehaviour, IBeginDragHandler, IEndDragHandler
{
protected ScrollRect rect;
protected int pageCount;
private RectTransform content;
protected float[] pages;
public float moveTime = 0.3f;
private float timer = 0;
private float startMovePos;
protected int currentPage = 0;
private bool isDraging = false;
private bool isMoving = false;
// 是不是开启自动滚动
public bool IsAutoScroll;
public float AutoScrollTime = 2;
private float AutoScrollTimer = 0;
public PageScrollType pageScrollType = PageScrollType.Horizontal;
public float vertical;
public ActionOnPageChange;
protected virtual void Start()
{
Init();
}
protected virtual void Update()
{
ListenerMove();
ListenerAutoScroll();
vertical = rect.verticalNormalizedPosition;
}
public void OnEndDrag(PointerEventData eventData)
{
// 滚动到离得最近的一页
this.ScrollToPage(CaculateMinDistancePage());
isDraging &#
推荐阅读