示例#1
0
    public void ShowQuestionCanvas(SimQuestion question)
    {
        // Log the question
        Debug.Log("Display question " + question.id + ": " + question.text);
        log.Info("Display question " + question.id + ": " + question.text);

        // Fill the question canvas info
        this.transform.Find("QuestionId").GetComponent <Text>().text   = "Question " + question.id;
        this.transform.Find("QuestionText").GetComponent <Text>().text = question.text;

        // Set the height of the box depending on the number of choices
        questionBox.sizeDelta = new Vector2(questionBox.sizeDelta.x, 125 + 75 * question.choices.Length);

        // Disable all the choice buttons
        foreach (GameObject G in choiceButtons)
        {
            G.SetActive(false);
        }

        // Set the choice buttons
        Transform choiceTemplate = this.transform.Find("ChoiceTemplate");

        for (int i = 0; i < question.choices.Length; i++)
        {
            // Instantiate a new choice button
            if (i >= choiceButtons.Count)
            {
                choiceButtons.Add(Instantiate(choiceTemplate.gameObject) as GameObject);
            }

            // Get the script component of the choice button
            RectTransform buttonBox  = choiceButtons[i].GetComponent <RectTransform>();
            Text          buttonText = choiceButtons[i].transform.Find("ChoiceText").GetComponent <Text>();
            choiceButtons[i].GetComponent <ChoiceButtonController>().SetChoiceNumber(i);

            // Position the button according to its parent object
            choiceButtons[i].transform.SetParent(this.transform, false);
            buttonBox.localPosition = new Vector3(0, -150 - 75 * i, 0);

            // Change the button text
            buttonText.text = question.choices[i].text;

            //Set the button active
            choiceButtons[i].SetActive(true);
        }

        // Show the canvas
        this.GetComponent <FadingElementUI>().fadeInCanvas();

        // Pause the game until the question is answer
        if (timeController != null)
        {
            timeController.PauseGame(true);
            timeController.BlockPauseButton(true);
        }

        // If there is a focus id in the question, move the camera to the focus point
        if (question.landmark != null)
        {
            // Find the point
            foreach (LandmarkController L in listOfLandmarkPoints)
            {
                if (L.landmarkId == question.landmark)
                {
                    cameraControl.BlockPlayerControls(5);
                    cameraControl.FocusOnHotPoint(L.transform, zoomFactor);
                    break;
                }
            }
        }

        // Update current question
        currentQuestion = question;
    }