Read Current Text Character Being Written

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
uqo
Posts: 7
Joined: Mon Apr 17, 2023 5:42 pm

Read Current Text Character Being Written

Post by uqo »

Hey there,

I'm implementing an Animal Crossing-style dialogue system into a game using FMOD in Unity and can't figure out a way to read what text symbol is currently being output by the UnityUITypewriterEffect.

This is what I have so far which seems to be working fine for changing the actor in FMOD, I just want a similar way to read the current text symbol "abc" etc. it gets very confusing if I say character so just trying to be clear what I mean :lol:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FMODUnity;
using PixelCrushers.DialogueSystem;

public class FMODDialogueAudio : MonoBehaviour
{
    FMOD.Studio.EventInstance characterSound;
    int currentCharacter;

    private void Start()
    {
        characterSound = RuntimeManager.CreateInstance("event:/SFX/Dialogue/dialogueMulti");
    }

    private void Update()
    {
        int actorID = DialogueManager.currentConversationState.subtitle.speakerInfo.id;
        characterSound.setParameterByName("Speaker", actorID);
        GetCurrentCharacter();
        characterSound.setParameterByName("TextCharacter", currentCharacter);

    }

    public void PlayCharacter()
    {
        characterSound.start();
    }

    void GetCurrentCharacter()
    {
        // No idea what to do here
    }
}
any help would be greatly appreciated
User avatar
Tony Li
Posts: 21684
Joined: Thu Jul 18, 2013 1:27 pm

Re: Read Current Text Character Being Written

Post by Tony Li »

Hi,

Instead of creating a separate script like that, make a subclass of UnityUITypewriterEffect -- or, better yet, switch to TextMesh Pro (instructions) and make a subclass of TextMeshProTypewriterEffect. Use this subclass in place of the original component.

Override the PlayCharacterAudio(char) method.
uqo
Posts: 7
Joined: Mon Apr 17, 2023 5:42 pm

Re: Read Current Text Character Being Written

Post by uqo »

Thank you for the speedy reply!

I'm a little confused as to whether that solves the problem I'm having.

I need each character of the alphabet to play a different sound depending on what character that is.

I'm attempting to switch over to text mesh pro but I may not be able to due to the team I'm working on but I feel I'm stuck in a place where i would have to figure out the same issue in Text Mesh Pro?

I'm not an expert on coding as I am a sound designer so I'm sorry if I'm just not getting it.

Thanks again for your help.
User avatar
Tony Li
Posts: 21684
Joined: Thu Jul 18, 2013 1:27 pm

Re: Read Current Text Character Being Written

Post by Tony Li »

Hi,

The process is the same whether you're using a Text component or TextMesh Pro component. TextMesh Pro generally provides crisper text, but Text is fine, too.

Assuming you're using Text, create a script something like this:

FMODTypewriterEffect .cs

Code: Select all

using UnityEngine;
using FMODUnity;
using PixelCrushers.DialogueSystem;

public class FMODTypewriterEffect : UnityUITypewriterEffect
{
    FMOD.Studio.EventInstance characterSound;

    private void Start()
    {
        characterSound = RuntimeManager.CreateInstance("event:/SFX/Dialogue/dialogueMulti");
    }
    
    protected override void PlayCharacterAudio(char c)
    {
        int actorID = DialogueManager.currentConversationState.subtitle.speakerInfo.id;
        characterSound.setParameterByName("Speaker", actorID);
        int characterIntValue = (int)c;
        characterSound.setParameterByName("TextCharacter", c);
        characterSound.Start();
     }
}
Then remove the UnityUITypewriterEffect component from your subtitle text GameObject, and add an FMODTypewriterEffect instead. If other components, such as a continue button's StandardUIContinueButtonFastForward component, reference the typewriter effect, make sure you update the references in those other components, too.
uqo
Posts: 7
Joined: Mon Apr 17, 2023 5:42 pm

Re: Read Current Text Character Being Written

Post by uqo »

Thank you for writing that script out for me.

I'm currently getting an error saying that because it doesn't derive from MonoBehaviour there is an error saving.

Thank you for that note on the buttons, I think that was what was going wrong for me a minute ago
uqo
Posts: 7
Joined: Mon Apr 17, 2023 5:42 pm

Re: Read Current Text Character Being Written

Post by uqo »

Just manged to fix it i think by adding PixelCrushers.DialogueSystem. before it
uqo
Posts: 7
Joined: Mon Apr 17, 2023 5:42 pm

Re: Read Current Text Character Being Written

Post by uqo »

thank you so much for your help, i'll try and get this to work and let you know :)
uqo
Posts: 7
Joined: Mon Apr 17, 2023 5:42 pm

Re: Read Current Text Character Being Written

Post by uqo »

May I ask what the integer values of each letter are? I think this may be stopping any audio from playing as the values I have in the fmod parameter only range from 0 to 27? for a-z and space " ".
uqo
Posts: 7
Joined: Mon Apr 17, 2023 5:42 pm

Re: Read Current Text Character Being Written

Post by uqo »

Managed to get it working how i was after. thank you again for your help I was getting really stuck
User avatar
Tony Li
Posts: 21684
Joined: Thu Jul 18, 2013 1:27 pm

Re: Read Current Text Character Being Written

Post by Tony Li »

Glad to help!
Post Reply