- #Unity audio overload update#
- #Unity audio overload pro#
- #Unity audio overload code#
- #Unity audio overload plus#
The SoundManager automatically creates a list internally from all 'sound variations' of a given sound type, and when you invoke PlaySound(), it selects one randomly.
#Unity audio overload code#
In terms of refactoring, internally the class changed a lot basically I encapsulated all AudioSource handling responsibilities into a separate nested class, and cut out all code duplication in the method overloads. The most visible change is that the methods now return the sound type in the callback, so you can route multiple playback finished notifications into a single method, and check there which one was finished.
#Unity audio overload plus#
Plus I changed the public method signatures. :) Anyhow, I refactored the SoundManager class again.
#Unity audio overload update#
Update3: I swear I'll stop adding these update sections here. Available logging settings: None, LogOnlyInEditor and LogAlways. So you can turn off logging for deployed builds in a way that completely avoids string operations and allocations (since all debug messages are constructed inside this helper class). Update2: I encapsulated all debug log messages into a separate class, and added a logging setting to the Inspector. Short testing shows this new feature to be working well, but please inform me of any bugs. For this addition I refactored the class internally. This means that the SoundManager can now be used for moving objects too. Update1: I added the capability of Transform tracking playback in the form of two new public methods. I just tried to help others too to understand it better. Note that the comments in the code are a bit excessive if you're an experienced developer. (I also have some ideas for additional features, but those would require some more book-keeping, plus classes where nesting them is not really justifiable.) I think it's a relatively maintainable/extensible design, so you shouldn't have a very hard time adding new features if you wanted. ) I tried to generally separate the responsibilities, but without creating a confusing amount of classes/files, so I pretty much nested everything into a single class.
#Unity audio overload pro#
Pro tip: It's totally not spaghetti code. I've been using it in my project for quite some time, and I'm a satisfied customer, so to speak, so I decided to share it.
So this is just a small, relatively simple component with solid core features that should perform reliably and efficiently. Admittedly I haven't looked into any implementations on the Asset Store, etc., because I didn't want to spoil the fun of writing mine from scratch. My take on a light-weight sound manager for Unit圓D. SoundManager component for Unit圓D With modulation ranges, AudioSource pooling, playing at world coordinates, and even playing while following a Transform Version information: Tested in Unity 2018.3, requires scripting runtime set to '.Net 4.x equivalent' (uses C# 7 features)