Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(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.