Simple Audio Manager
A simple to use audio manager for Unity
com.iristrummer.simple-audio-manager Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/simple-audio-manager.git?path=Audio Manager/Assets/SimpleAudioManager README Markdown
Copy this to your project's README.md
## Installation
Add **Simple Audio Manager** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/simple-audio-manager.git?path=Audio%20Manager%2FAssets%2FSimpleAudioManager
```
[](https://www.pkglnk.dev/pkg/simple-audio-manager)README
Simple-Audio-Manager-Unity3D
A simple-to-use audio manager for Unity
Usage
// Play an audio clip once
AudioManager.Instance.PlayOnce(audioClip, SoundType.Effects);
// Play an audio clip once at a specific position
AudioManager.Instance.PlayAudioClipAtPosition(audioClip, new Vector3(1, 2, 3), SoundType.Effects);
// Play a looping audio clip
AudioManager.Instance.PlayOnLoop(audioClip, SoundType.Background);
// Set the volume for groups
AudioManager.Instance.SetVolume(0.5f, SoundType.Effects);
// Fade a group's volume over time
AudioManager.Instance.FadeGroupVolumeTo(0f, 3f, SoundType.Master);
You can use the AudioPlayer component to play audio clips directly in the scene or for setting up background music.
If you need to configure different volumes for different audio clips, consider using the serializable SoundEffect helper struct, which contains an audio clip and a volume.
Installation
The package can be installed using OpenUPM
- Install the OpenUPM CLI
- Run the following command in the command line in your project directory:
openupm add com.iristrummer.simple-audio-manager
To take a look at the demo scene, clone the repository, open the Unity project under AudioManager/ and start the Demo scene in Assets/Scenes/DemoScene.unity.
Getting Started
Setting up the Audio Mixer
- Create a new audio mixer asset (right click in the Unity project window -> Create -> Audio Mixer)
- Open the Audio Mixer window (Window -> Audio -> Audio Mixer)
- In the Audio Mixer window, click the "+"-icon next to the Groups tab to add a new group under the
Mastergroup, name the groupBackground. Add two more groups in the same way with the namesEffectsandUI
4. Select the `Master` group. In the hierarchy window, right click the volume field and select "Expose 'Volume (of Master)' to script". Repeat this procedure for the three groups you created in the previous step
5. In the audio mixer on the top right click on the "Exposed Parameters" button. Rename each parameter to the group name and append "Volume", for example "MasterVolume"
Setting up the Audio Manager
- Create a new empty game object and add the AudioManager script to it
- In the Audio Mixer field of the script, add the Audio Mixer asset you just created
Dependency Injection Frameworks
If you plan on using your own dependency injection framework follow the instructions below.
Without any modification you access the instance of the AudioManager via the singleton AudioManager.Instance. If you, however, want to use a dependency injection framework e.g. Zenject to access the instance you need to do the following:
- Open the menu Tools -> Simple Audio Manager -> Settings
- Disable "Enable Singleton" (this will remove the default way of accessing the instance via
AudioManager.Instance) - (Optional) If you also want to use the
AudioPlayercomponent you need to implement it using your desired dependency injection framework (see below for an example on how to do this with Zenject)
// Example AudioPlayer implementation using Zenject to get the instance (binding is set up in e.g. project context)
public class AudioPlayer : AudioPlayerBase
{
[Inject] private readonly AudioManager audioManager;
protected override AudioManager AudioManager => audioManager;
}
Acknowledgements
Ressources for the Demo are provided by:
- "Unity-UI-Rounded-Corners” by Kir Evdokimov (https://github.com/kirevdokimov). Available for use under the MIT license, at https://github.com/kirevdokimov/Unity-UI-Rounded-Corners
- "Sonus Tres" © Sandro Figo (https://soundcloud.com/sandrofigo/sonus-tres)
- Icons and Sound Effects by Kenney (https://kenney.nl/). Available for use under the Creative Commons CC0 License (https://creativecommons.org/publicdomain/zero/1.0/)
No comments yet. Be the first!