InspectListPanel.cs 16 KB

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