Page 2 of 3
Re: Typewriter effect and Size fitter
Posted: Fri Jul 14, 2023 5:27 pm
by Shinos
Hi,
sorry if i didn't answer before, unfortunately i had some busy days, thanks for your help i'll try your script right now.
Re: Typewriter effect and Size fitter
Posted: Fri Jul 14, 2023 5:57 pm
by Shinos
ok i tried it, but unless i'm doing something wrong it doesn't seem to work as intended:
here's a record : the red one works because it is using the old subclass with text and not textmeshpro, the green with the new suggestions and script does not scale the bubble with the text
https://youtube.com/shorts/zSFmxPjtq_U
Re: Typewriter effect and Size fitter
Posted: Fri Jul 14, 2023 8:56 pm
by Tony Li
Hi,
The script I provided in a previous reply expands vertically, not horizontally. It's just an example.
Re: Typewriter effect and Size fitter
Posted: Sat Jul 15, 2023 10:55 am
by Shinos
I see, but i tried more and it does not expand vertically if the text exceed it just goes out of the bubble speech, the bubble remains of the same size whatever happens both vertically and horizontallly.
PS: i have to apologize i tried it with the default prefab of the bubble subtitles and it indeed resize vertically, now i only have to understand what i did wrong with mine custom bubble and how to make it resize also horizontally.
thanks
Re: Typewriter effect and Size fitter
Posted: Sat Jul 15, 2023 10:59 pm
by Tony Li
Hi,
If you compare the Layout Elements and Horizontal/Vertical Layout Groups of the bubbles, you should be able to identify what's different in the bubble UIs.
Resizing horizontally is going to require a little more code. I think you'll need to call textComponent.ForceMeshUpdate() and then use Mathf.Min() to set the Layout Group's Min Width to the lesser value of textBounds.x and the maximum width you want your bubble to grow before line wrapping.
Re: Typewriter effect and Size fitter
Posted: Mon Jul 17, 2023 3:13 am
by Shinos
Hi,
so i was trying implementing your tips for the horizontal and this is the code now:
Code: Select all
using PixelCrushers.DialogueSystem;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class CustomTMProTypewriter : TextMeshProTypewriterEffect
{
[SerializeField] private float maxBubbleWidth;
private void Update()
{
if (isPlaying)
{
var bounds = textComponent.textBounds;
layoutElement.preferredHeight = bounds.size.y;
textComponent.ForceMeshUpdate();
float preferredWidth = Mathf.Min(bounds.size.x, maxBubbleWidth);
layoutElement.preferredWidth =preferredWidth;
}
}
but it doesn't work as intended, this is what happens actually ahaha
- Senza titolo.png (3.43 KiB) Viewed 945 times
Re: Typewriter effect and Size fitter
Posted: Mon Jul 17, 2023 10:12 am
by Tony Li
Hi,
Try setting layoutElement.minWidth, too.
Re: Typewriter effect and Size fitter
Posted: Mon Jul 17, 2023 3:58 pm
by Shinos
Hi,
tried but nothing, same result, setting minwidth just get the width stuck, and it gets updated only the vertical size the same as before, i need to resize horizontal size not vertical, (preferrable would be both)
the preferred height gets updated and it works flawessly, but the preferred width gets stuck at a value of 23 i don't know why. and it just resize vertically making it static in the horizontal axis
Re: Typewriter effect and Size fitter
Posted: Mon Jul 17, 2023 10:07 pm
by Tony Li
This is a bit complicated to do with TMPro. Here's a script:
Code: Select all
using PixelCrushers.DialogueSystem;
using UnityEngine;
public class CustomTMProTypewriter : TextMeshProTypewriterEffect
{
[SerializeField] private float maxBubbleWidth;
private void Update()
{
if (isPlaying)
{
layoutElement.minWidth = layoutElement.preferredWidth = maxBubbleWidth;
Canvas.ForceUpdateCanvases();
textComponent.ForceMeshUpdate();
var bounds = textComponent.textBounds;
var desiredX = Mathf.Min(bounds.size.x, maxBubbleWidth);
var desiredY = bounds.size.y;
layoutElement.minHeight = layoutElement.preferredHeight = desiredY;
layoutElement.minWidth = layoutElement.preferredWidth = desiredX;
textComponent.ForceMeshUpdate();
Canvas.ForceUpdateCanvases();
}
}
}
You'll need to set up a Mask:
- tmpromask.png (67.48 KiB) Viewed 916 times
And the first line will type by word, not by character.
Re: Typewriter effect and Size fitter
Posted: Mon Jul 24, 2023 5:47 pm
by Shinos
Hi,
sorry if i did not answer before, i also tried this, but unless i did something wrong it didn't worked as intended, like i can't even see the words now, so maybe i screwed up something regarding the mask, but anyway they keep to be wrote only in vertical and the horizontal line keeps to stay at the same minimun lil size, so i just kinda gave up, cause this resulted to be a bigger issue to solve than i thought it was, and even if i still think it's not as cool as having the speech box to resize as the words gets typed i'll just use the default system as it was at the beginning, it's worth to say that without Text Mesh Pro the script you provided at the beginning worked, but since i do not have TextAnimator, to give a little fancy feel to my dialogues i really need TMPro, so that's it. I'm, sorry to have bothered you without coming to an actual "solution" but don't worry