예제 #1
0
    //#if CHAPTER_ONE

    //    /// <summary>
    //    /// 考试试题列表
    //    /// </summary>
    //    private List<string> examList = new List<string>();
    //    /// <summary>
    //    /// 随机练习列表
    //    /// </summary>
    //    private List<string> exerList = new List<string>();


    //    /// <summary>
    //    /// 开始随机练习
    //    /// </summary>
    //    private void StartExercise()
    //    {
    //        CleanQuestion();
    //        CloseAllLight();
    //        string index = RandomExerIndex();
    //        cQuestionData question = ConfigDataMgr.Instance.GetQuestionByIndex(index);
    //        StartCoroutine(BeginQuestion(question, false));
    //    }

    //    /// <summary>
    //    /// 开始灯光考试
    //    /// </summary>
    //    private void StartLightExam()
    //    {
    //        CleanQuestion();
    //        CloseAllLight();
    //        //生成试题列表
    //        RandomExamList();
    //        StartCoroutine(_BeginLightExam());
    //    }

    //    private void RandomExamList()
    //    {
    //        ExamData examData = ConfigDataMgr.Instance.gameConfig.examList[GameDataMgr.Instance.carType.ToString().ToUpper()];
    //        int count = examData.exam.Count;
    //        if (examList != null)
    //        {
    //            int index = examData.exam.IndexOf(examList);
    //            index++;
    //            index %= examData.exam.Count;
    //            examList = examData.exam[index];
    //        }
    //        else
    //        {
    //            examList = examData.exam[Random.Range(0, examData.exam.Count)];
    //        }
    //    }

    //    private string RandomExerIndex()
    //    {
    //        ExamData examData = ConfigDataMgr.Instance.gameConfig.examList[GameDataMgr.Instance.carType.ToString().ToUpper()];
    //        int count = examData.random.Count;
    //        exerList = new List<string>();
    //        for (int i = 0; i < count; i++)
    //        {
    //            exerList.Add(examData.random[i]);
    //        }
    //        int random = Random.Range(0, count / 2);
    //        string index = exerList[random];
    //        exerList.Remove(index);
    //        exerList.Add(index);
    //        return index;
    //    }


    //    IEnumerator _BeginLightExam()
    //    {
    //        textQuestion.text = examTip.exam_tip;
    //        textAnswer.text = "";
    //        audioObject = AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.GetAudioWithURL(examTip.exam_audio));
    //        Debug.Log(audioObject.playTime);
    //        yield return new WaitForSeconds(audioObject.playTime);
    //        audioObject = null;
    //        yield return new WaitForSeconds(3f);
    //        for (int i = 0; i < examList.Count; i++)
    //        {
    //            cQuestionData question = ConfigDataMgr.Instance.GetQuestionByIndex(examList[i]);
    //            yield return StartCoroutine(BeginQuestion(question, true, i != 0));
    //        }
    //        //yield return StartCoroutine(BeginQuestion(ConfigDataMgr.ExamEnd, true));
    //        textAnswer.text = "恭喜你全部操作成功!!!";
    //        imgResult.gameObject.SetActive(true);
    //        imgResult.sprite = sprRight;
    //        AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.LoadAudioClip("right"));
    //    }

    //    /// <summary>
    //    /// Begins the question.
    //    /// </summary>
    //    /// <returns>The question.</returns>
    //    /// <param name="question">Question.</param>
    //    IEnumerator BeginQuestion(cQuestionData question, bool isExam, bool ding = true)
    //    {
    //        textQuestion.text = question.question;
    //        textAnswer.text = question.answer;
    //        textAnswer.gameObject.SetActive(false || IsShowAnswer);
    //        audioObject = AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.GetAudioWithURL(question.audio));
    //        Debug.Log(audioObject.playTime);
    //        yield return new WaitForSeconds(audioObject.playTime);
    //        audioObject = null;

    //        if (ding && !string.IsNullOrEmpty(examTip.broadcast_end))
    //        {
    //            AudioObject audioBroadcast = AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.GetAudioWithURL(examTip.broadcast_end));
    //            yield return new WaitForSeconds(audioBroadcast.playTime);
    //        }

    //        LowToHigCount = 0;//防止抢先操作
    //        yield return new WaitForSeconds(4f);//操作时间

    //        bool result = true;
    //        result &= (question.DoubleJumpLamp == DoubleJumpLamp);
    //        result &= (question.ClearAnceLamp == ClearanceLamp);
    //        result &= (question.LowBeamLight == LowBeamLight);
    //        result &= (question.HigBeamLight == HigBeamLight);
    //        result &= (question.FrontFogLamp == FrontFogLamp);
    //        result &= (question.RearFogLamp == RearFogLamp);
    //        result &= (question.LeftIndicator == LeftIndicator);
    //        result &= (question.RightIndicator == RightIndicator);
    //        result &= (question.LowToHigLight == (LowToHigCount >= 2));

    //        result &= !(!question.LowToHigLight && lowToHigCount > 0);
    //        textAnswer.gameObject.SetActive(true);

    //        imgResult.gameObject.SetActive(true);
    //        imgResult.sprite = result ? sprRight : sprError;
    //        if (result)
    //        {
    //            if (!isExam)
    //            {
    //                imgResult.gameObject.SetActive(true);
    //                imgResult.sprite = result ? sprRight : sprError;
    //                AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.LoadAudioClip("right"));
    //            }
    //            yield return new WaitForSeconds(3.0f);
    //            imgResult.gameObject.SetActive(false);
    //        }
    //        else
    //        {
    //            imgResult.gameObject.SetActive(true);
    //            imgResult.sprite = result ? sprRight : sprError;
    //            AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.LoadAudioClip("error"));
    //            PauseQuestion();
    //        }
    //    }

    //#elif CHAPTER_TWO
    /// <summary>
    /// 开始随机练习
    /// </summary>
    void StartExercise()
    {
        CleanQuestion();
        CloseAllLight();
        sQuestionData question = RandomExerIndex();

        StartCoroutine(BeginExercise(question));
    }
