Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

AudioManager - A nifty unity extension [Testers?]

Discussion in 'Works In Progress - Archive' started by mathiassoeholm, Mar 6, 2013.

  1. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Hello there! :)

    AudioManager (in lack of a fancy name), is a nifty little extension for Unity, which allows you to easily manage and play audio. Instead of keeping track of multiple audio sources, all your sounds are grouped in a single window, as shown below:

    $AudioManager.PNG

    The cool thing is that it automatically generates convenient static methods, to play your sound effects. So to play a sound all you have to do is call the appropriate method. If you're using an IDE with autocompletion it will pop up as a suggestion:

    $AutoCompletion.png

    If you want to contribute, you can fork the repo on GitHub.

    More info and download here

    The AudioManager will be freely available on the Asset Store once properly tested.

    If you have any feedback, future requests etc. leave a reply..

    Thanks :D
     
    Last edited: Mar 21, 2013
  2. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Here's the changes I made

    • Removed need for Apply button
    • Audio settings are updated live
    • More compact layout
    • Ability to sync settings between files
    • A few extra settings

    And a new screenshot

     

    Attached Files:

    Last edited: Mar 10, 2013
  3. TerrainCreator

    TerrainCreator

    Joined:
    Aug 12, 2012
    Posts:
    161
    Looks awesome, ill give it a go
     
  4. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Yay, thanks mate! :D

    Please don't freak out if you encounter bugs, just post them and I'll do my best to fix them.

    EDIT: Just fixed the prefab contained in the plugins folder, so it doesn't contain references to my missing audio files :)
     
    Last edited: Mar 8, 2013
  5. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Okay it's come to my attention that the extension kinda breaks when downlaoding straight from the repo.

    So there's now a perma link to the latest version in a unity package on the github page :)
    The newest version also include some critical bugfixes.

    ATM the tool doesn't support the webplayer platform, because of some IO operations.. Currently looking into this
     
  6. Ben-Massey

    Ben-Massey

    Joined:
    Jun 13, 2011
    Posts:
    581
    Hey, this looks like a really neat tool! Correct me if im wrong but is this accessed globally or is this simply a component/gameobject you have to set up in your scene? Thanks.
     
  7. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Thanks :)

    It is accesed globally through the window menu -> Audio Manager :)

    It requires a gameobject with an AudioManager component in the scene, but that is automatically taken care of.
     
    Last edited: Mar 10, 2013
  8. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Added more stuff, as you can see in the screenshot:



    You can tag a sound either as sound effect or music.. This is to make it easy to mute them independently, if needed :)
     

    Attached Files:

  9. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    382
    this is pretty cool I will have to check it out thanks!
     
  10. SuperSlonik

    SuperSlonik

    Joined:
    Feb 14, 2013
    Posts:
    132
    yeah, seems like an interesting idea. i would like to give it a shot!
     
  11. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Thanks! Tell me what you think :)
     
  12. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Okay this thing is almost ready for the asset store, I think..



    Here's what's updated:

    • Support for webplayer platform
    • Mute methods
    • Support for collections of audio
    • Minor bugfixes

    I haven't heard from anyone, is everything working?

    I need to make some tests to see if mobile platforms works, and how the editor looks with pro.
    Any help is very much appreciated :)
     
  13. jamieo01

    jamieo01

    Joined:
    Nov 24, 2009
    Posts:
    68
    When I import the files into Unity it insta-crashes.

    Here is an image of the error message I get

    $Crash.png
     
    Last edited: Mar 21, 2013
  14. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Are you using a version of Unity prior to 4.0?

    It also seams that you have more than one file called AudioManager.cs, this creates conflicts.
    This might be because you have a file beforehand with the same name as one of my files.
    You might have to rename your file then.

    Thanks for the feedback :)
     
  15. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    Just wobdering, Can this be used to control your music in game? (I mean, can I change all the volume settings and so during run time?)
     
  16. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Yup, in the latest version just uploaded, there are three static properties (AudioManager.MasterVolume, AudioManager.MusicVolume, AudioManager.SoundEffectsVolume). Setting these updates the audio volume levels. :)
     
  17. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    Cool, I'll defiantly check it out.

    One more question, How are you doing the whole fill up your list of audio sources?
    just wanting to know how efficient it is.
     
  18. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    The audio sources are created using a simple pooling system, so the instantiated audio sources gets reused. :)
     
    Last edited: Mar 23, 2013
  19. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    When trying to import, I got an error that crashed unity.
    After running unity again, I get this:
    I'm gussing you made the prefab in unity4 and I'm using 3.5 so that might be it.
    How was the prefab build? (so I can create a new one)

    You might wanna create some simple help document.
     
    Last edited: Mar 23, 2013
  20. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    The prefab is simply an empty gameobject with the AudioManager component applied to it.. The path 'Assets/Plugins/AudioManager/AudioManager.prefab' is vital..

    And you guessed right, I made it with 4.1. I assume that I'll just have to export the package from an older version of Unity for those versions to be supported.

    And yeah, I'm planning to create some in depth documentation for it. :)

    Thanks!
     
  21. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    I'm not sure why, but I'm not seeing the custom inspector.
    Any ideas?

    **edit**
    nvm lol, didn't notice it's actually a custom window, not inspector.
     
  22. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    Whne trying to play a sound in the AudioManager window, I get this error:
    btw, It seems the manager is automatically deciding if the clip I'm adding is a music or sound effect.
    Are you doing this by checking the clip length or something? its pretty cool!
     
    Last edited: Mar 26, 2013
  23. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Hmm, unforunateley I wansn't able to recreate the bug..

    I think it might be a problem occuring becuase you used and older version of the AudioManager, and some audio sources are saved which aren't compatible with the new version.

    To fix the problem, try selecting all audio sources in the hierachy and delete them. If that doesn't work, try downloading the latest version of the AudioManager and try with a new project.

    And yes, the AudioManager checks the clips length, if it is above 8 seconds, it's assumed to be music ;)

    And thanks for the feedback, helps alot :)
     
  24. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    I have another question.
    I noticed that when using AudioManager.PlaySound() commend, you are creating an audio source in the scene that plays the given sound.
    So how should I go about with 3D sound? my SFX are meant to come from a specific location.
     
  25. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Good question!
    I haven't implemented support for it yet. But much like you can play a sound with a volume parameter, there will be an overload to spawn/move the source at a specific location, and also an option to child the source to a gameobject.
     
  26. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    I think somthing like: AudioManager.PlaySound("soundsname", gameobject)
    And have the manager add an audio source component to that gameobject with the given sound, will be best.

    You might wanna add DontDestroyOnLoad to the AudioManager prefab.
     
    Last edited: Mar 27, 2013
  27. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Childing or adding it will have the same result. I find childing easier with the way the rest of the code works :)

    Working on requested features now, thanks for the input!

    EDIT: About the don't destroy on load thing.. The Audio Manager is supposed to be destroyed, otherwise you might end up with multiple instances. If the AudioManager is missing in a scene, you simply have to open the scene and add focus to the AudioManager window for a second. I know this isn't very intuitive, I'll see what I can do :)
     
    Last edited: Mar 30, 2013
  28. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    But if I have 2 Audio Managers (one in each scene) each one will have different audio clips/settings/whatever.
    I want to have one Audio Manager placed on the first scene and that is it.
    To prevent your script from creating multiple instances, so can just do something like:
    Code (csharp):
    1. if (!GameObject.Find("Audio Manager")){
    2.    //spwan an Audio Manager
    3. }
     
  29. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Nope, the settings are synced from the prefab. Or at least it should be, is that not the case?
     
  30. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    How are they synced? something has to hold all settings and everything.
    If whats holding the setting is the Audio Manager located in the scene, then no, that is not the case.
    when going to a different scene, all gameobject from previous scene are gone.
     
  31. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    The AudioManager prefab, located in your assets folder :)
    When changing settings you are actually changing the local prefab directly.
     
  32. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    OH... ok, wasn't sure if its possible...
    I'm gonna test it and see if it really works and get back to you :)
     
  33. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Thanks a lot mate :)
     
  34. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    It seems the volume are being saved.
    But I stumbled upon two issues.

    1. When misspelling a name of a clip, you get no indication.
    You should add some check when calling AudioManager.PlaySound() to see if the name of the clip is available in the AudioManager and if not, show an error.

    2. Not sure why but when trying to play a clip with AudioManager.PlaySound() on a diffrent scene then the one with the AudioManager, I hear nothing.
    I can see the created audio source with my clip inside, but I can't hear anything.

    And I'm still wating for SFX support :p
     
  35. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Hmm, that's odd because I throw a null ref exception if the clip isn't found.. Here's the implementation, it works for me.

    Code (csharp):
    1.  
    2.     /// <summary>
    3.     /// Plays a sound matching the given name.
    4.     /// </summary>
    5.     /// <param name="name">
    6.     /// The name of the audio clip.
    7.     /// </param>
    8.     /// <param name="volume">
    9.     /// The volume factor, from 0 to 1.
    10.     /// </param>
    11.     /// <param name="position">
    12.     /// Where to place the audio source.
    13.     /// </param>
    14.     /// <param name="parent">
    15.     /// The used audio source will be a child of this transform.
    16.     /// </param>
    17.     public static void PlaySound(string name, float? volume, Vector3? position, Transform parent)
    18.     {
    19.         // Find an audio item matching the given name
    20.         AudioItem item = instance.AudioItems.FirstOrDefault(a => a.Name == name);
    21.  
    22.         if (item == null)
    23.         {
    24.             throw new NullReferenceException("No audio items matched the given name");
    25.         }
    26.  
    27.         // Play the sound
    28.         instance.PlaySound(item, volume, position, parent);
    29.     }
    30.  
    Not sure about the volume problem though, sounds wierd.

    Try the new version, added SFX support :)
    https://dl.dropbox.com/u/4375689/Permanent/AudioManagerLatest.unitypackage
     
  36. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    I will be happy if you could export a 3.5 version.
     
  37. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    Another thing I just noticed.
    Plugins are not supported for webplayer.
    You might wanna think about a way to make it supported for webplayer as well.
     
  38. PhilllChabbb

    PhilllChabbb

    Joined:
    Sep 16, 2013
    Posts:
    8
    I must say a big THANK YOU Mathias for this excellent plugin. It took me 3 seconds to set up and get it to work...! Wow. Being able to play sounds with one line of code is quite elegant. :D

    I am also having a problem with building the game for the webplayer. I get this error :

    It is a bit strange, since when I test in Unity, everything works flawlessly. I am using Unity 4.1.3 for now (will update once my little game is done). Could this be due that my Unity isn't up-to-date enough? FYI, I'm using an empty scene with a cube, one script to play the audio and a couple of audio assets.

    Once again, kudos for your effort to share a wonderful tool. :)
     
    Last edited: Sep 16, 2013
  39. PhilllChabbb

    PhilllChabbb

    Joined:
    Sep 16, 2013
    Posts:
    8
    I've managed to build for the WebPlayer and PC with this very simple edit. :)


    UNITY_EDITOR functions don't get compiled into the game build. That was the cause of the warning earlier. For anyone curious and wants more info - Platform Dependent Compilation

    To be able to build, we simply have to let Unity know what not to be included in the build. You only need to edit two of the scripts [ AudioWindow.cs ] and [ AudioManagerSettings.cs ].

    For [ AudioWindow.cs ] :

    Code (csharp):
    1. #if UNITY_EDITOR //Add this line at the top of the script
    2.  
    3. using System.IO;
    4. using UnityEngine;
    5. using UnityEditor;
    6.  
    7. ...(rest of the code)...
    8.  
    9. #endif   //Add this line at the bottom of the script
    10.  


    For [ AudioManagerSettings.cs ] we simply add #if UNITY_EDITOR and #endif to isolate the using UnityEditor; command.

    Code (csharp):
    1. #if UNITY_EDITOR //Add this line here
    2. using UnityEditor;
    3. #endif    //Add this line here
    4. using UnityEngine;
    5.  
    6. [System.Serializable]
    7. public class AudioManagerSettings
    8. {
    9.  
    10.     public bool IsAllMuted;
    11.     public bool IsMusicMuted;
    12.    
    13.     ...(rest of the code)...
    14.  
    15. }
    16.  
    17.  
    Hope this can help anyone who might have this problem too. Once again, awesome sound library...!! :)
     
  40. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Hey thanks a lot, I'm glad you like it despite the bugs :p

    I stopped working on it because I got hired for a full time position as a programmer, so it was hard to find the time.
    I'll see if I can find the time for it one of the upcoming weekends since there's actually interest for it. Also I hate having half done projects lying around..

    I will email you the first working version, as soon as I've looked at it (probably in 2 weeks or so) :)
     
  41. PhilllChabbb

    PhilllChabbb

    Joined:
    Sep 16, 2013
    Posts:
    8
    Hey sounds cool! :D 'Grats on the job.

    If it feels right and you are up to it I'd love to give you a hand. ;)
     
  42. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
  43. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    I fixed this on GitHub now, it'll be in the next unity package :)

    https://github.com/mathiassoeholm/AudioManagerExtension/commit/31dbe43f62f2d98080311381579875b97d272ca0