Unclaimed Package Is this your package? Claim it to unlock full analytics and manage your listing.
Claim This Package

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

Style
Preview
pkglnk installs badge
## 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
```

[![pkglnk](https://www.pkglnk.dev/badge/simple-audio-manager.svg?style=pkglnk)](https://www.pkglnk.dev/pkg/simple-audio-manager)

README

Simple-Audio-Manager-Unity3D

A simple-to-use audio manager for Unity

openupm

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

  1. Install the OpenUPM CLI
  2. 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

  1. Create a new audio mixer asset (right click in the Unity project window -> Create -> Audio Mixer)
  2. Open the Audio Mixer window (Window -> Audio -> Audio Mixer)
  3. In the Audio Mixer window, click the "+"-icon next to the Groups tab to add a new group under the Master group, name the group Background. Add two more groups in the same way with the names Effects and UI
Screenshot of Unity Audio Mixer window 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 Screenshot of Unity Hierarchy window 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" Screenshot of Unity Audio Mixer window with exposed parameter tab

Setting up the Audio Manager

  1. Create a new empty game object and add the AudioManager script to it
  2. 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:

  1. Open the menu Tools -> Simple Audio Manager -> Settings
  2. Disable "Enable Singleton" (this will remove the default way of accessing the instance via AudioManager.Instance)
  3. (Optional) If you also want to use the AudioPlayer component 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:

Comments

No comments yet. Be the first!