예제 #2
0
    /// <summary>
    /// server试题--资源下载
    /// </summary>
    /// <param name="carInfo">Car info.</param>
    /// <param name="callback">Callback.</param>
    public void DownLoadAudioResource(ResponseCarInfo carInfo, Callback <bool, float> callback)
    {
        downloadCallback = callback;
        downloadList     = new List <string>();
        downloadIndex    = 0;

        //检查开始灯光考试的语音需要更新
        TypeModel model = carInfo.TypeModel;

        //for (int i = 0; i < carInfo.listnewold.Count; i++)
        //{
        //    if (int.Parse(carInfo.listnewold[i].type) == GameDataMgr.Instance.carTypeData.type)
        //    {
        //        model = carInfo.listnewold[i];
        //        break;
        //    }
        //}
        if (model != null)
        {
            if (!ConfigDataMgr.Instance.resourceDict.ContainsKey(model.examaudio))
            {
                downloadList.Add(model.examaudio);
            }
            if (!string.IsNullOrEmpty(model.broadcastend.Trim()) && !ConfigDataMgr.Instance.resourceDict.ContainsKey(model.broadcastend))
            {
                downloadList.Add(model.broadcastend);
            }
        }
        else
        {
            Debug.LogError("version配置不正确");
        }

        //检查试题的语音是否需要更新
        for (int i = 0; i < carInfo.questions.Count; i++)
        {
            sQuestionData question = carInfo.questions[i];
            if (!ConfigDataMgr.Instance.resourceDict.ContainsKey(question.audio))
            {
                //downloadList.Add(question.audio.Replace("http:", "https:"));
                downloadList.Add(question.audio);
            }
        }

        if (downloadList.Count <= 0)
        {
            downloadCallback(true, 1f);
        }
        else
        {
            DownLoadFile();
        }
    }
