游戏引擎 c# Unity ugui 学习记录(一) ScrollView实现分页滚动功能 - ListenerAutoScroll()

📅 2026-11-30 👤 拼多多助力营销技巧 📂 拼多多助力2027 👁️ 392 次阅读

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

一、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 &#

推荐阅读

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