/Unity-Simple-Audio-Manager

A simple audio manager for Unity with pooling

Primary LanguageC#

Unity Simple Audio Manager

Summary

This is a simple Audio Manager for Unity Engine with pooling. It was thought to be used in a small or medium sized project.

This Unity package was created in Unity Engine v. 2021.3.14f1. It should be used in another version without any error.

Installion

  1. Clone the repository to any place in your computer. There is a Unity Package file in Unity-Simple-Audio-Manager\Assets\AudioManagerByOzzysDen\AudioManagerByOzzysDen.unitypackage.
  2. Open your Unity project or create a new one. Go to Assets/Import Package/Custom Package on the top navigation menu and import AudioManagerByOzzysDen.unitypackage to your project.
  3. Package is in your project now.

Usage

  1. In the Assets folder you'll find a Prefabs folder (AudioManagerByOzzysDen\Prefabs). Simply drag AudioManager prefab to your Hierarchy on your scene.
  2. If you want to use same AudioManager in all of your scenes tick DontDestroy on the prefab. This will make the prefab Singleton pattern. If you want to make it a Singleton I recommend putting the AudioManager in your starting scene only.
  3. You'll find another prefab in the same directory called AudioPlayer. This prefab has the AudioSource component, which is responsible for playing any Audio in your game. And it is pooled to save memory and resources. This means an instance of AudioPlayer will be created anytime there is no any empty (not playing) AudioPlayer prefab exists under AudioManager. Once a AudioPlayer is created it won't be destroyed, any of them will be used repeatedly.
  4. There is AudioFiles ScriptableObject called Audio Data in Assets\AudioManagerByOzzysDen directory. Here you have to set your audio clip files in the list.
  5. This asset was intended to play Sound FX but you also use it to play game music as well. You just have to tick isLoop to play the game music in a loop. There will be a pseudo random Music Player I will share in the future. I'll pass the link here as soon as it is ready.

    AudioData_img

  6. Finally, there is a PoolSize variable on the AudioManager. You can set the initial pool size according to your project's scale. Then on the start manager will create defined number of AudioPlayer prefab under AudioManager in the Hierarchy (default is 5).

    AudioManager_Img