Customize typewriter stop characters?

Announcements, support questions, and discussion for the Dialogue System.
nicmar
Posts: 133
Joined: Wed Aug 21, 2019 2:39 am

Customize typewriter stop characters?

Post 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!
Working on SpaceChef - A wacky open world space western, featuring a chef with nothing to loose, after he loses everything.. ;) Follow our work on @BlueGooGames.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Customize typewriter stop characters?

Post 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.
nicmar
Posts: 133
Joined: Wed Aug 21, 2019 2:39 am

Re: Customize typewriter stop characters?

Post by nicmar »

Thanks, I'll make a custom UnityUITypewriterEffect, and make sure to subclass it :)
Working on SpaceChef - A wacky open world space western, featuring a chef with nothing to loose, after he loses everything.. ;) Follow our work on @BlueGooGames.
nicmar
Posts: 133
Joined: Wed Aug 21, 2019 2:39 am

Re: Customize typewriter stop characters?

Post 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)
Working on SpaceChef - A wacky open world space western, featuring a chef with nothing to loose, after he loses everything.. ;) Follow our work on @BlueGooGames.
nicmar
Posts: 133
Joined: Wed Aug 21, 2019 2:39 am

Re: Customize typewriter stop characters?

Post 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 :)
Working on SpaceChef - A wacky open world space western, featuring a chef with nothing to loose, after he loses everything.. ;) Follow our work on @BlueGooGames.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Customize typewriter stop characters?

Post 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.
nicmar
Posts: 133
Joined: Wed Aug 21, 2019 2:39 am

Re: Customize typewriter stop characters?

Post by nicmar »

Cool thanks! So did you think my solution is a solid one that you would recommend? :)
Working on SpaceChef - A wacky open world space western, featuring a chef with nothing to loose, after he loses everything.. ;) Follow our work on @BlueGooGames.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Customize typewriter stop characters?

Post 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;
nicmar
Posts: 133
Joined: Wed Aug 21, 2019 2:39 am

Re: Customize typewriter stop characters?

Post by nicmar »

Thanks!
Working on SpaceChef - A wacky open world space western, featuring a chef with nothing to loose, after he loses everything.. ;) Follow our work on @BlueGooGames.
nicmar
Posts: 133
Joined: Wed Aug 21, 2019 2:39 am

Re: Customize typewriter stop characters?

Post 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!
Working on SpaceChef - A wacky open world space western, featuring a chef with nothing to loose, after he loses everything.. ;) Follow our work on @BlueGooGames.
Post Reply