[HOWTO] How To: Show Platform-Specific Text & Audio

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

[HOWTO] How To: Show Platform-Specific Text & Audio

Post by Tony Li »

A Dialogue System user asked (paraphrasing):
For WebGL builds, my project's menu key is Tab. For other platforms, it's Esc. I also have two versions of each localized voiceover audio file -- one for WebGL, another for other platforms.

1. How do I include the key name in dialogue text?
The [var=variable] markup tag is a relatively easy way to include conditional text in your Dialogue Text. Example:

C# code:

Code: Select all

#if UNITY_WEBGL
    DialogueLua.SetVariable("MenuKey", "Tab");
#else
    DialogueLua.SetVariable("MenuKey", "Esc");  
#endif
  • Dialogue Text: "Press [var=MenuKey"] to open the menu."
2. How do I play platform-specific, localized audio?
I can suggest two different ways to play platform-specific audio:

Let's say you're playing in French and entrytaglocal is "NPC_42_7_fr".

You have two files: NPC_42_7_fr_webgl for WebGL and NPC_42_7_fr for all other platforms.

1. If you're playing audio using the Audio() or AudioWait() sequencer commands, you can make a similar custom command -- say, AudioWaitPlatform() -- that appends "_webgl" to the audio filename before trying to load it if the build is for WebGL.

2. Or, you could continue to use AudioWait(). Instead, add a script with an OnConversationLine method to the Dialogue Manager. In OnConversationLine, replace the string "{{platform}}" with "_webgl" in the sequence for WebGL builds and with nothing in other builds:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
#if UNITY_WEBGL
    subtitle.sequence = subtitle.sequence.Replace("{{platform}}", "_webgl");
#else
    subtitle.sequence = subtitle.sequence.Replace("{{platform}}", "");
#endif
}
Then say your Sequence is: AudioWait(entrytaglocal{{platform}}))

OnConversationLine will receive subtitle.sequence = "AudioWait(NPC_42_7_fr{{platform}})"

In WebGL, it will fix up subtitle.sequence to be AudioWait(NPC_42_7_fr_webgl)"
Post Reply