Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        m_GUITextures = this.gameObject.GetComponentsInChildren <GUITexture>();
        m_GUITexts    = this.gameObject.GetComponentsInChildren <GUIText>();
        if (true == m_FadeInValid)
        {
            // Debug.Log( "true == m_FadeInValid" ) ;
            foreach (GUITexture guiTexture in m_GUITextures)
            {
                guiTexture.color = new Color(guiTexture.color.r,
                                             guiTexture.color.g,
                                             guiTexture.color.b,
                                             0);
            }

            foreach (GUIText guiText in m_GUITexts)
            {
                guiText.material.color = new Color(guiText.material.color.r,
                                                   guiText.material.color.g,
                                                   guiText.material.color.b,
                                                   0);
            }

            ShowGUITexture.Show(this.gameObject, false, true, true);
        }

        m_State.state = (int)FadeState.UnActive;
    }
Beispiel #2
0
    private void CheckJudge2()
    {
        if (false == m_LevelGeneratorPtr.m_QuestionTable.ContainsKey(m_QuestionString))
        {
            return;
        }

        string minAnimKey            = "";
        QuestionTableStruct question = m_LevelGeneratorPtr.m_QuestionTable[m_QuestionString];
        int detectIndex = 0;

        Debug.Log("question.m_DetectionZones" + question.m_DetectionZones.Count);
        Dictionary <string, DetectionPose> .Enumerator iQuestion = question.m_DetectionZones.GetEnumerator();
        while (iQuestion.MoveNext())
        {
            if (detectIndex == m_AnswerIndex)
            {
                minAnimKey = iQuestion.Current.Key;
                Debug.Log("m_AnswerIndex=" + m_AnswerIndex);
                break;
            }
            ++detectIndex;
        }

        // Debug.Log( "minAnimKey" + minAnimKey ) ;
        if (0 != minAnimKey.Length)
        {
            m_ResultString = minAnimKey;
            Debug.Log("m_ResultString" + m_ResultString);
            m_AnimationPlayer.Setup(m_ResultString);
            if (-1 != m_ResultString.IndexOf("_f"))
            {
                // show false alarm
                ShowGUITexture.Show(m_GUIWrong, true, true, true);
                m_GUIAgain.gameObject.SendMessage("ClearIsDown");
                m_QuestionState = QuestionState.FalseAnimation;
            }
            else
            {
                ShowGUITexture.Show(m_GUICorrect, true, true, true);
                m_QuestionState = QuestionState.CorrectAnimation;
            }
        }
    }
Beispiel #3
0
    // Use this for initialization
    void Start()
    {
        if (null == m_GUIAnimationTexture)
        {
            GameObject obj = GameObject.Find(m_GUIAnimationObjectName);
            if (null == obj)
            {
                Debug.Log("AnimationPlayer::Start() null == obj");
            }
            m_GUIAnimationTexture         = obj.GetComponent <GUITexture>();
            m_GUIAnimationTexture.texture = null;
        }

        if (null == m_GUIQuestionZoneAnswer)
        {
            m_GUIQuestionZoneAnswer = GameObject.Find(m_GUIQuestionZoneAnswerName);
            if (null == m_GUIQuestionZoneAnswer)
            {
                Debug.Log("AnimationPlayer::Start() null == m_GUIQuestionZoneAnswer");
            }

            m_GUIQuestionZoneAnswer.GetComponent <GUITexture>().texture    = null;
            m_GUIQuestionZoneAnswer.GetComponent <GUITexture>().pixelInset = new Rect(0, (Camera.main.pixelHeight - Camera.main.pixelWidth * m_PictureScale) / 2, Camera.main.pixelWidth, Camera.main.pixelWidth * m_PictureScale);
            ShowGUITexture.Show(m_GUIQuestionZoneAnswer, false, true, true);
        }

        if (null == m_LevelGeneratorPtr)
        {
            GameObject obj = GameObject.Find("GlobalSingleton");
            m_LevelGeneratorPtr = obj.GetComponent <LevelGenerator>();
        }

        if (null == m_AnimationPlayer)
        {
            GameObject obj = GameObject.Find("GlobalSingleton");
            m_AnimationPlayer = obj.GetComponent <AnimationPlayer>();
        }

        if (null == m_GUIReady)
        {
            GameObject obj = GameObject.Find("GUI_Ready");
            m_GUIReady = obj.GetComponent <GUIText>();
        }

        if (null == m_GUIBack)
        {
            m_GUIBack = GameObject.Find(m_GUIBackName);
        }

        if (null == m_GUIInstruction)
        {
            m_GUIInstruction = GameObject.Find("GUI_Instruction");
        }

        if (null == m_GUICorrect)
        {
            m_GUICorrect = GameObject.Find("GUI_CorrectSymbol");
            ShowGUITexture.Show(m_GUICorrect, false, true, true);
        }

        if (null == m_GUIWrong)
        {
            m_GUIWrong = GameObject.Find("GUI_WrongSymbol");
            ShowGUITexture.Show(m_GUIWrong, false, true, true);
        }

        if (null == m_GUIAgain)
        {
            m_GUIAgain = GameObject.Find("GUI_Again");
            ShowGUITexture.Show(m_GUIAgain, false, true, true);
        }



        m_QuestionString = StaticData.QuestionString;
        Debug.Log("m_QuestionString=" + m_QuestionString);

        SetupForAnswerZone();
    }
