| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public interface IItemBase<T>
- {
- void InitInfo(T info);
- }
- /// <summary>
- ///
- /// </summary>
- /// <typeparam name="T">数据源</typeparam>
- /// <typeparam name="K">格子类</typeparam>
- public class CustomSV<T, K> where K : IItemBase<T>
- {
- private RectTransform content;
- private int viewHeight;
- private Dictionary<int, GameObject> currItemDic = new Dictionary<int, GameObject>();
- private List<T> 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<T> 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);
- }
- }
|