Skip to content

Instantly share code, notes, and snippets.

@altunsercan
Created September 1, 2016 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altunsercan/37f9ce5fe5fba2d93762dce6f7005df6 to your computer and use it in GitHub Desktop.
Save altunsercan/37f9ce5fe5fba2d93762dce6f7005df6 to your computer and use it in GitHub Desktop.
Following gist is created for a blog post. If you want to read the details you can read the blog at:
http://sercanaltun.com/blog/fungus-game-sound-music-setup
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEngine;
using UnityEngine.Audio;
namespace Fungus
{
/// <summary>
/// Sets parameter value for target AudioMixer.
/// </summary>
[CommandInfo("Audio",
"Set Mixer Parameter",
"Sets parameter value for target AudioMixer.")]
[AddComponentMenu("")]
public class SetMixerParameter : Command
{
[Tooltip("Target AudioMixer")]
[SerializeField]
protected AudioMixer mixer = null;
[Tooltip("Name of exposed parameter")]
[SerializeField]
protected string parameterName = "";
[Tooltip("New float value of the parameter")]
[SerializeField] protected float parameterValue = 0f;
public override void OnEnter()
{
mixer.SetFloat(parameterName, parameterValue);
Continue();
}
public override string GetSummary()
{
if (mixer == null)
{
return "No target mixer selected";
}
return "Set " + parameterValue + " of " + mixer.name + " to " + parameterValue;
}
public override Color GetButtonColor()
{
return new Color32(242, 209, 176, 255);
}
}
}
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEngine;
using UnityEngine.Audio;
namespace Fungus
{
/// <summary>
/// Transitions mixer values to selected snapshot.
/// </summary>
[CommandInfo("Audio",
"Transition to Mixer Snapshot",
"Transition mixer values to selected snapshot.")]
[AddComponentMenu("")]
public class TransitionToMixerSnapshot : Command
{
[Tooltip("Target AudioMixer")]
[SerializeField]
protected AudioMixer mixer = null;
[Tooltip("Name of snapshot")]
[SerializeField]
protected string snapshotName = "";
[Range(0,60)]
[Tooltip("Transition time")]
[SerializeField] protected float transitionTime = 1f;
public override void OnEnter()
{
AudioMixerSnapshot snapshot = mixer.FindSnapshot(snapshotName);
if (snapshot == null)
{
Continue();
return;
}
snapshot.TransitionTo(transitionTime);
}
public override string GetSummary()
{
if (mixer == null)
{
return "No target mixer selected";
}
return "Transition to " + snapshotName + " of " + mixer.name + " in " + transitionTime + "seconds";
}
public override Color GetButtonColor()
{
return new Color32(242, 209, 176, 255);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment