InspectListPanel.cs 17 KB

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