Giter VIP home page Giter VIP logo

u3d-audiomixer's Introduction

U3D-AudioMixer

AudioMixer is a Unity script written in C# that attempts to implement an audio mixer with channels. In Unity, the most typical way to control audio was though priorities, which could be set in a sound's properties. There was never a built-in system to relay audio to a specific channel.

AudioMixer implements audio channeling via a script with the same name that is attached to a GameObject. Entities in your game that need to play a sound (or music) can call AudioMixer to play a sound in a specified channel of your choice. Notice that this is not a Unity extension and thus does not make audio channels a built-in feature in Unity.

AudioMixer was made for music and 2D sounds in mind. This is not recommended for 3D sounds. 3D sounds require a location, which would be too cumbersome to implement in AudioMixer.

You can read my reason for start this here.

Demo Scene

The demo scene ( AM_TestScene.unity ) features an array of keys on the screen that play sound in multiple channels. By default there are 8 channels and 2 sounds to test per channel for a total of 16 sounds.

You should be able to play audio from multiple channels at the same time. If you play a sound for channel X and then play another sound that is also for channel X, the first invoked sound stops immediatly and the second sound plays at that channel.

Channel 1 plays looping music. The rest are sound effects or jingles.

The demo project requires Unity 4.2 or greater.

The functionality of the keys can be changed by clicking on a key in the scene and adjusting the inspector.

demoScreen

How to Use

Put the AudioMixer.cs script somewhere in your /Assets folder. Then place the prefab AudioMixerObject.prefab into a folder called /Resources. This folder must be somewhere in the /Assets folder, so for example: /Assets/Resources/AudioMixerObject.prefab.

The next step in important if you're placing AudioMixer into a new Unity project. Go to the AudioMixerObject prefab and in the inspector, make sure the AudioMixer script is attatched. It most likely will not be attatched if you took AudioMixer assets into a new project.

Whenever you want to play a sound in code, you can call the AudioMixer like this:

using UnityEngine;
using System.Collections;

public class SoundPlayerScriptExample : Monobehavior
{
    public AudioClip soundEffect;
    public int audioMixerChannel = 1;
    public AudioMixerChannelTypes audioType = AudioMixerChannelTypes.Sound;
    
    void Start()
    {
        AudioMixer.Play(audioMixerChannel, soundEffect, audioType);
    }
}

Notice that this is a static call. An instance of the AudioMixerObject prefab will be created when needed, so you don't have to.

Be default, AudioMixer sets up 8 channels (which are actually AudioSources). If you would like more channels, change the constant NUM_OF_CHANNELS, which can be found right after AudioMixer's class declaration. Notice that changing this constant will NOT adjust anything in the demo scene.

Documentation

For documentation, please refer to the wiki.

u3d-audiomixer's People

Watchers

 avatar  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.