新建一个ScrollView,在Content上挂几个子节点,挂上PageView脚本即可
注:PageView会自动对Content下的节点进行大小整理,每一个子节点都会和Viewport窗口大小一致
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class PageView : MonoBehaviour, IBeginDragHandler, IEndDragHandler
{
[SerializeField]
private bool _interactable = true;
public bool interactable
{
get { return _interactable; }
set
{
_interactable = value;
if (m_ScrollRect != null) m_ScrollRect.horizontal = interactable;
}
}
[Tooltip("页面移动速率")]
public float smooting = 5f;
[Tooltip("划过多少就算成功")]
[Range(0.1f, 1f)]
public float limit = 0.3f;
public bool autoPlay = false;
public float autoPlaySeconds = 5f;
//本游戏对象上的ScrollRect组件
priv