Skip to content

Music Controller for smooth sound transitions

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

TheStami/Unity-MusicFlowController

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Music Flow Controller 🎵

Simple Music Controller for Unity providing smooth audio transitions without gain loss and desync issues

Unity Version Version License

📖 Description

Unity Music Flow Controller is an simple music control system for Unity that provides smooth transitions between musical tracks without unwanted volume drop. The default "Equal Power Crossfade" mode maintain consistent volume during track changes.

🚀 Installation

Method 1: Package Manager (Unity 2019.3+)

  1. Open Window > Package Manager in Unity
  2. Click + and select Add package from git URL
  3. Paste: https://github.com/TheStami/Unity-MusicFlowController.git

📚 Quick Start

1. Basic Setup

Add MusicController component to object.

screenshot

You can add as many music tracks as you want. Name is optional. Add AutioClip to it.

Volume is is the target volume after playing the song, you can control maximum volume here or add Audio Mixer Group.

2. Playback Control

When you got component (GetComponent<MusicController>()), you can control tracks by index or by giving MusicTrack list.

// Play single track
musicController.PlayTrack(0); // Play first track

// Play with stop others
musicController.PlayTrack(1, true); // Play second, stop all others

// Stop all tracks
musicController.StopAllTracks();

// Control multiple tracks simultaneously
musicController.PlayTracks(
    new int[] { 0, 2 },    // Tracks to start
    new int[] { 1 }        // Tracks to stop
);

List<MusicTrack> allTracks = musicController.MusicTracks;
musicController.PlayTracks(
    allTracks.Where(x => x.name == "happy").ToArray();
    allTracks.Where(x => x.name == "sad").ToArray();
);

⚙️ Configuration

MusicController Parameters

Parameter Type Description Default Value
musicTracks List List of music tracks -
volume float (0-1) Destination volume 1.0
transitionSpeed float Transition speed 2.0
transitionMode MusicTransitionType Transition type EqualPowerCrossfade
audioMixerGroup AudioMixerGroup Audio Mixer Group -

Transition Types

1. Equal Power Crossfade (Default)

  • Benefits: Maintains consistent volume during transitions
  • Algorithm: Uses sine/cosine functions for smooth transitions

2. Linear

  • Benefits: Simple, predictable transitions, with audible transitions between tracks
  • Algorithm: Linear volume interpolation

3. Lerp

  • Benefits: Smooth transitions with acceleration
  • Algorithm: Lerp interpolation with curve

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Music Controller for smooth sound transitions

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages