jetskipenguin / unity-audio-manager

Reusable Audio Manager Package

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unity-audio-manager

Reusable Audio Manager Package

Code and Ideas were borrowed from Unity's Open Project

https://github.com/UnityTechnologies/open-project-1

Features

  • Create reusable audio configurations (pitch, volume, reverb, spread, etc)
  • Create audio cues with one or more audio clips that can play sequentially or randomly
  • Audio Source pool can help save memory when lots of audio sources are present.
  • Ability to instantiate audio cues from anywhere without needing a direct reference to the AudioManager

Current Limitations

  • You cannot change the volume of audio cue while it's playing
  • All audio cues play on the same mixer on the same group
  • Not able to change group volume

Installation

  • Click Window -> Package Manager

  • In top left click the plus button, then "add package from git url"

  • Input the git url.


This package has a dependency on the following package:

https://github.com/Thundernerd/Unity3D-SerializableInterface

This package can be installed via the same method.

Scripts

Various examples can be found in:

AudioManager/Samples/

Audio Cue Scriptable Object

One audio cue represents a series of one or more audio clips that can be played sequentially or randomly

These audio cues can be played via AudioEventChannel which will interface with the audiomanager.

image

Audio Configuration

An audio configuration is a series of audio properties that can be reused among different audio cues.
(i.e music configuration, shotgun sfx configuration, etc)

image

Audio Source Pool

The audio source pool creates a set amount (initial size) of audio emitters that are available for the audio manager to assign audio clips too, if the pool runs out of space, new audio emitters are instantiated.

The audio source pool can help save memory when there are lots of audio clips playing at a time.

image

AudioCueEventChannel

The audio event channel(s) are an intermediary between the script wanting to start an audio cue and the audio manager.

Each audio event channel represents a different purpose behind the audio cue.

These channels help to decouple the Audio Manager and script wanting to start an audio cue.

Audio Manager

The audio manager listens to requests to start audio cues on AudioCueEventChannels and requests audio emitters from the AudioSourcePool to actually instantiate the sound clips.

image

Playing a sound

using UnityEngine;

public class PlayingSoundExample : MonoBehaviour
{
	[SerializeField] private AudioCueSO _musicSO = default;
	[SerializeField] private AudioConfigurationSO _audioConfig = default;

    [SerializeField] private AudioCueEventChannelSO _musicEventChannel = default;

	private int _musicKey;

	private void Start()
	{
		PlayMusic();
	}

	private void Update()
	{
		if (Input.GetKeyDown(KeyCode.M))
		{
      			// stops audio cue
			_musicEventChannel.RaiseStopEvent(_musicKey);
		}
	}

	private void PlayMusic()
	{
    		// plays audio cue
		_musicKey = _musicEventChannel.RaisePlayEvent(_musicSO, _audioConfig, transform.position);
	}
}

About

Reusable Audio Manager Package

License:MIT License


Languages

Language:C# 100.0%