Code Monkey home page Code Monkey logo

unity-audio-manager's Introduction

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);
	}
}

unity-audio-manager's People

Contributors

jetskipenguin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.