using System.Collections; using System.Collections.Generic; using UnityEngine; public class BaseList : MonoBehaviour { [HideInInspector] public int rCount = 0; [HideInInspector] public List configs = new List(); [HideInInspector] public List Views = new List(); [HideInInspector] private int maxCount; [HideInInspector] public int maxRowItemCount = 0; [HideInInspector] public int maxColumItemCount = 0; public int Row; public int Column; // Start is called before the first frame update void Start() { } public virtual void initList(List c) { if (Views.Count<=0) { maxCount = Row * Column; Views = new List(); BaseView view = this.GetComponentInChildren(); // Debug.Log("viewviewviewview"); view.gameObject.SetActive(false); Views.Add(view); BaseView cloneView; for (int i = 0; i < maxCount - 1; i++) { cloneView = Instantiate(view); cloneView.transform.parent = this.transform; cloneView.name = view.name + "_" + (i + 1); cloneView.transform.localScale = view.transform.localScale; cloneView.transform.localRotation = view.transform.localRotation; Views.Add(cloneView); } } configs = new List(); c.ForEach(i => configs.Add(i)); int vindex=0; for (int i = 0; i < Views.Count; i++) { if(i< configs.Count) { Views[i].init(i, configs[i], vindex); Views[i].baselist = this; Views[i].gameObject.SetActive(true); vindex++; //Debug.Log(i); //if (i == 1) //{ // AgoraVideoAudioManager.Instance.ShowOneView(RoomMain.Instance.agoraRawImage); //} } else { Views[i].gameObject.SetActive(false); } } maxRowItemCount = (this.configs.Count - 1) / Row + 1; maxColumItemCount = (this.configs.Count - 1) / Column + 1; // rCount = maxItemCount; } public void showItems(int start,int end,bool isShow=false) { int vindex = 0; for (int i = 0; i < Views.Count; i++) { Views[i].sx = i; if ((i + start) < configs.Count&&i<= (end - start)&& (i + start)>=0) { if (Views[i].Index!= (i + start)) { Views[i].init((i + start),configs[(i + start)], vindex); Views[i].baselist = this; } if (Views[i].isShow|| isShow) { Views[i].gameObject.SetActive(true); vindex++; } } else { Views[i].gameObject.SetActive(false); } } } public void showItems(List items) { int vindex = 0; for (int i = 0; i < items.Count; i++) { if(items[i]>=0) { if(configs.Count>items[i]) { if (Views[i].Index != items[i]) { Views[i].init(items[i], configs[items[i]], vindex); Views[i].baselist = this; } Views[i].gameObject.SetActive(true); vindex++; } else { Views[i].gameObject.SetActive(false); } } else { Views[i].gameObject.SetActive(false); } } } public virtual void updateConfig(List configs) { // this.configs = configs; initList(configs); } }