Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics

Master Audio integration

A topic by alfa995 created May 31, 2019 Views: 114 Replies: 3
Viewing posts 1 to 4
(1 edit)

Hi! I intend to use Master Audio for my projects and I was trying to get STM to play its sounds through it.

I looked into it and I think I figured out the general changes/additions it needs, it's actually pretty easy, but I hesitate to go in and just start changing code, especially since it'd become a hassle to redo the changes whenever there's a new update, plus I'm not familiar with the code to modify the editor and add the extra fields it needs. I was hoping to just request it as a feature and explain those changes to hopefully make it easier to implement?

Basically, you have a Master Audio object in the scene, define Sound Groups in it and to play sounds you just reference a Sound Group by name, passing it as a string argument on any of Master Audio's play sound methods. So to get it to work, all that's needed is to add some text fields to the default Audio Clip, the custom Audio Clips and Sound Clip in the editor.

  • default Audio Clip: just a string field, maybe with a [SoundGroup] attribute so the user can pick the sound from a dropdown.
  • Audio Clip: it wouldn't need an array of clips, since its own name could reference a Sound Group. Should have the same [SoundGroup] attribute too. The different sound variations would then be handled from Master Audio, by adding them to the Sound Group itself.
  • Sound Clip: instead of taking a clip for each character, it'd again take a string with the [SoundGroup] attribute.

That's for the editor side, now for the implementation side:

I think the only changes needed would be on the PlaySound method. There's no need for an Audio Source, Master Audio handles it separately and in fact they recommend removing them. There's no need to check if sounds are currently playing or allowed to be cut off, since each Sound Group has its own settings for that. Finding and assigning the clip to play based on the read character would be the same, but instead of finding a clip, it'd be a string with a Sound Group name. The pitch mode and all that would stay, but instead of modifying the pitch attribute of the audio source, it'd be stored in a variable and sent as an argument on a PlaySoundAndForget() call that replaces the

I think that's about it. There might be extra stuff like a way for the user to choose whether to use this or the regular implementation but that should be the core functionality.



This is something I've thought of before, and actually... I think there's enough in STM for this to be built *on top* instead of changing the code, but changing the code is fine! I publish updates semi-frequently with bugfixes, but unless a change effects you (either fixes a bug or adds a feature you want) you don't *need* to update... and if you do, I think you could use source control to merge your local changes with mine!

Either way, here's three ways to do it:

Inside of SuperTextMesh.cs, there's a PlaySound() method that's invoked every time it's supposed to play a sound. You could just edit this function to do what you need it to do! Or for a fancier approach...

You could make this a virtual method (I'd change it to be virtual myself in the next update if you go with this), and you could make a "MasterAudioSuperTextMesh" class that inherits from SuperTextMesh, but with an overridden PlaySound() function. You can even extend the custom editor to add the additional components you need with the code here: I think DrawDefaultInspector could be used to get the new components, or you could use reflection? I know I've used code like that before, I just can't find the right forum post.

Method #3 is to use STM's "OnPrintEvent"! This UnityEvent/delegate event is invoked every time a character is printed, and using it together with hyphenedText[latestNumber] you could even do events for specific letters. If you do it this way, you could just have an additional monobehaviour that sits on your STM object and handles audio stuff! This is probably the easiest way to do it and doesn't involve touching the source code at all.

Anyway, I hope this helps! I think method #3 might be the place to start, using delegate events to handle this would be great!

It's all working now! I decided to go for the second method, making a class that inherits from SuperTextMesh and overriding the PlaySound function. So yeah, I had to make it virtual in the original code, plus I modified the STMSoundClipData, STMAudioClipData and STMAutoClipData to add the string attributes I needed. Figuring out the editor changes was a bit confusing at first but other than that it wasn't too hard.

Hope it's not too much trouble, making PlaySound virtual for the next update like you mentioned. Thank you so much for your help!


Sure! I don't thiiiink it should break anything, so why not!