Beispiel #4
0
    private void DetectAmongAnswers()
    {
        // 判斷滑鼠在哪裡
        // 依照question的answer的數目
        if (false == m_LevelGeneratorPtr.m_QuestionTable.ContainsKey(m_QuestionString))
        {
            return;
        }

        QuestionTableStruct question = m_LevelGeneratorPtr.m_QuestionTable[m_QuestionString];
        int   answerNum    = question.m_DetectionZones.Count;
        float ratioOfMouse = (float)Input.mousePosition.x / (float)Camera.main.pixelWidth;

        m_AnswerIndex = (int)(ratioOfMouse * answerNum);
        // Debug.Log( "DetectAmongAnswers() answerIndex= " + answerIndex ) ;
        // 決定question要顯示的透明半身圖
        string imagePath = "";
        int    i         = 0;

        foreach (DetectionPose pose in question.m_DetectionZones.Values)
        {
            if (i == m_AnswerIndex)
            {
                imagePath = pose.m_AnswerImagePath;
                // Debug.Log( "DetectAmongAnswers() imagePath= " + imagePath ) ;
                break;
            }
            ++i;
        }


        // 調整answersymbol的位置
        if (null != m_GUIAnswerSymbol)
        {
            m_GUIAnswerSymbol.GetComponent <GUITexture>().pixelInset =
                new Rect(m_AnswerIndex * m_AnswerSymbolWidth,
                         m_AnswerSymbolStartY,
                         m_AnswerSymbolWidth,
                         m_AnswerSymbolHeight);

            /*if( true == m_GUIAnswerSymbol.guiTexture.pixelInset.Contains( new Vector2( Input.mousePosition.x , Input.mousePosition.y ) ) )
             * {
             *      // Debug.LogError( "true == m_GUIAnswerSymbol.guiTexture.pixelInset.Contains" ) ;
             *      m_GUIAnswerDescription.guiText.color = Color.cyan ;
             * }
             * else
             */
            {
                m_GUIAnswerDescription.GetComponent <GUIText>().color = Color.red;
            }


            m_GUIAnswerDescription.GetComponent <GUIText>().pixelOffset =
                new Vector2(m_AnswerIndex * m_AnswerSymbolWidth + m_AnswerSymbolWidth / 2,
                            m_AnswerDescriptionStartY);

            ShowGUITexture.Show(m_GUIAnswerSymbol, true, true, true);
            ShowGUITexture.Show(m_GUIAnswerMouseCursor, true, true, true);
        }

        // switch and show the image
        if (0 != imagePath.Length)
        {
            m_GUIQuestionZoneAnswer.GetComponent <GUITexture>().texture =
                (Texture2D)Resources.Load("Texture/" + imagePath);
            ShowGUITexture.Show(m_GUIQuestionZoneAnswer, true, true, true);
        }

        // 如果滑鼠按下,則進入判斷流程
        if (true == Input.GetMouseButtonUp(0))
        {
            ShowGUITexture.Show(m_GUIAnswerSymbol, false, true, true);
            ShowGUITexture.Show(m_GUIQuestionZoneAnswer, false, true, true);
            ShowGUITexture.Show(m_GUIInstruction, false, true, true);
            ShowGUITexture.Show(m_GUIAnswerMouseCursor, false, true, true);

            // 把返回開啟
            ShowGUITexture.Show(m_GUIBack, true, true, true);

            m_QuestionState = QuestionState.Judge;
        }
    }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        switch (m_QuestionState)
        {
        case QuestionState.UnActive:

            if (null != m_GUIAnimationTexture)
            {
                m_GUIAnimationTexture.texture = null;
            }

            {
                ShowGUITexture.Show(m_GUIQuestionZoneAnswer, false, true, true);
                ShowGUITexture.Show(m_GUIWrong, false, true, true);
                ShowGUITexture.Show(m_GUICorrect, false, true, true);
                ShowGUITexture.Show(m_GUIInstruction, false, true, true);
                ShowGUITexture.Show(m_GUIAgain, false, true, true);
                ShowGUITexture.Show(m_GUIAnswerSymbol, false, true, true);
                ShowGUITexture.Show(m_GUIAnswerMouseCursor, false, true, true);
            }

            // show ready mark.
            m_GUIReady.enabled = true;
            m_GUIReady.gameObject.SendMessage("ClearIsDown");
            m_QuestionState = QuestionState.Ready;
            break;

        case QuestionState.Ready:

        {
            GUI_IsDown guiIsDown = m_GUIReady.gameObject.GetComponent <GUI_IsDown>();
            if (true == guiIsDown.m_IsDown && 0 != m_QuestionString.Length)
            {
                // close ready sign
                m_GUIReady.enabled = false;
                // play question
                m_AnimationPlayer.Setup(m_QuestionString);
                ShowGUITexture.Show(m_GUIInstruction, true, true, true);
                string text = StrsManager.Get(m_InstructionQuestion);
                m_GUIInstruction.GetComponent <GUIText>().text = text;

                // 把返回關閉
                ShowGUITexture.Show(m_GUIBack, false, true, true);

                m_QuestionState = QuestionState.QuestionAnimation;
            }
        }
        break;

        case QuestionState.QuestionAnimation:
            // wait for animation complete
            if (false == m_AnimationPlayer.m_IsActive)
            {
                // show drag sword sign
                ShowGUITexture.Show(m_GUIInstruction, true, true, true);
                string text = StrsManager.Get(m_InstructionMoveSword);
                m_GUIInstruction.GetComponent <GUIText>().text = text;
                m_QuestionState = QuestionState.DecideTheAnswer;
            }
            break;

        case QuestionState.DecideTheAnswer:
            DetectAmongAnswers();
            UpdateMouseCursor();
            break;


        case QuestionState.Judge:
            CheckJudge2();


            break;

        case QuestionState.CorrectAnimation:

            if (false == m_AnimationPlayer.m_IsActive)
            {
                // show drag sword sign
                QuestionTableStruct question = m_LevelGeneratorPtr.m_QuestionTable[m_QuestionString];
                m_AnimationPlayer.Setup(question.m_FinishAnimationString);
                m_QuestionState = QuestionState.FinishAnimation;
            }

            break;

        case QuestionState.FalseAnimation:
            if (false == m_AnimationPlayer.m_IsActive)
            {
                // show drag sword sign
                ShowGUITexture.Show(m_GUIAgain, true, true, true);
            }

            GUI_IsDown guiIsDown = m_GUIAgain.gameObject.GetComponent <GUI_IsDown>();
            if (true == guiIsDown.m_IsDown)
            {
                m_QuestionState = QuestionState.UnActive;
            }
            break;

        case QuestionState.FinishAnimation:

            break;
        }
    }
