123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541 |
-
- 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<GameObject> taskList = new List<GameObject>();
- 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<FunctionValue> _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<PlaySounds>().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<PlaySounds>().soundName = "sound0";
- leftButton_show.gameObject.SetActive(false);
- rightButton_show.gameObject.SetActive(false);
- // 克隆一份数据
- _currFVList = new List<FunctionValue>();
- Debug.Log(999);
- _currFVList.AddRange(GongYe.FunctionValues);
- StartInitialize();
- Debug.Log(101010);
- StartCoroutine(StartshowHand());
- }
- /// <summary>
- /// 初始化项目
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 根据传入的步骤ID显示当前步骤
- /// </summary>
- /// <param name="taskIndex">步骤ID</param>
- public void ShowHandleClick(int taskIndex)
- {
- SetEngineeringFunctionInfo(taskIndex);
- SelectInspectResultButton();
- }
- /// <summary>
- /// 状态
- /// </summary>
- /// <param name="index"></param>
- /// <param name="newValue"></param>
- 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;
- }
- }
- /// <summary>
- /// 刷新状态
- /// </summary>
- /// <param name="changeIndex"></param>
- /// <param name="prevValue"></param>
- /// <param name="currValue"></param>
- private void RefreshState(int changeIndex, int prevValue, int currValue)
- {
- Debug.LogWarning($"当前改变的index {changeIndex} 从{prevValue} 改变为{currValue}");
- taskList[changeIndex].GetComponent<InspectList_Button>().startInspect = (StartInspect)_currFVList[changeIndex].value;
- taskList[changeIndex].GetComponent<InspectList_Button>().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<InspectList_Button>().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();//结算面板
- }
- }
- }
- /// <summary>
- /// 对应的步骤面板被选中
- /// </summary>
- private void SelectInspectResultButton()
- {
- isBegain = false;
- foreach (var item in _currFVList)
- {
- taskList[item.index].GetComponent<InspectList_Button>().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<InspectList_Button>().mainSubtasks;
- tagText_Two.text = taskList[item.index].GetComponent<InspectList_Button>().text_name.text;
- text_Content.text = taskList[item.index].GetComponent<InspectList_Button>().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);
- }
- }
- /// <summary>
- /// 当点击中间页面的上一步、下一步按钮
- /// </summary>
- /// <param name="butoonName"></param>
- public void ButtonUserClick(string butoonName)
- {
- isBegain = false;
- switch (butoonName)
- {
- case "LeftButton":
- leftB();
- break;
- case "RightButton":
- RightB();
- break;
- }
- }
- /// <summary>
- /// 上一步
- /// </summary>
- private void leftB()
- {
- if (taskIndex > 0)
- {
- taskIndex -= 1;
- SetEngineeringFunctionInfo(taskIndex);
- SelectInspectResultButton();
- }
- else
- {
- taskIndex = 0;
- leftButton_show.gameObject.SetActive(false);
- isMakeSound = false;
- }
- }
- /// <summary>
- /// 下一步
- /// </summary>
- 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<InspectList_Button>().viewTag == 1)//判断是否属于扫描二维码的 列表条
- {
- Debug.Log(taskList[i]);
- if (message == taskList[i].GetComponent<InspectList_Button>().code || taskList[i].GetComponent<InspectList_Button>().code == "8SSA10E75875D1SG93L02F6")
- {
- saoMa = 1;
- //通过
- }
- else
- {
- //不合格
- if (scansOfNum >= 2)
- {
- saoMa = 2;
- TestingNoPass_SaoMa();
- return;
- }
- else if (scansOfNum == 1)
- {
- MakeSound("sound_SaoMiao_NoPass");
- }
- }
- }
- }
- }
- }
- /// <summary>
- /// 2021.2.23 手动检测成功或失败
- /// </summary>
- /// <param name="message"></param>
- public void Testring_UserClickNoOrPass(string message)
- {
- isBegain = false;
- int currIndex = message == "检测成功" ? 2 : 3;
- SetEngineeringFunctionInfo(taskIndex, currIndex);
- RefreshState(taskIndex, -1, currIndex);
- }
- /// <summary>
- /// 检测不合格
- /// </summary>
- public void TestingNoPass_SaoMa()
- {
- for (int i = 0; i < taskList.Count; i++)
- {
- if (taskIndex == i)
- {
- taskList[i].GetComponent<InspectList_Button>().status = 3;//
- taskList[i].GetComponent<InspectList_Button>().jiluStaatus = 3;//
- }
- if (taskIndex + 1 == taskList.Count)
- {
- MakeLastSound();
- }
- }
- // ButtonUserClick("RightButton");
- scansOfNum = 0;
- saoMa = 0;
- }
- /// <summary>
- ///检测合格
- /// </summary>
- public void TestingPass_YuYin()
- {
- //for (int i = 0; i < taskList.Count; i++)
- //{
- // if (taskIndex == i)
- // {
- // if (taskList[i].GetComponent<InspectList_Button>().viewTag == 2)//语音
- // {
- // taskList[i].GetComponent<InspectList_Button>().status = 2;//
- // taskList[i].GetComponent<InspectList_Button>().jiluStaatus = 2;//
- // }
- // else
- // {
- // return;
- // }
- // }
- // if (taskIndex + 1 == taskList.Count)
- // {
- // MakeLastSound();
- // }
- //}
- //ButtonUserClick("RightButton");
- //yuYin = 0;
- }
- /// <summary>
- /// 检测不合格
- /// </summary>
- public void TestingNoPass_YuYin()
- {
- // for (int i = 0; i < taskList.Count; i++)
- // {
- // if (taskIndex == i)
- // {
- // if (taskList[i].GetComponent<InspectList_Button>().viewTag == 2)//语音
- // {
- // taskList[i].GetComponent<InspectList_Button>().status = 3;//
- // taskList[i].GetComponent<InspectList_Button>().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<PlaySounds>().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<PlaySounds>().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<PlaySounds>().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<InspectList_Button>().startInspect = StartInspect.Undetected;
- taskList[i].GetComponent<InspectList_Button>().SetBtnState();
- }
- //左右按钮不可见
- leftButton_show.gameObject.SetActive(false);
- rightButton_show.gameObject.SetActive(false);
- //回到外箱检测页面
- inspectList.UserClick("buttonTag1");
- m_IsFirstActiveTrue = false;
- }
- }
|