Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

[solved] Speech Bubble Transform

A topic by BingrunJ created Mar 03, 2019 Views: 493 Replies: 2
Viewing posts 1 to 3
(1 edit)

Hi!

I'm trying to make my speech bubble to grow when the dialogue text is typing by using the ContentSizeFitter Component. 

But it seems not working, for now. The boundary already at the finish place when the text still typing.

I know there are some topics talking about this but it's been a while and I just wanna know if there is a specified way to achieve this effect in the new release? ( I'm using STM 1.8.11 in Unity 2018.3.3f1 )

Thanks!


Developer (1 edit)

Hey!


I just wrote up a helper script that should do what you need, attach this to a child of your STM object, and it should update the size of its rect to match STM's textBounds variables:


using UnityEngine;
using System.Collections;
[RequireComponent(typeof(RectTransform))]
public class STMMatchRect : MonoBehaviour {
    private RectTransform tr; //this object's own transform
    public SuperTextMesh stm; //stm used for reference
    public Vector2 size;
    public Vector2 offset;
    
    //set up events!
    public void OnEnable()
    {
        stm.OnPrintEvent += Match;
        tr = GetComponent<RectTransform>();
    }
    public void OnDisable()
    {
        stm.OnPrintEvent -= Match;
    }
    //make this object's rect match STM's current text rect.
    public void Match()
    {
        //box size, plus offset
        size.x = stm.bottomRightTextBounds.x - stm.topLeftTextBounds.x;
        size.y = -stm.bottomRightTextBounds.y + stm.topLeftTextBounds.y;
        offset.x = stm.rawTopLeftBounds.x + stm.rawBottomRightBounds.x * 2f;
        offset.y = -size.y - stm.rawTopLeftBounds.y;
        tr.sizeDelta = size;
        tr.anchoredPosition = offset;
        tr.pivot = Vector2.zero;
    }
}


Also, as it stands, this will actually set the size incorrectly, as STM calculates its bounds after calling events. I went ahead and fixed that alongside a long-standing bounding box sizing issue, so this will work with the next update! (The helper script will be included, too)


Please send me an email with your invoice no. and I'll send the update immediately! I'll be submitting it to the asset store/itch in just a moment. If v1.8.12 is up, then that's what I just submitted.

(1 edit)

Hi Kai!

Thank you so much! I will send you the mail ASAP.