using System.Collections; using System.Collections.Generic; using System.Linq; using LitJson; using UnityEngine; using UnityEngine.UI; public class zhanghaomanager : MonoBehaviour { public Toggle t1; public Toggle t2; public Toggle t3; public UIScrollScript uiScroll; public GameObject go; List list = new List(); bool startinit=false; void OnEnable() { } private void Start() { uiScroll.Init(); RemoveAll(); startinit=false; StartCoroutine(getreplist()); uiScroll.onUpdateItem -= ContentUpdateItem; uiScroll.onUpdateItem += ContentUpdateItem; } int choose =-1; private void Awake() { list.Add(go); t1.onValueChanged.AddListener((b)=>{ if(b) { choose=-1; RemoveAll(); startinit=false; StartCoroutine(getreplist()); } }); t2.onValueChanged.AddListener((b)=>{ if(b) { choose=1; RemoveAll(); startinit=false; StartCoroutine(getreplist()); } }); t3.onValueChanged.AddListener((b)=>{ if(b) { choose=0; RemoveAll(); startinit=false; StartCoroutine(getreplist()); } }); } private void ContentUpdateItem(GameObject item, int wrapIndex, int realIndex) { if (realIndex >= 0&&datamsg.Count>realIndex) { UserInfoItem xitem = item.GetComponent(); xitem.init(datamsg[realIndex]); item.SetActive(true); } else { item.SetActive(false); } } List datamsg =new List(); int MaxLiebiao=11; public void RemoveAll() { datamsg=new List(); } public void sousuo() { RemoveAll(); startinit=false; StartCoroutine(getreplist()); } public Text searchstr; public IEnumerator getreplist() { Debug.Log("getreplist start"); yield return StartCoroutine(DataManager.Instance.GetUserList((msg)=>{ JsonData jd =JsonMapper.ToObject(msg); for (int i = list.Count; i < MaxLiebiao; i++) { GameObject n =GameObject.Instantiate(go,go.transform.parent); list.Add(n); } if(jd["data"]["list"].ToString()!="[]") { for (int i = 0; i < MaxLiebiao; i++) { if(jd["data"]["list"].ToString()!="[]"&&jd["data"]["list"].Count> i) { if(jd["data"]["list"][i]["name"].ToString().Contains(searchstr.text)||jd["data"]["list"][i]["account"].ToString().Contains(searchstr.text)) { if(choose==-1||choose.ToString()==jd["data"]["list"][i]["admin"].ToString()) { list[i].GetComponent().init(jd["data"]["list"][i]); //list[i].SetActive(true); datamsg.Add(jd["data"]["list"][i]); } else { list[i].SetActive(false); } } else { list[i].SetActive(false); } } else { list[i].SetActive(false); } } for (int i = datamsg.Count;i().init(jd["data"]["list"][i]); // list[i].SetActive(true); } if(i>=MaxLiebiao) datamsg.Add(jd["data"]["list"][i]); } } } } else { for (int i = 0; i < list.Count; i++) { list[i].SetActive(false); } } if(datamsg.Count!=0) { Debug.Log("datamsg===>"+datamsg.Count); uiScroll.InitList(0, datamsg.Count); } else { for (int i = 0; i < list.Count; i++) { list[i].SetActive(false); } } startinit=true; })); } }