Beispiel #1
0
    /// <summary>
    /// Create a speech balloon, sized appropriately for its text.
    /// </summary>
    /// <returns>The balloon's TextMeshPro component, so that its text can be set.</returns>
    protected TextMeshProUGUI AddBalloon(string message, BalloonTypes type)
    {
        GameObject      balloon      = MonoBehaviour.Instantiate <GameObject>(speechBalloon, chatContent);
        TextMeshProUGUI balloonText  = balloon.transform.Find(TEXT_OBJ).GetComponent <TextMeshProUGUI>();
        Image           balloonImage = balloon.transform.Find(IMAGE_OBJ).GetComponent <Image>();

        balloonImage.sprite = AssignBalloonImage(type);
        balloonImage.color  = AssignBalloonColor(type);

        int rows = message.Length / SIZE_PER_ROW;

        rows = rows < 1 ? 1 : rows;         //don't let rows be 0;

        int height = TEXT_ROW_SIZE * rows;


        //resize the balloon

        //the balloon object needs to be big enough for the speech balloon, plus some extra to create space between balloons
        balloon.GetComponent <RectTransform>().sizeDelta = new Vector2(CHAT_WINDOW_WIDTH, height + BALLOON_PADDING);

        //the balloon image doesn't need the extra space
        balloonImage.GetComponent <RectTransform>().sizeDelta = new Vector2(CHAT_WINDOW_WIDTH, height);


        return(balloonText);
    }
Beispiel #2
0
    /// <summary>
    /// For generic statements of unpredictable formatting--how many attacks the Ranger has left, etc.
    /// </summary>
    public void MakeStatement(string statement, BalloonTypes type)
    {
        TextMeshProUGUI balloon = AddBalloon(statement, type);

        balloon.text = statement;

        ManageChatLength();
        WaitTask waitTask  = new WaitTask();
        WaitTask waitTask2 = new WaitTask();         //an ugly, irksome bodge! the scrollbar needs to be fully resized before the scrolling starts

        waitTask.Then(waitTask2);
        waitTask2.Then(new ScrollChatTask());

        Services.Tasks.AddTask(waitTask);
    }