123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class NormalList : BaseList
- {
- public float rowSpacing;
- public float columnSpacing;
- public GameObject bLeft;
- public GameObject bRight;
- public TextMesh tPage;
- private int nPage=0;
- public void clickLeft()
- {
- nPage--;
- if (nPage < 0)
- {
- nPage = 0;
- }
- else
- {
- setPage(nPage);
- }
- }
- public void clickRight()
- {
- nPage++;
- if (nPage > getMaxPage())
- {
- nPage = getMaxPage();
- }
- else
- {
- setPage(nPage);
- }
- }
- public void setPage(int index)
- {
- nPage = index;
- int vIndex=0;
- for (int i=0;i<Views.Count ;i++)
- {
- if(configs.Count>(i+index*(Views.Count)))
- {
- Views[i].init((i + index * (Views.Count)),configs[(i + index * (Views.Count ))], vIndex);
- Views[i].gameObject.SetActive(true);
- vIndex++;
- }
- else
- {
- Views[i].gameObject.SetActive(false);
- }
- }
- if(tPage!=null)
- {
- tPage.text = (nPage+1) + "/" + (getMaxPage()+1);
- }
- }
- public override void initList(List<BaseConfig> c)
- {
- base.initList(c);
- for (int i = 0; i < Views.Count; i++)
- {
- Views[i].transform.localPosition = new Vector3(((i) % Row) * rowSpacing, -((i) / Row) * columnSpacing, 0);
- }
- setPage(0);
- if (bLeft != null)
- {
- bLeft.AddComponent<Button>().onClick.AddListener(clickLeft);
- }
- if (bRight != null)
- {
- bRight.AddComponent<Button>().onClick.AddListener(clickRight);
- }
- }
- public int getMaxPage()
- {
- return ((configs.Count - 1) / (Views.Count));
- }
- public override void updateConfig(List<BaseConfig> c)
- {
- if (this.configs.Count < c.Count)
- {
- configs = new List<BaseConfig>();
- c.ForEach(i => configs.Add(i));
- setPage(getMaxPage());
- }
- else if(nPage>= getMaxPage())
- {
- configs = new List<BaseConfig>();
- c.ForEach(i => configs.Add(i));
- setPage(getMaxPage());
- }
- else
- {
- configs = new List<BaseConfig>();
- c.ForEach(i => configs.Add(i));
- }
- }
- }
|