예제 #3
0
    /// <summary>
    /// Begins the question.
    /// </summary>
    /// <returns>The question.</returns>
    /// <param name="question">Question.</param>
    IEnumerator BeginExercise(sQuestionData question)
    {
        #region MyRegion
        textQuestion.text = question.question;
        textAnswer.text   = question.answer;
        textAnswer.gameObject.SetActive(IsShowAnswer);
        audioObject = AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.GetAudioWithURL(question.audio));
        Debug.Log(audioObject.playTime);
        yield return(new WaitForSeconds(audioObject.playTime));

        audioObject = null;

        if (/*ding && */ !string.IsNullOrEmpty(examTip.broadcast_end))
        {
            AudioObject audioBroadcast = AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.GetAudioWithURL(examTip.broadcast_end));
            yield return(new WaitForSeconds(audioBroadcast.playTime));
        }
        LowToHigCount = 0;                    //防止抢先操作
        yield return(new WaitForSeconds(4f)); //操作时间

        bool result = GetQuestionResult(question);

        textAnswer.gameObject.SetActive(true);

        imgResult.gameObject.SetActive(true);
        imgResult.sprite = result ? sprRight : sprError;

        if (result)
        {
            imgResult.gameObject.SetActive(true);
            imgResult.sprite = result ? sprRight : sprError;
            AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.LoadAudioClip("right"));

            yield return(new WaitForSeconds(3.0f));

            imgResult.gameObject.SetActive(false);
        }
        else
        {
            imgResult.gameObject.SetActive(true);
            imgResult.sprite = result ? sprRight : sprError;
            AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.LoadAudioClip("error"));
            PauseQuestion();
        }
        #endregion
    }
예제 #4
0
    /// <summary>
    /// 获取答题结果是否
    /// </summary>
    /// <returns><c>true</c>, if question result was gotten, <c>false</c> otherwise.</returns>
    /// <param name="question">Question.</param>
    private bool GetQuestionResult(sQuestionData question)
    {
        bool result = true;

        result &= ((question.DoubleJumpLamp == 1) == DoubleJumpLamp);
        result &= ((question.ClearAnceLamp == 1) == ClearanceLamp);
        result &= ((question.LowBeamLight == 1) == LowBeamLight);
        result &= ((question.HigBeamLight == 1) == HigBeamLight);
        result &= ((question.FrontFogLamp == 1) == FrontFogLamp);
        result &= ((question.RearFogLamp == 1) == RearFogLamp);
        result &= ((question.LeftIndicator == 1) == LeftIndicator);
        result &= ((question.RightIndicator == 1) == RightIndicator);
        result &= (question.LowToHigLight <= lowToHigCount);

        Debug.Log("DoubleJumpLamp:" + DoubleJumpLamp + "\nClearanceLamp:" + ClearanceLamp + "\nLowBeamLight:" + LowBeamLight + "\nHigBeamLight:" + HigBeamLight + "\nFrontFogLamp:" + FrontFogLamp + "\nRearFogLamp:" + RearFogLamp + "\nlowToHigCount:" + lowToHigCount);

        Debug.Log("DoubleJumpLamp:" + question.DoubleJumpLamp + "\nClearanceLamp:" + question.ClearAnceLamp + "\nLowBeamLight:" + question.LowBeamLight + "\nHigBeamLight:" + question.HigBeamLight + "\nFrontFogLamp:" + question.FrontFogLamp + "\nRearFogLamp:" + question.RearFogLamp + "\nlowToHigCount:" + question.LowToHigLight);

        return(result);
    }
