XunJianInitialize.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using LitJson;
  2. using Newtonsoft.Json;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.Events;
  7. using static LangChaoJiekou;
  8. public class XunJianInitialize :MonoSingleton<XunJianInitialize>
  9. {
  10. public XJTaskItem tastItem;
  11. public GameObject contentUI;
  12. public XunJianDetails xjDetails;
  13. public GameObject retractBtn;
  14. public GameObject expandBtn;
  15. public GameObject defaultUI;
  16. public GameObject endUI;
  17. public GameObject homeEndUI;
  18. public XJTaskItem checkTaskItem;
  19. private bool isScale;
  20. private bool isInit;
  21. private List<XJTaskItem> listItem;
  22. public UnityEvent OnReset = new UnityEvent(); // ÖØÖÃʼþ
  23. private void Start()
  24. {
  25. isInit = false;
  26. listItem = new List<XJTaskItem>();
  27. isScale = false;
  28. }
  29. private void OnEnable()
  30. {
  31. defaultUI.SetActive(false);
  32. endUI.SetActive(false);
  33. homeEndUI.SetActive(false);
  34. // Éϱ¨Ñ²¼ì¿ªÊ¼
  35. JsonData data = new JsonData();
  36. data["id"] = XunJianAllData.taskItem.distributeId;
  37. StartCoroutine(LangChaoJiekou.Instance.SendHttp(LangChaoJiekou.execute, data.ToJson(), (msg) =>
  38. {
  39. Debug.Log("DGJ ==> /record/execute " + msg);
  40. }, "application/json",false));
  41. }
  42. private void Update()
  43. {
  44. if(!isInit && XunJianAllData.listRoomItem!=null)
  45. {
  46. isInit = true;
  47. InitializeData();
  48. }
  49. #if UNITY_EDITOR
  50. //if (Test) return;
  51. return;
  52. #endif
  53. OnReset?.Invoke();
  54. }
  55. public void InitializeData( )
  56. {
  57. for (int i = 0; i < XunJianAllData.listRoomItem.Count; i++)
  58. {
  59. GameObject item = GameObject.Instantiate(tastItem.gameObject, tastItem.transform.parent);
  60. item.SetActive(true);
  61. item.GetComponent<XJTaskItem>().InitData(i+1, XunJianAllData.listRoomItem[i] ,xjDetails);
  62. listItem.Add(item.GetComponent<XJTaskItem>());
  63. }
  64. if (listItem!=null&&listItem.Count > 0)
  65. {
  66. SetCheckIte(listItem[0]);
  67. }
  68. }
  69. public void GoHome()
  70. {
  71. xjDetails.SubmitData();
  72. homeEndUI.SetActive(true);
  73. }
  74. public void Complete()
  75. {
  76. for (int i = 0; i < listItem.Count; i++)
  77. {
  78. if(listItem[i].itemData.recd==null)
  79. {
  80. defaultUI.SetActive(true);
  81. return;
  82. }
  83. }
  84. endUI.SetActive(true);
  85. }
  86. public void LastItem()
  87. {
  88. for (int i = 0; i < listItem.Count; i++)
  89. {
  90. if(checkTaskItem.itemData.inspItemId == listItem[i].itemData.inspItemId)
  91. {
  92. int num = i - 1;
  93. if (num>=0)
  94. {
  95. SetCheckIte(listItem[num]);
  96. }
  97. else
  98. {
  99. SetCheckIte(listItem[i]);
  100. }
  101. break;
  102. }
  103. }
  104. }
  105. public void NextItem()
  106. {
  107. for (int i = 0; i < listItem.Count; i++)
  108. {
  109. if (checkTaskItem.itemData.inspItemId == listItem[i].itemData.inspItemId)
  110. {
  111. int num = i + 1;
  112. if (num < listItem.Count)
  113. {
  114. SetCheckIte(listItem[num]);
  115. }
  116. else
  117. {
  118. SetCheckIte(listItem[i]);
  119. }
  120. break;
  121. }
  122. }
  123. }
  124. public int GetCheckItemNum()
  125. {
  126. if (checkTaskItem == null)
  127. return -1;
  128. for (int i = 0; i < listItem.Count; i++)
  129. {
  130. if (checkTaskItem.itemData.inspItemId == listItem[i].itemData.inspItemId)
  131. {
  132. return i+1;
  133. }
  134. }
  135. return -2;
  136. }
  137. public void SetCheckIte(XJTaskItem item)
  138. {
  139. if (checkTaskItem != null)
  140. {
  141. checkTaskItem.numText.color = Color.white;
  142. if(checkTaskItem.itemData.recd==null)
  143. {
  144. checkTaskItem.imageBG.SetActive(false);
  145. }
  146. }
  147. checkTaskItem = item;
  148. xjDetails.InitData(item.itemData);
  149. checkTaskItem.numText.color = Color.yellow;
  150. checkTaskItem.imageBG.SetActive(true);
  151. }
  152. public void SetScaleFunction()
  153. {
  154. contentUI.SetActive(isScale);
  155. xjDetails.gameObject.SetActive(isScale);
  156. retractBtn.SetActive(isScale);
  157. isScale = !isScale;
  158. expandBtn.SetActive(isScale);
  159. }
  160. public void back()
  161. {
  162. ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowChoose);
  163. }
  164. }