zhanghaomanager.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using LitJson;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class zhanghaomanager : MonoBehaviour
  8. {
  9. public Toggle t1;
  10. public Toggle t2;
  11. public Toggle t3;
  12. public UIScrollScript uiScroll;
  13. public GameObject go;
  14. List<GameObject> list = new List<GameObject>();
  15. bool startinit=false;
  16. void OnEnable()
  17. {
  18. }
  19. private void Start() {
  20. uiScroll.Init();
  21. RemoveAll();
  22. startinit=false;
  23. StartCoroutine(getreplist());
  24. uiScroll.onUpdateItem -= ContentUpdateItem;
  25. uiScroll.onUpdateItem += ContentUpdateItem;
  26. }
  27. int choose =-1;
  28. private void Awake() {
  29. list.Add(go);
  30. t1.onValueChanged.AddListener((b)=>{
  31. if(b)
  32. {
  33. choose=-1;
  34. RemoveAll();
  35. startinit=false;
  36. StartCoroutine(getreplist());
  37. }
  38. });
  39. t2.onValueChanged.AddListener((b)=>{
  40. if(b)
  41. {
  42. choose=1;
  43. RemoveAll();
  44. startinit=false;
  45. StartCoroutine(getreplist());
  46. }
  47. });
  48. t3.onValueChanged.AddListener((b)=>{
  49. if(b)
  50. {
  51. choose=0;
  52. RemoveAll();
  53. startinit=false;
  54. StartCoroutine(getreplist());
  55. }
  56. });
  57. }
  58. private void ContentUpdateItem(GameObject item, int wrapIndex, int realIndex)
  59. {
  60. if (realIndex >= 0&&datamsg.Count>realIndex)
  61. {
  62. UserInfoItem xitem = item.GetComponent<UserInfoItem>();
  63. xitem.init(datamsg[realIndex]);
  64. item.SetActive(true);
  65. }
  66. else
  67. {
  68. item.SetActive(false);
  69. }
  70. }
  71. List<JsonData> datamsg =new List<JsonData>();
  72. int MaxLiebiao=11;
  73. public void RemoveAll()
  74. {
  75. datamsg=new List<JsonData>();
  76. }
  77. public void sousuo()
  78. {
  79. RemoveAll();
  80. startinit=false;
  81. StartCoroutine(getreplist());
  82. }
  83. public Text searchstr;
  84. public IEnumerator getreplist()
  85. {
  86. Debug.Log("getreplist start");
  87. yield return StartCoroutine(DataManager.Instance.GetUserList((msg)=>{
  88. JsonData jd =JsonMapper.ToObject(msg);
  89. for (int i = list.Count; i < MaxLiebiao; i++)
  90. {
  91. GameObject n =GameObject.Instantiate(go,go.transform.parent);
  92. list.Add(n);
  93. }
  94. if(jd["data"]["list"].ToString()!="[]")
  95. {
  96. for (int i = 0; i < MaxLiebiao; i++)
  97. {
  98. if(jd["data"]["list"].ToString()!="[]"&&jd["data"]["list"].Count> i)
  99. {
  100. if(jd["data"]["list"][i]["name"].ToString().Contains(searchstr.text)||jd["data"]["list"][i]["account"].ToString().Contains(searchstr.text))
  101. {
  102. if(choose==-1||choose.ToString()==jd["data"]["list"][i]["admin"].ToString())
  103. {
  104. list[i].GetComponent<UserInfoItem>().init(jd["data"]["list"][i]);
  105. //list[i].SetActive(true);
  106. datamsg.Add(jd["data"]["list"][i]);
  107. }
  108. else
  109. {
  110. list[i].SetActive(false);
  111. }
  112. }
  113. else
  114. {
  115. list[i].SetActive(false);
  116. }
  117. }
  118. else
  119. {
  120. list[i].SetActive(false);
  121. }
  122. }
  123. for (int i = datamsg.Count;i<jd["data"]["list"].Count;i++)
  124. {
  125. if(jd["data"]["list"][i]["name"].ToString().Contains(searchstr.text)||jd["data"]["list"][i]["account"].ToString().Contains(searchstr.text))
  126. {
  127. if(choose==-1||choose.ToString()==jd["data"]["list"][i]["admin"].ToString())
  128. {
  129. if(i<list.Count)
  130. {
  131. list[i].GetComponent<UserInfoItem>().init(jd["data"]["list"][i]);
  132. // list[i].SetActive(true);
  133. }
  134. if(i>=MaxLiebiao)
  135. datamsg.Add(jd["data"]["list"][i]);
  136. }
  137. }
  138. }
  139. }
  140. else
  141. {
  142. for (int i = 0; i < list.Count; i++)
  143. {
  144. list[i].SetActive(false);
  145. }
  146. }
  147. if(datamsg.Count!=0)
  148. {
  149. Debug.Log("datamsg===>"+datamsg.Count);
  150. uiScroll.InitList(0, datamsg.Count);
  151. }
  152. else
  153. {
  154. for (int i = 0; i < list.Count; i++)
  155. {
  156. list[i].SetActive(false);
  157. }
  158. }
  159. startinit=true;
  160. }));
  161. }
  162. }