예제 #5
0
    IEnumerator BeginLightExam(List <int> examList)
    {
        bool isPass = true;      //是否通过考试
        //bool isBreak = false;   //是否中断考试
        int   totalScore = 100;  //考试总成绩
        float totalTime  = 5f;   //考试总时长

        //试题开始的提示信息
        textQuestion.text = examTip.exam_tip;
        textAnswer.text   = "";
        audioObject       = AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.GetAudioWithURL(examTip.exam_audio));
        Debug.Log(audioObject.playTime);
        yield return(new WaitForSeconds(audioObject.playTime));

        audioObject = null;
        yield return(new WaitForSeconds(0.5f));

        for (int i = 0; i < examList.Count; i++)
        {
            sQuestionData question = GameDataMgr.Instance.carInfo.GetQuestionWithId(examList[i]);

            #region MyRegion
            textQuestion.text = question.question;
            textAnswer.text   = question.answer;
            textAnswer.gameObject.SetActive(IsShowAnswer);
            imgResult.gameObject.SetActive(false);
            audioObject = AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.GetAudioWithURL(question.audio));
            Debug.Log(audioObject.playTime);
            float playTime = Mathf.Clamp(audioObject.playTime - 0.2f, 0.2f, audioObject.playTime);
            LowToHigCount = 0;//防止抢先操作
            yield return(new WaitForSeconds(playTime));

            audioObject = null;
            Debug.LogWarning("开始答题:" + question.question);
            if (!string.IsNullOrEmpty(examTip.broadcast_end) &&
                i != 0 &&                      //第一道题不提示ding
                i != (examList.Count - 1))     //最后一道题不提示ding
            {
                Debug.LogWarning("Ding ^^^^^^^^^^^^ ");
                AudioObject audioBroadcast = AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.GetAudioWithURL(examTip.broadcast_end));
                yield return(new WaitForSeconds(audioBroadcast.playTime));
            }

            bool  result = GetQuestionResult(question);
            float delay;
            if (result)     //默认灯光是正确的
            {
                Debug.LogWarning("答案默认正确");
                delay       = totalTime;
                isOperation = false;
                while (delay > 0f)
                {
                    yield return(null);

                    delay -= Time.deltaTime;
                    if (isOperation)  //如果正确时进行其他操作变错误
                    {
                        Debug.LogWarning("等待时间中进行了操作");
                        result = false;
                        break;
                    }
                }
            }
            else            //默认灯光是不正确
            {
                Debug.LogWarning("答案默认错误");
                delay = totalTime;
                do
                {
                    yield return(null);

                    delay -= Time.deltaTime;
                    if (isOperation)
                    {
                        isOperation = false;
                        result      = GetQuestionResult(question);
                    }
                } while (delay > 0 && !result);

                if (result)     //等待剩余时间
                {
                    Debug.LogWarning("答题时间:" + delay);
                    isOperation = false;
                    delay       = Mathf.Clamp(delay, 0f, (i + 1) == examList.Count ? 0.5f : 1f);
                    while (delay > 0f)
                    {
                        yield return(null);

                        delay -= Time.deltaTime;
                        if (isOperation)  //如果正确时进行其他操作变错误
                        {
                            Debug.LogWarning("等待时间中进行了操作");
                            result = false;
                            break;
                        }
                    }
                }
            }

            textAnswer.gameObject.SetActive(true);
            imgResult.gameObject.SetActive(true);
            imgResult.sprite = result ? sprRight : sprError;
            if (result)
            {
                Debug.LogWarning("答题----正确");
                yield return(new WaitForSeconds(2.0f));

                imgResult.gameObject.SetActive(false);
            }
            else
            {
                Debug.LogWarning("答题----错误");
                AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.LoadAudioClip("error"));
                yield return(new WaitForSeconds(2.0f));

                totalScore -= question.score;
            }

            //未通过考试,进行首次提示
            if (isPass && totalScore < 90)
            {
                Debug.LogWarning("未通过考试---提示");
                isPass = false;
                bool waiting = true;
                bool choice  = false;
                UIPrompDialog.ShowPromp(UIPrompDialog.PrompType.CancelAndConfirm, "", "考试不合格,是否继续考试?",
                                        (confirm) =>
                {
                    choice  = confirm;
                    waiting = false;
                }, "继续考试", "放弃考试");

                while (waiting)
                {
                    yield return(null);
                }

                if (!choice)    //选择放弃考试
                {
                    Debug.LogWarning("放弃考试");
                    IsLightExam = false;
                    IsChioce    = false;
                    yield break;
                }
            }
            #endregion
        }

        textQuestion.text = "";
        if (isPass)                //通过考试
        {
            if (totalScore == 100) //满分通过
            {
                textAnswer.text = "<color=#00ff00>恭喜你满分通过考试!!!</color>";
                imgResult.gameObject.SetActive(true);
                imgResult.sprite = sprRight;
                AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.LoadAudioClip("right"));
            }
            else
            {
                textAnswer.text = "<color=#00ff00>恭喜你通过考试!!!</color>";
                imgResult.gameObject.SetActive(true);
                imgResult.sprite = sprRight;
                AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.LoadAudioClip("right"));
            }
        }
        else            //未通过考试
        {
            textAnswer.text = "<color=#ff0000>考试未通过</color>";
            imgResult.gameObject.SetActive(true);
            imgResult.sprite = sprError;
            AudioSystemMgr.Instance.PlaySoundByClip(ResourcesMgr.Instance.LoadAudioClip("error"));
            PauseQuestion();
        }
    }