using System.Collections; using System.Collections.Generic; using UnityEngine; public interface IItemBase { void InitInfo(T info); } /// /// /// /// 数据源 /// 格子类 public class CustomSV where K : IItemBase { private RectTransform content; private int viewHeight; private Dictionary currItemDic = new Dictionary(); private List itemList; private int preMinIndex = -1; private int preMaxIndex = -1; private float itemW; private float itemH; private int col; public CustomSV(RectTransform content,int h,List itemList,float itemW,float itemH) { this.content = content; this.viewHeight = h; this.itemList = itemList; this.itemW = itemW; this.itemH = itemH; } private void InitContentHeigth() { content.sizeDelta = new Vector2(col * itemW, Mathf.CeilToInt(itemList.Count / col) * itemH); } public void UpdateConten() { int minIndex = (int)(content.anchoredPosition3D.y / itemH) * col; int maxIndex = (int)((content.anchoredPosition3D.y + viewHeight) / itemH) * col + (col - 1); } private int IndexLimit(int index) { return Mathf.Clamp(index, 0, itemList.Count - 1); } }