Page 1 of 2

Customize typewriter stop characters?

Posted: Thu Aug 29, 2019 4:11 am
by nicmar
Hey, what is the recommended way to change the typewriter custom characters?

I like that there's a break on PERIOD and a short break on COMMA, but I don't like the break when having three periods in a row, like this:

"Where is the smell coming from...?"

Is there a way to ignore ... and only respect . in the end of a sentence or before a space?

Thanks!

Re: Customize typewriter stop characters?

Posted: Thu Aug 29, 2019 8:06 am
by Tony Li
Here are a few options:

1. Use a character that looks like a period but is not.

2. Or, turn off that feature in the typewriter effect. Instead, manually add "\." whenever you want to add a period pause.

3. Or, customize UnityUITypewriterEffect or TextMeshProTypewriterEffect, depending on which type of UI component you're using. I recommend making a subclass or a copy of the script. Don't edit the script directly. Otherwise it will be overwritten when you update the Dialogue System.

Re: Customize typewriter stop characters?

Posted: Thu Aug 29, 2019 9:36 am
by nicmar
Thanks, I'll make a custom UnityUITypewriterEffect, and make sure to subclass it :)

Re: Customize typewriter stop characters?

Posted: Wed Oct 23, 2019 2:08 am
by nicmar
Hey Tony!

I finally got around to subclassing the UnityUITypewriterEffect, but I've having a little trouble figuring out where to inject my code.

This seemed to work, is this how you would do it? :)

Code: Select all

    public class CustomUnityUITypewriterEffect : UnityUITypewriterEffect
    {

        public override IEnumerator Play(int fromIndex = 0)
        {
            if ((control != null) && (charactersPerSecond > 0)) {
                control.text = control.text.Replace("...", "…").Replace("..", "…");

            }
            typewriterCoroutine = coroutineController.StartCoroutine(base.Play(fromIndex));
            yield return null;
        }

    }
(EDITED, first it didn't work, but I had miss an inspector setting when changing to the custom class)

Re: Customize typewriter stop characters?

Posted: Wed Oct 23, 2019 2:17 am
by nicmar
Oh yeah I had to change this in the original class (out of order):

Code: Select all

        protected UnityEngine.UI.Text control;
        protected Coroutine typewriterCoroutine = null;
        protected MonoBehaviour coroutineController = null;
        public virtual IEnumerator Play(int fromIndex = 0)
I think we talked about this in another thread, that some of these should be protected / virtual instead of private / non-virtual :)

Re: Customize typewriter stop characters?

Posted: Wed Oct 23, 2019 8:54 am
by Tony Li
Hi,

They're all set to protected/virtual in the upcoming version 2.2.2 being released this week. So if you update to 2.2.2 there are no worries about losing your edits to UnityUITypewriterEffect.

Re: Customize typewriter stop characters?

Posted: Wed Oct 23, 2019 9:00 am
by nicmar
Cool thanks! So did you think my solution is a solid one that you would recommend? :)

Re: Customize typewriter stop characters?

Posted: Wed Oct 23, 2019 9:09 am
by Tony Li
Two thoughts:

1. Make sure your fonts support the elipsis (…) character.

2. Change this line:

Code: Select all

yield return null;
to this:

Code: Select all

yield return typewriterCoroutine;

Re: Customize typewriter stop characters?

Posted: Wed Oct 23, 2019 3:24 pm
by nicmar
Thanks!

Re: Customize typewriter stop characters?

Posted: Thu Oct 24, 2019 3:05 am
by nicmar
I though of a different thing and I can't figure out how to solve it.

My stop chars are . ? ! and ellipsis. I autoconvert .. and ... into ellipsis using the script in this thread.

But sometimes I want it to say something like this, to make the character seem hesitant:
Are you sure..?

This would give two stops (ellipsis + ?).

Could you think of any way to work around this? Without manually adding break chars, cause that would be too much work.. :)

Thanks!