123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- 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<GameObject> list = new List<GameObject>();
- 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<UserInfoItem>();
- xitem.init(datamsg[realIndex]);
- item.SetActive(true);
- }
- else
- {
- item.SetActive(false);
- }
- }
- List<JsonData> datamsg =new List<JsonData>();
- int MaxLiebiao=11;
- public void RemoveAll()
- {
- datamsg=new List<JsonData>();
- }
- 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<UserInfoItem>().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<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())
- {
- if(i<list.Count)
- {
- list[i].GetComponent<UserInfoItem>().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;
-
- }));
-
- }
- }
|