Page 1 of 1

FMOD Sequencer Command

Posted: Wed Nov 04, 2020 9:34 am
by Tony Li
Discord user Nemesis Warlock shared a sequencer event FMODAudioEvent(uri) to play one-shot FMOD audio:

SequencerCommandFMODAudioEvent.cs

Code: Select all

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

namespace PixelCrushers.DialogueSystem.SequencerCommands
{
    public class SequencerCommandFMODAudioEvent : SequencerCommand
    {
        public void Awake()
        {
            string FMODEvent = GetParameter(0);

            if (!string.IsNullOrEmpty(FMODEvent))
            {
                RuntimeManager.PlayOneShot(FMODEvent);
                Stop(); 
            }
        }
    }
}

Re: FMOD Sequencer Command

Posted: Wed Jan 05, 2022 4:40 pm
by Tony Li
If you want to change the typewriter effect to use FMOD, make a subclass of your typewriter script (UnityUITypewriterEffect or TextMeshProTypewriterEffect) and override PlayCharacterAudio(). Something like:

Code: Select all

public class MyTypewriterEffect : TextMeshProTypewriterEffect
{
    protected override void PlayCharacterAudio()
    {
        FMODUnity.RuntimeManager.PlayOneShot("your typewriting sound");
    }
}
If you want to play different sounds based on the character being typed, you can override PlayCharacterAudio(char c) instead (or in addition).

different sound based on the actor, you could set "your typewriting sound" in an OnConversationLine method, or by overriding StandardUISubtitlePanel.ShowSubtitle, or right in your overridden typewriter script: (In this example, the actor has a custom field named "Typewriter Sound" that names the FMOD event.)

Code: Select all

public class MyTypewriterEffect : TextMeshProTypewriterEffect
{
    private string soundEvent;

    public override void StartTyping(string text, int fromIndex = 0)
    {
        Actor actor = DialogueManager.masterDatabase.GetActor(DialogueManager.currentConversationState.speakerInfo.id);
        soundEvent = actor.LookupValue("Typewriter Sound");
        base.StartTyping(text, fromIndex);
    }

    protected override void PlayCharacterAudio()
    {
        FMODUnity.RuntimeManager.PlayOneShot(soundEvent);
    }
}