InspectListPanel.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. 
  2. using CCS.App;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using UnityEngine;
  8. public class InspectListPanel : MonoBehaviour
  9. {
  10. public GongYeContral GongYe;
  11. // Use this for initialization
  12. public static int taskIndex = 0;
  13. public List<GameObject> taskList = new List<GameObject>();
  14. public GameObject leftButton, rightButton;
  15. public GameObject leftButton_show, rightButton_show;
  16. public TextMesh tagText;//标题
  17. public TextMesh tagText_Two;//副标题
  18. public TextMesh text_Content;//内容
  19. public ReadXMLWaiXiang readWX;//外箱检测的xml;
  20. public ReadXMLFuJian readFJ;
  21. public ReadXMLPeiZhi readPZ;
  22. public InspectList inspectList;
  23. public GameObject[] show_Photo_Video_Model;
  24. public GameObject soundsParent;
  25. public GameObject soundsParent1;
  26. public GameObject soundsAudioSource;
  27. private bool isMakeSound = true;
  28. public GameObject text_saomiao;
  29. public GameObject text_yuyin;
  30. private bool isInitUpdate;//用来限制循环
  31. public GameObject baseViewPanel;//列表面板
  32. public GameObject contentPanel1; //内容面板1
  33. public GameObject contentPanel2;//内容面板2
  34. public GameObject settlementPanel;//结算面板
  35. private int scansOfNum = 0;//扫码次数
  36. public int saoMa; //1 pass 2 no pass
  37. public int yuYin;//1 pass 2 no pass
  38. private List<FunctionValue> _currFVList; //所有步骤
  39. private bool isBegain = true;//控制第一条待检测。
  40. private bool m_IsFirstActiveTrue = true;
  41. private void Awake()
  42. {
  43. }
  44. private void OnEnable()
  45. {
  46. if (!m_IsFirstActiveTrue)
  47. {
  48. PlaySounds(-2);
  49. soundsAudioSource = Resources.Load("PlaySounds") as GameObject;
  50. GameObject sounds = Instantiate(soundsAudioSource, soundsParent.transform.position, Quaternion.identity);
  51. sounds.transform.parent = soundsParent.transform;
  52. sounds.name = "playSounds0";
  53. sounds.GetComponent<PlaySounds>().soundName = "sound0";
  54. show_Photo_Video_Model[taskIndex].SetActive(false); //将当前选中的步骤面板播放内容隐藏
  55. isBegain = true;
  56. StartInitialize();
  57. StartCoroutine(StartshowHand());
  58. }
  59. }
  60. void Start()
  61. {
  62. PlaySounds(-2);
  63. soundsAudioSource = Resources.Load("PlaySounds") as GameObject;
  64. GameObject sounds = Instantiate(soundsAudioSource, soundsParent.transform.position, Quaternion.identity);
  65. sounds.transform.parent = soundsParent.transform;
  66. sounds.name = "playSounds0";
  67. sounds.GetComponent<PlaySounds>().soundName = "sound0";
  68. leftButton_show.gameObject.SetActive(false);
  69. rightButton_show.gameObject.SetActive(false);
  70. // 克隆一份数据
  71. _currFVList = new List<FunctionValue>();
  72. Debug.Log(999);
  73. _currFVList.AddRange(GongYe.FunctionValues);
  74. StartInitialize();
  75. Debug.Log(101010);
  76. StartCoroutine(StartshowHand());
  77. }
  78. /// <summary>
  79. /// 初始化项目
  80. /// </summary>
  81. private void StartInitialize()
  82. {
  83. taskIndex = 0;
  84. for (int i = 0, count = _currFVList.Count; i < count; i++)
  85. {
  86. _currFVList[i].value = 0;
  87. }
  88. _currFVList[0].isShow = true;
  89. }
  90. IEnumerator StartshowHand()
  91. {
  92. yield return new WaitForSeconds(12.2f);
  93. if (isBegain == true)
  94. {
  95. ShowHandleClick(taskIndex);
  96. }
  97. }
  98. /// <summary>
  99. /// 根据传入的步骤ID显示当前步骤
  100. /// </summary>
  101. /// <param name="taskIndex">步骤ID</param>
  102. public void ShowHandleClick(int taskIndex)
  103. {
  104. SetEngineeringFunctionInfo(taskIndex);
  105. SelectInspectResultButton();
  106. }
  107. /// <summary>
  108. /// 状态
  109. /// </summary>
  110. /// <param name="index"></param>
  111. /// <param name="newValue"></param>
  112. private void SetEngineeringFunctionInfo(int index, int newValue)
  113. {
  114. _currFVList[index].value = newValue;
  115. }
  116. // 是否选中(待检测状态)
  117. private void SetEngineeringFunctionInfo(int index)
  118. {
  119. isBegain = false;
  120. foreach (var item in _currFVList)
  121. {
  122. item.isShow = item.index == index ? true : false;
  123. _currFVList[item.index].isShow = item.isShow;
  124. }
  125. }
  126. /// <summary>
  127. /// 刷新状态
  128. /// </summary>
  129. /// <param name="changeIndex"></param>
  130. /// <param name="prevValue"></param>
  131. /// <param name="currValue"></param>
  132. private void RefreshState(int changeIndex, int prevValue, int currValue)
  133. {
  134. Debug.LogWarning($"当前改变的index {changeIndex} 从{prevValue} 改变为{currValue}");
  135. taskList[changeIndex].GetComponent<InspectList_Button>().startInspect = (StartInspect)_currFVList[changeIndex].value;
  136. taskList[changeIndex].GetComponent<InspectList_Button>().SetBtnState();
  137. if (currValue == 2 || currValue == 3)
  138. {
  139. int nextIndex = Mathf.Clamp(changeIndex + 1, 0, taskList.Count - 1);
  140. Debug.Log("nextIndex:" + nextIndex);
  141. if (nextIndex > changeIndex)
  142. {
  143. switch (taskList[nextIndex].GetComponent<InspectList_Button>().startInspect)
  144. {
  145. case StartInspect.Undetected:
  146. case StartInspect.qualified:
  147. case StartInspect.Unqualified:
  148. //选中状态
  149. if (nextIndex == 0)
  150. {
  151. inspectList.UserClick("buttonTag1");
  152. }
  153. else if (nextIndex == 5)
  154. {
  155. inspectList.UserClick("buttonTag2");
  156. }
  157. else if (nextIndex == 12)
  158. {
  159. inspectList.UserClick("buttonTag3");
  160. }
  161. else
  162. {
  163. SetEngineeringFunctionInfo(nextIndex);
  164. SelectInspectResultButton();
  165. }
  166. break;
  167. default:
  168. break;
  169. }
  170. }
  171. else
  172. {
  173. MakeLastSound();//结算面板
  174. }
  175. }
  176. }
  177. /// <summary>
  178. /// 对应的步骤面板被选中
  179. /// </summary>
  180. private void SelectInspectResultButton()
  181. {
  182. isBegain = false;
  183. foreach (var item in _currFVList)
  184. {
  185. taskList[item.index].GetComponent<InspectList_Button>().OnSelect(item.isShow);
  186. show_Photo_Video_Model[item.index].SetActive(item.isShow);
  187. if (item.isShow)
  188. {
  189. taskIndex = item.index;
  190. PlaySounds(taskIndex);
  191. tagText.text = taskList[item.index].GetComponent<InspectList_Button>().mainSubtasks;
  192. tagText_Two.text = taskList[item.index].GetComponent<InspectList_Button>().text_name.text;
  193. text_Content.text = taskList[item.index].GetComponent<InspectList_Button>().content;
  194. }
  195. }
  196. }
  197. // Update is called once per frame
  198. void Update()
  199. {
  200. if (taskIndex > 0)
  201. {
  202. leftButton.SetActive(true);
  203. }
  204. else
  205. {
  206. leftButton.SetActive(false);
  207. leftButton_show.SetActive(false);
  208. }
  209. if (taskIndex < taskList.Count - 1)
  210. {
  211. rightButton.SetActive(true);
  212. }
  213. else
  214. {
  215. rightButton.SetActive(false);
  216. rightButton_show.SetActive(false);
  217. }
  218. }
  219. /// <summary>
  220. /// 当点击中间页面的上一步、下一步按钮
  221. /// </summary>
  222. /// <param name="butoonName"></param>
  223. public void ButtonUserClick(string butoonName)
  224. {
  225. isBegain = false;
  226. switch (butoonName)
  227. {
  228. case "LeftButton":
  229. leftB();
  230. break;
  231. case "RightButton":
  232. RightB();
  233. break;
  234. }
  235. }
  236. /// <summary>
  237. /// 上一步
  238. /// </summary>
  239. private void leftB()
  240. {
  241. if (taskIndex > 0)
  242. {
  243. taskIndex -= 1;
  244. SetEngineeringFunctionInfo(taskIndex);
  245. SelectInspectResultButton();
  246. }
  247. else
  248. {
  249. taskIndex = 0;
  250. leftButton_show.gameObject.SetActive(false);
  251. isMakeSound = false;
  252. }
  253. }
  254. /// <summary>
  255. /// 下一步
  256. /// </summary>
  257. private void RightB()
  258. {
  259. if (taskIndex < taskList.Count)
  260. {
  261. taskIndex += 1;
  262. SetEngineeringFunctionInfo(taskIndex);
  263. SelectInspectResultButton();
  264. }
  265. else
  266. {
  267. taskIndex = taskList.Count;
  268. rightButton_show.gameObject.SetActive(false);
  269. isMakeSound = false;
  270. }
  271. }
  272. void OnDestroy()
  273. {
  274. }
  275. public void Testing_Pass_or_NoPass(String message)
  276. {
  277. scansOfNum += 1;
  278. for (int i = 0; i < taskList.Count; i++)
  279. {
  280. if (taskIndex == i)
  281. {
  282. if (taskList[i].GetComponent<InspectList_Button>().viewTag == 1)//判断是否属于扫描二维码的 列表条
  283. {
  284. Debug.Log(taskList[i]);
  285. if (message == taskList[i].GetComponent<InspectList_Button>().code || taskList[i].GetComponent<InspectList_Button>().code == "8SSA10E75875D1SG93L02F6")
  286. {
  287. saoMa = 1;
  288. //通过
  289. }
  290. else
  291. {
  292. //不合格
  293. if (scansOfNum >= 2)
  294. {
  295. saoMa = 2;
  296. TestingNoPass_SaoMa();
  297. return;
  298. }
  299. else if (scansOfNum == 1)
  300. {
  301. MakeSound("sound_SaoMiao_NoPass");
  302. }
  303. }
  304. }
  305. }
  306. }
  307. }
  308. /// <summary>
  309. /// 2021.2.23 手动检测成功或失败
  310. /// </summary>
  311. /// <param name="message"></param>
  312. public void Testring_UserClickNoOrPass(string message)
  313. {
  314. isBegain = false;
  315. int currIndex = message == "检测成功" ? 2 : 3;
  316. SetEngineeringFunctionInfo(taskIndex, currIndex);
  317. RefreshState(taskIndex, -1, currIndex);
  318. }
  319. /// <summary>
  320. /// 检测不合格
  321. /// </summary>
  322. public void TestingNoPass_SaoMa()
  323. {
  324. for (int i = 0; i < taskList.Count; i++)
  325. {
  326. if (taskIndex == i)
  327. {
  328. taskList[i].GetComponent<InspectList_Button>().status = 3;//
  329. taskList[i].GetComponent<InspectList_Button>().jiluStaatus = 3;//
  330. }
  331. if (taskIndex + 1 == taskList.Count)
  332. {
  333. MakeLastSound();
  334. }
  335. }
  336. // ButtonUserClick("RightButton");
  337. scansOfNum = 0;
  338. saoMa = 0;
  339. }
  340. /// <summary>
  341. ///检测合格
  342. /// </summary>
  343. public void TestingPass_YuYin()
  344. {
  345. //for (int i = 0; i < taskList.Count; i++)
  346. //{
  347. // if (taskIndex == i)
  348. // {
  349. // if (taskList[i].GetComponent<InspectList_Button>().viewTag == 2)//语音
  350. // {
  351. // taskList[i].GetComponent<InspectList_Button>().status = 2;//
  352. // taskList[i].GetComponent<InspectList_Button>().jiluStaatus = 2;//
  353. // }
  354. // else
  355. // {
  356. // return;
  357. // }
  358. // }
  359. // if (taskIndex + 1 == taskList.Count)
  360. // {
  361. // MakeLastSound();
  362. // }
  363. //}
  364. //ButtonUserClick("RightButton");
  365. //yuYin = 0;
  366. }
  367. /// <summary>
  368. /// 检测不合格
  369. /// </summary>
  370. public void TestingNoPass_YuYin()
  371. {
  372. // for (int i = 0; i < taskList.Count; i++)
  373. // {
  374. // if (taskIndex == i)
  375. // {
  376. // if (taskList[i].GetComponent<InspectList_Button>().viewTag == 2)//语音
  377. // {
  378. // taskList[i].GetComponent<InspectList_Button>().status = 3;//
  379. // taskList[i].GetComponent<InspectList_Button>().jiluStaatus = 3;//
  380. // }
  381. // else
  382. // {
  383. // return;
  384. // }
  385. // }
  386. // if (taskIndex + 1 == taskList.Count)
  387. // {
  388. // MakeLastSound();
  389. // }
  390. // }
  391. // ButtonUserClick("RightButton");
  392. // yuYin = 0;
  393. }
  394. private void YanChiMakeSound()
  395. {
  396. GameObject sounds = Instantiate(soundsAudioSource, soundsParent.transform.position, Quaternion.identity);
  397. sounds.transform.parent = soundsParent.transform;
  398. sounds.name = "playSounds" + taskIndex + 1;
  399. sounds.GetComponent<PlaySounds>().soundName = "sound" + taskIndex + 1;
  400. isMakeSound = false;
  401. }
  402. private void MakeLastSound()
  403. {
  404. PlaySounds(-1);
  405. if (soundsParent1.transform.Find("playSoundsOver") == null)
  406. {
  407. GameObject sounds = Instantiate(soundsAudioSource, soundsParent1.transform.position, Quaternion.identity);
  408. sounds.transform.parent = soundsParent1.transform;
  409. sounds.name = "playSoundsOver";
  410. sounds.GetComponent<PlaySounds>().soundName = "soundOver";
  411. }
  412. baseViewPanel.SetActive(false);//列表面板
  413. contentPanel1.SetActive(false); //内容面板1
  414. contentPanel2.SetActive(false);//内容面板2
  415. settlementPanel.SetActive(true);//结算面板
  416. }
  417. private void MakeSound(string soundName)
  418. {
  419. for (int j = 0; j < soundsParent.transform.childCount; j++)
  420. {
  421. Destroy(soundsParent.transform.GetChild(j).gameObject);
  422. }
  423. if (soundsParent1.transform.Find(soundName) == null)
  424. {
  425. GameObject sounds = Instantiate(soundsAudioSource, soundsParent.transform.position, Quaternion.identity);
  426. sounds.transform.parent = soundsParent.transform;
  427. sounds.name = soundName;
  428. sounds.GetComponent<PlaySounds>().soundName = soundName;
  429. }
  430. }
  431. private void PlaySounds(int Soundindex)
  432. {
  433. string soundNames = "";
  434. switch (Soundindex)
  435. {
  436. case -2:
  437. soundNames = "GY_OBE_SoundStart";
  438. break;
  439. case 0:
  440. soundNames = "GY_OBE_Sound1";
  441. break;
  442. case 1:
  443. soundNames = "GY_OBE_Sound2";
  444. break;
  445. case 2:
  446. soundNames = "GY_OBE_Sound3";
  447. break;
  448. case 3:
  449. soundNames = "GY_OBE_Sound4";
  450. break;
  451. case 4:
  452. soundNames = "GY_OBE_Sound5";
  453. break;
  454. case -1:
  455. soundNames = "GY_OBE_SoundEnd";
  456. break;
  457. }
  458. AudioManager.Instance.AudioGongYe_OBE_LanguageSounds(soundNames);
  459. }
  460. private void OnDisable()
  461. {
  462. //关闭结算面板,显示内容面板
  463. baseViewPanel.SetActive(true);//列表面板
  464. contentPanel1.SetActive(true); //内容面板1
  465. contentPanel2.SetActive(true);//内容面板2
  466. settlementPanel.SetActive(false);//结算面板
  467. //使所有步骤回归未检测状态
  468. for (int i = 0; i < _currFVList.Count; i++)
  469. {
  470. taskList[i].GetComponent<InspectList_Button>().startInspect = StartInspect.Undetected;
  471. taskList[i].GetComponent<InspectList_Button>().SetBtnState();
  472. }
  473. //左右按钮不可见
  474. leftButton_show.gameObject.SetActive(false);
  475. rightButton_show.gameObject.SetActive(false);
  476. //回到外箱检测页面
  477. inspectList.UserClick("buttonTag1");
  478. m_IsFirstActiveTrue = false;
  479. }
  480. }