GetString() public method

public GetString ( ) : string
return string
Exemplo n.º 1
0
 private void UpdateButtons()
 {
     //char[] letters = new char[]{'A', 'B', 'C', 'D', 'E'};
     for (int i = 0; i < answerButtonTexts.Length; i++)
     {         //set button text
         if (i >= availableAnswers.Count)
         {
             Debug.LogWarning("Not enough distractors");
             return;
         }
         ProblemPart part = (ProblemPart)availableAnswers[i];
         answerButtonTexts[i].text = part.GetString();             //"(" + letters[i] + ") " +
     }
 }
    private void PopulateRichTextAreas(Problem problemToDisplay)
    {
        Question question       = problemToDisplay.GetQuestion();
        int      textAreaCount  = question.GetQuestionPartCount();
        float    ySpacePerArea  = 1f / (float)(textAreaCount - question.GetMultipleChoiceLetterCount());
        float    xSpacePerImage = (float)1 / Mathf.Clamp((float)question.GetMaximumQuestionPartRepeated(), 1, imagesPerRow);
        float    ySpacePerImage = (float)1 / Mathf.Ceil((float)question.GetMaximumQuestionPartRepeated()
                                                        / (float)imagesPerRow);

        int  row = 0;
        bool previousAreaWasMultipleChoice = false;

        if (textAreaCount == 0)
        {
            Senseix.Logger.BasicLog("I got a problem with no question atoms.");
            return;            //throw new UnityException ("I got a problem with no question atoms.");
        }
        richTextAreas = new GameObject[textAreaCount];

        for (int i = 0; i < textAreaCount; i++)
        {
            GameObject  newArea     = Instantiate(questionTextPrefab) as GameObject;
            ProblemPart problemPart = problemToDisplay.GetQuestion().GetQuestionPart(i);

            if (newArea.GetComponent <RectTransform>() == null ||
                newArea.GetComponent <Text>() == null)
            {
                throw new UnityException("richTextArea must have a rect transform and Text");
            }

            if (problemPart.HasString())
            {
                newArea.GetComponent <Text>().text += problemPart.GetString();
            }

            float indentedX = 0f;
            if (previousAreaWasMultipleChoice)
            {
                indentedX = indentMultipleChoices;
            }

            newArea.GetComponent <RectTransform>().SetParent(questionParent);
            PositionRectTransform(newArea.GetComponent <RectTransform>(),
                                  indentedX,
                                  1 - (row + 1) * ySpacePerArea,
                                  1,
                                  1 - row * ySpacePerArea);

            if (problemPart.HasSprite())
            {
                //squish this a little bit to provide space between image groups
                newArea.GetComponent <RectTransform>().anchorMin += new Vector2(0f, spaceImageAreas);
                newArea.GetComponent <RectTransform>().anchorMax -= new Vector2(0f, spaceImageAreas);


                for (int j = 0; j < problemPart.TimesRepeated(); j++)
                {
                    GameObject newImage = Instantiate(questionImagePrefab) as GameObject;
                    newImage.GetComponent <RectTransform>().SetParent(newArea.transform);
                    int imageColumn = j % imagesPerRow;
                    int imageRow    = Mathf.FloorToInt((float)j / (float)imagesPerRow);
                    PositionRectTransform(newImage.GetComponent <RectTransform>(),
                                          (imageColumn * xSpacePerImage),
                                          1 - (imageRow + 1) * ySpacePerImage,
                                          ((imageColumn + 1) * xSpacePerImage),
                                          1 - imageRow * ySpacePerImage);

                    newImage.GetComponent <Image>().sprite = problemPart.GetSprite();
                }
            }

            richTextAreas[i] = newArea;

            if (!problemPart.IsMultipleChoiceLetter())
            {
                row++;
                previousAreaWasMultipleChoice = false;
            }
            else
            {
                previousAreaWasMultipleChoice = true;
            }
        }
    }