[HOWTO] How To: Show Platform-Specific Text & Audio
Posted: Mon Mar 15, 2021 7:46 pm
A Dialogue System user asked (paraphrasing):
C# code:
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:
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)"
The [var=variable] markup tag is a relatively easy way to include conditional text in your Dialogue Text. Example: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?
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."
I can suggest two different ways to play platform-specific audio:2. How do I play platform-specific, localized 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
}
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)"