Beispiel #6
0
    // Update is called once per frame
    void Update()
    {
        float currentAlpha = 0;

        m_State.Update();
        switch ((FadeState)m_State.state)
        {
        case FadeState.UnActive:
            if (m_State.ElapsedFromLast() > m_StartSec)
            {
                // Debug.Log( "m_StartSec" + m_StartSec ) ;
                m_State.state = (int)FadeState.FadeIn;
            }
            break;

        case FadeState.FadeIn:
            if (true == m_State.IsFirstTime())
            {
                ShowGUITexture.Show(this.gameObject, true, true, true);
            }

            if (false == m_FadeInValid)
            {
                m_State.state = (int)FadeState.Steady;
            }

            currentAlpha = GetAlpha();
            float timeRemain = m_FadeInSec - m_State.ElapsedFromLast();
            if (timeRemain < 0.0f)
            {
                currentAlpha  = 1.0f;
                m_State.state = (int)FadeState.Steady;
            }
            else
            {
                // Debug.Log( "m_State.ElapsedFromLast()" + m_State.ElapsedFromLast() ) ;
                currentAlpha = m_State.ElapsedFromLast() / m_FadeInSec;
            }

            ApplyAlpha(currentAlpha);


            break;

        case FadeState.Steady:
            if (m_State.ElapsedFromLast() > m_SteadySec)
            {
                m_State.state = (int)FadeState.FadeOut;
            }
            break;

        case FadeState.FadeOut:
            if (false == m_FadeOutValid)
            {
                m_State.state = (int)FadeState.End;
            }

            currentAlpha = GetAlpha();
            timeRemain   = m_FadeOutSec - m_State.ElapsedFromLast();
            if (timeRemain < 0.0f)
            {
                currentAlpha  = 0.0f;
                m_State.state = (int)FadeState.End;
            }
            else
            {
                currentAlpha = timeRemain / m_FadeOutSec;
            }

            ApplyAlpha(currentAlpha);

            break;

        case FadeState.End:
            if (true == m_IsLoop)
            {
                m_State.state = (int)FadeState.FadeIn;
            }
            else if (true == m_State.IsFirstTime())
            {
                ShowGUITexture.Show(this.gameObject, false, true, true);
            }
            break;
        }
    }