using Assets.Scenes.Ride.Scripts.Model; using Assets.Scripts; using System; using System.Linq; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace Assets.Scenes.Ride.Scripts { public class BaseListFactory : MonoBehaviour { protected AbstractPlayer playerController; protected CyclingController cyclingController; protected GameObject nearByItem; protected GameObject nearByMajorItem; protected GameObject scroll; protected Transform parent { get; set; } private GameObject body; protected int totalPages = 0; protected int bufferSize = 0; protected int pageIndex = 1; protected int pageSize = 5; private int preNum = 0;//前面的数量 private int offset = 8;//显示区域的数量 protected bool startMouse = false; protected float t = 1f; protected virtual void Awake() { scroll = transform.parent.parent.gameObject; parent = transform; if (scroll != null) { UIManager.AddEvent(scroll, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag); } } private void Update() { if (Input.GetAxis("Mouse ScrollWheel") != 0) { if (scroll.GetComponent().verticalNormalizedPosition <= 0 || scroll.GetComponent().verticalNormalizedPosition >= (pageIndex == 0 ? 1.2 : 1)) { startMouse = true; } } else { if (startMouse) { startMouse = false; OnEndDrag(null); } } t -= Time.deltaTime; while (t < 0) { //Utils.DestroyChildren(parent); CreateList(); t += 1f; } } protected virtual void CreateList() { } protected virtual void OnEndDrag(BaseEventData arg0) { var scrollrect = scroll.GetComponent(); if (scrollrect.verticalNormalizedPosition <= 0) { SetNextIndex(); } if (scrollrect.verticalNormalizedPosition >= (pageIndex == 0 ? 1.2 : 1)) { SetPreIndex(); } } protected void SetNextIndex() { var p = pageIndex + 1; if (p <= totalPages) { pageIndex++; } } protected void SetPreIndex() { var p = pageIndex - 1; if (p > 0) { pageIndex--; } } } }