using CCS.App; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; public class InspectListPanel : MonoBehaviour { public GongYeContral GongYe; // Use this for initialization public static int taskIndex = 0; public List taskList = new List(); public GameObject leftButton, rightButton; public GameObject leftButton_show, rightButton_show; public TextMesh tagText;//标题 public TextMesh tagText_Two;//副标题 public TextMesh text_Content;//内容 public ReadXMLWaiXiang readWX;//外箱检测的xml; public ReadXMLFuJian readFJ; public ReadXMLPeiZhi readPZ; public InspectList inspectList; public GameObject[] show_Photo_Video_Model; public GameObject soundsParent; public GameObject soundsParent1; public GameObject soundsAudioSource; private bool isMakeSound = true; public GameObject text_saomiao; public GameObject text_yuyin; private bool isInitUpdate;//用来限制循环 public GameObject baseViewPanel;//列表面板 public GameObject contentPanel1; //内容面板1 public GameObject contentPanel2;//内容面板2 public GameObject settlementPanel;//结算面板 private int scansOfNum = 0;//扫码次数 public int saoMa; //1 pass 2 no pass public int yuYin;//1 pass 2 no pass private List _currFVList; //所有步骤 private bool isBegain = true;//控制第一条待检测。 private bool m_IsFirstActiveTrue = true; private void Awake() { } private void OnEnable() { if (!m_IsFirstActiveTrue) { PlaySounds(-2); soundsAudioSource = Resources.Load("PlaySounds") as GameObject; GameObject sounds = Instantiate(soundsAudioSource, soundsParent.transform.position, Quaternion.identity); sounds.transform.parent = soundsParent.transform; sounds.name = "playSounds0"; sounds.GetComponent().soundName = "sound0"; show_Photo_Video_Model[taskIndex].SetActive(false); //将当前选中的步骤面板播放内容隐藏 isBegain = true; StartInitialize(); StartCoroutine(StartshowHand()); } } void Start() { PlaySounds(-2); soundsAudioSource = Resources.Load("PlaySounds") as GameObject; GameObject sounds = Instantiate(soundsAudioSource, soundsParent.transform.position, Quaternion.identity); sounds.transform.parent = soundsParent.transform; sounds.name = "playSounds0"; sounds.GetComponent().soundName = "sound0"; leftButton_show.gameObject.SetActive(false); rightButton_show.gameObject.SetActive(false); // 克隆一份数据 _currFVList = new List(); Debug.Log(999); _currFVList.AddRange(GongYe.FunctionValues); StartInitialize(); Debug.Log(101010); StartCoroutine(StartshowHand()); } /// /// 初始化项目 /// private void StartInitialize() { taskIndex = 0; for (int i = 0, count = _currFVList.Count; i < count; i++) { _currFVList[i].value = 0; } _currFVList[0].isShow = true; } IEnumerator StartshowHand() { yield return new WaitForSeconds(12.2f); if (isBegain == true) { ShowHandleClick(taskIndex); } } /// /// 根据传入的步骤ID显示当前步骤 /// /// 步骤ID public void ShowHandleClick(int taskIndex) { SetEngineeringFunctionInfo(taskIndex); SelectInspectResultButton(); } /// /// 状态 /// /// /// private void SetEngineeringFunctionInfo(int index, int newValue) { _currFVList[index].value = newValue; } // 是否选中(待检测状态) private void SetEngineeringFunctionInfo(int index) { isBegain = false; foreach (var item in _currFVList) { item.isShow = item.index == index ? true : false; _currFVList[item.index].isShow = item.isShow; } } /// /// 刷新状态 /// /// /// /// private void RefreshState(int changeIndex, int prevValue, int currValue) { Debug.LogWarning($"当前改变的index {changeIndex} 从{prevValue} 改变为{currValue}"); taskList[changeIndex].GetComponent().startInspect = (StartInspect)_currFVList[changeIndex].value; taskList[changeIndex].GetComponent().SetBtnState(); if (currValue == 2 || currValue == 3) { int nextIndex = Mathf.Clamp(changeIndex + 1, 0, taskList.Count - 1); Debug.Log("nextIndex:" + nextIndex); if (nextIndex > changeIndex) { switch (taskList[nextIndex].GetComponent().startInspect) { case StartInspect.Undetected: case StartInspect.qualified: case StartInspect.Unqualified: //选中状态 if (nextIndex == 0) { inspectList.UserClick("buttonTag1"); } else if (nextIndex == 5) { inspectList.UserClick("buttonTag2"); } else if (nextIndex == 12) { inspectList.UserClick("buttonTag3"); } else { SetEngineeringFunctionInfo(nextIndex); SelectInspectResultButton(); } break; default: break; } } else { MakeLastSound();//结算面板 } } } /// /// 对应的步骤面板被选中 /// private void SelectInspectResultButton() { isBegain = false; foreach (var item in _currFVList) { taskList[item.index].GetComponent().OnSelect(item.isShow); show_Photo_Video_Model[item.index].SetActive(item.isShow); if (item.isShow) { taskIndex = item.index; PlaySounds(taskIndex); tagText.text = taskList[item.index].GetComponent().mainSubtasks; tagText_Two.text = taskList[item.index].GetComponent().text_name.text; text_Content.text = taskList[item.index].GetComponent().content; } } } // Update is called once per frame void Update() { if (taskIndex > 0) { leftButton.SetActive(true); } else { leftButton.SetActive(false); leftButton_show.SetActive(false); } if (taskIndex < taskList.Count - 1) { rightButton.SetActive(true); } else { rightButton.SetActive(false); rightButton_show.SetActive(false); } } /// /// 当点击中间页面的上一步、下一步按钮 /// /// public void ButtonUserClick(string butoonName) { isBegain = false; switch (butoonName) { case "LeftButton": leftB(); break; case "RightButton": RightB(); break; } } /// /// 上一步 /// private void leftB() { if (taskIndex > 0) { taskIndex -= 1; SetEngineeringFunctionInfo(taskIndex); SelectInspectResultButton(); } else { taskIndex = 0; leftButton_show.gameObject.SetActive(false); isMakeSound = false; } } /// /// 下一步 /// private void RightB() { if (taskIndex < taskList.Count) { taskIndex += 1; SetEngineeringFunctionInfo(taskIndex); SelectInspectResultButton(); } else { taskIndex = taskList.Count; rightButton_show.gameObject.SetActive(false); isMakeSound = false; } } void OnDestroy() { } public void Testing_Pass_or_NoPass(String message) { scansOfNum += 1; for (int i = 0; i < taskList.Count; i++) { if (taskIndex == i) { if (taskList[i].GetComponent().viewTag == 1)//判断是否属于扫描二维码的 列表条 { Debug.Log(taskList[i]); if (message == taskList[i].GetComponent().code || taskList[i].GetComponent().code == "8SSA10E75875D1SG93L02F6") { saoMa = 1; //通过 } else { //不合格 if (scansOfNum >= 2) { saoMa = 2; TestingNoPass_SaoMa(); return; } else if (scansOfNum == 1) { MakeSound("sound_SaoMiao_NoPass"); } } } } } } /// /// 2021.2.23 手动检测成功或失败 /// /// public void Testring_UserClickNoOrPass(string message) { isBegain = false; int currIndex = message == "检测成功" ? 2 : 3; SetEngineeringFunctionInfo(taskIndex, currIndex); RefreshState(taskIndex, -1, currIndex); } /// /// 检测不合格 /// public void TestingNoPass_SaoMa() { for (int i = 0; i < taskList.Count; i++) { if (taskIndex == i) { taskList[i].GetComponent().status = 3;// taskList[i].GetComponent().jiluStaatus = 3;// } if (taskIndex + 1 == taskList.Count) { MakeLastSound(); } } // ButtonUserClick("RightButton"); scansOfNum = 0; saoMa = 0; } /// ///检测合格 /// public void TestingPass_YuYin() { //for (int i = 0; i < taskList.Count; i++) //{ // if (taskIndex == i) // { // if (taskList[i].GetComponent().viewTag == 2)//语音 // { // taskList[i].GetComponent().status = 2;// // taskList[i].GetComponent().jiluStaatus = 2;// // } // else // { // return; // } // } // if (taskIndex + 1 == taskList.Count) // { // MakeLastSound(); // } //} //ButtonUserClick("RightButton"); //yuYin = 0; } /// /// 检测不合格 /// public void TestingNoPass_YuYin() { // for (int i = 0; i < taskList.Count; i++) // { // if (taskIndex == i) // { // if (taskList[i].GetComponent().viewTag == 2)//语音 // { // taskList[i].GetComponent().status = 3;// // taskList[i].GetComponent().jiluStaatus = 3;// // } // else // { // return; // } // } // if (taskIndex + 1 == taskList.Count) // { // MakeLastSound(); // } // } // ButtonUserClick("RightButton"); // yuYin = 0; } private void YanChiMakeSound() { GameObject sounds = Instantiate(soundsAudioSource, soundsParent.transform.position, Quaternion.identity); sounds.transform.parent = soundsParent.transform; sounds.name = "playSounds" + taskIndex + 1; sounds.GetComponent().soundName = "sound" + taskIndex + 1; isMakeSound = false; } private void MakeLastSound() { PlaySounds(-1); if (soundsParent1.transform.Find("playSoundsOver") == null) { GameObject sounds = Instantiate(soundsAudioSource, soundsParent1.transform.position, Quaternion.identity); sounds.transform.parent = soundsParent1.transform; sounds.name = "playSoundsOver"; sounds.GetComponent().soundName = "soundOver"; } baseViewPanel.SetActive(false);//列表面板 contentPanel1.SetActive(false); //内容面板1 contentPanel2.SetActive(false);//内容面板2 settlementPanel.SetActive(true);//结算面板 } private void MakeSound(string soundName) { for (int j = 0; j < soundsParent.transform.childCount; j++) { Destroy(soundsParent.transform.GetChild(j).gameObject); } if (soundsParent1.transform.Find(soundName) == null) { GameObject sounds = Instantiate(soundsAudioSource, soundsParent.transform.position, Quaternion.identity); sounds.transform.parent = soundsParent.transform; sounds.name = soundName; sounds.GetComponent().soundName = soundName; } } private void PlaySounds(int Soundindex) { string soundNames = ""; switch (Soundindex) { case -2: soundNames = "GY_OBE_SoundStart"; break; case 0: soundNames = "GY_OBE_Sound1"; break; case 1: soundNames = "GY_OBE_Sound2"; break; case 2: soundNames = "GY_OBE_Sound3"; break; case 3: soundNames = "GY_OBE_Sound4"; break; case 4: soundNames = "GY_OBE_Sound5"; break; case -1: soundNames = "GY_OBE_SoundEnd"; break; } AudioManager.Instance.AudioGongYe_OBE_LanguageSounds(soundNames); } private void OnDisable() { //关闭结算面板,显示内容面板 baseViewPanel.SetActive(true);//列表面板 contentPanel1.SetActive(true); //内容面板1 contentPanel2.SetActive(true);//内容面板2 settlementPanel.SetActive(false);//结算面板 //使所有步骤回归未检测状态 for (int i = 0; i < _currFVList.Count; i++) { taskList[i].GetComponent().startInspect = StartInspect.Undetected; taskList[i].GetComponent().SetBtnState(); } //左右按钮不可见 leftButton_show.gameObject.SetActive(false); rightButton_show.gameObject.SetActive(false); //回到外箱检测页面 inspectList.UserClick("buttonTag1"); m_IsFirstActiveTrue = false; } }