Bear in mind that if you hate Singleton, you might hate my example too. But at the very least, I hope it gives you an idea of what can be done and what not with sound assets.
Please bear in mind that it will load all sound asset in one scriptable object file. So if you have a lot of sounds, this system might add some overhead in memory & you might have to do some tweaks on yourself to load only necessary sounds by scene. I will try to do it eventually when I get time. Nevertheless, if you are making a game where you don’t have issue with loading all sound files in memory (like a casual game for example), this system will help you I am sure of it.
In unity we mostly use audio as PlayOneShot most of the time. As we all know, PlayOneShot takes file name as params. But managing file name via string => YUCK!
This project turns all your audio files in Enum as part of a scriptable object!
(Make sure you have at least one audio file in project!)
1. Go To Window/EzAudioManager
2. Click the big button
3. It will generate a Scriptable Object in Resources/EzAudioBook.asset
=== This should create all the necessary files. Check if all sounds came into your scriptable object.
4. In your scene, Add EzAudioManager/EzAudioSystem.prefab
5. In your script, just write
- If filename cannot be turned as an identifier, then it will have
INVALID_NAME_Xwhere x will be a number ofcourse.
If you want to investigate further, go to
EzAudioManager/EzAudioFiles.cs. You will see which files is invalidated due to bad name.
(You are welcome! 😛 )
- If same filename found in multiple places, same thing will happen, it will be marked as
- Spaces in file names will be replaced by underscore
- Optimize for Background and other musics, which are not necessarily played with PlayOneShot function.
License & Policy
Do whatever you want with it. I hope it will help you in your project!
Thanks to my company Ulka Games who give me enough freedom to publish these kind of things.