FMOD Sequencer Command

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 20623
Joined: Thu Jul 18, 2013 1:27 pm

FMOD Sequencer Command

Post 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(); 
            }
        }
    }
}
User avatar
Tony Li
Posts: 20623
Joined: Thu Jul 18, 2013 1:27 pm

Re: FMOD Sequencer Command

Post 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);
    }
}
Post Reply