示例#1
0
    void LoadQuestionTable()
    {
        TextAsset content = (TextAsset) Resources.Load( m_QuestionTableFilepath ) ;
        if( null == content )
        {
            Debug.LogError( "LoadQuestionTable() null == content" + m_QuestionTableFilepath ) ;
            return ;
        }
        XmlDocument doc = new XmlDocument() ;
        doc.LoadXml( content.text ) ;
        XmlNode rootChild = doc.FirstChild ;
        if( "QuestionTable" != rootChild.Name )
            return ;

        for( int i = 0 ; i < rootChild.ChildNodes.Count ; ++i )
        {
            XmlNode childNode = rootChild.ChildNodes[ i ] ;
            if( "QuestionDefine" == childNode.Name )
            {
                QuestionTableStruct question = new QuestionTableStruct() ;
                question.ParseXML( childNode ) ;
                if( 0 < question.m_QuestionAnimationString.Length )
                {
                    m_QuestionTable.Add( question.m_QuestionAnimationString , question ) ;
                }
            }
        }
        Debug.Log( "LoadQuestionTable() m_QuestionTable.Count=" + m_QuestionTable.Count ) ;
    }
示例#2
0
    void LoadQuestionTable()
    {
        TextAsset content = (TextAsset)Resources.Load(m_QuestionTableFilepath);

        if (null == content)
        {
            Debug.LogError("LoadQuestionTable() null == content" + m_QuestionTableFilepath);
            return;
        }
        XmlDocument doc = new XmlDocument();

        doc.LoadXml(content.text);
        XmlNode rootChild = doc.FirstChild;

        if ("QuestionTable" != rootChild.Name)
        {
            return;
        }

        for (int i = 0; i < rootChild.ChildNodes.Count; ++i)
        {
            XmlNode childNode = rootChild.ChildNodes[i];
            if ("QuestionDefine" == childNode.Name)
            {
                QuestionTableStruct question = new QuestionTableStruct();
                question.ParseXML(childNode);
                if (0 < question.m_QuestionAnimationString.Length)
                {
                    m_QuestionTable.Add(question.m_QuestionAnimationString, question);
                }
            }
        }
        Debug.Log("LoadQuestionTable() m_QuestionTable.Count=" + m_QuestionTable.Count);
    }
示例#3
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;
            }
        }
    }
示例#4
0
    private void SetupForAnswerZone()
    {
        // m_GUIAnswerZones
        m_GUIAnswerSymbol = GameObject.Find("GUI_AnswerSymbol");
        if (null == m_GUIAnswerSymbol)
        {
            Debug.LogError("SetupForAnswerZone() null == m_GUIAnswerSymbol");
            return;
        }

        if (false == m_LevelGeneratorPtr.m_QuestionTable.ContainsKey(m_QuestionString))
        {
            Debug.LogError("SetupForAnswerZone() false == ContainsKey( m_QuestionString" + m_QuestionString);
            return;
        }

        QuestionTableStruct question = m_LevelGeneratorPtr.m_QuestionTable[m_QuestionString];
        int answerNum = question.m_DetectionZones.Count;

        m_AnswerSymbolWidth  = Camera.main.pixelWidth / answerNum;
        m_AnswerSymbolHeight = Camera.main.pixelWidth * m_PictureScale;
        m_AnswerSymbolStartY = (Camera.main.pixelHeight - Camera.main.pixelWidth * m_PictureScale) / 2;
        m_GUIAnswerSymbol.GetComponent <GUITexture>().pixelInset =
            new Rect(0, m_AnswerSymbolStartY, m_AnswerSymbolWidth, m_AnswerSymbolHeight);
        // new Rect( 0 , (Camera.main.pixelHeight - Camera.main.pixelWidth * m_PictureScale) / 2 ,
        // Camera.main.pixelWidth , Camera.main.pixelWidth * m_PictureScale ) ;

        m_GUIAnswerDescription = GameObject.Find(m_GUIAnswerDescrptionName);
        if (null == m_GUIAnswerDescription)
        {
            Debug.LogError("SetupForAnswerZone() null == m_GUIAnswerDescription");
            return;
        }

        m_GUIAnswerMouseCursor = GameObject.Find(m_GUIAnswerMouseCursorName);
        if (null == m_GUIAnswerMouseCursor)
        {
            Debug.LogError("SetupForAnswerZone() null == m_GUIAnswerMouseCursor");
            return;
        }
    }
示例#5
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;
        }
    }
示例#6
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;
        }
    }