Class MusicPlayer
- Namespace
- TDMaker.Unity.View
- Assembly
- TDMaker.Unity.dll
Plays background music: a menu loop while no battle is shown, the level's battle loop (music, falling back to this component's defaults), an optional intense loop from configurable waves (last wave, waves flagged bossWave, or from a wave number) and victory / defeat stingers that stop or duck the loop. Changes crossfade between two pooled AudioSources; a third plays stingers. Volume = track × TDGameSettings Music × Master, routed to the Music mixer group when one is set. No allocation per frame; every clip is optional (an empty slot is silent).
[AddComponentMenu("2D Tower Defense Maker/Music Player")]
public sealed class MusicPlayer : MonoBehaviour
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourMusicPlayer
- Inherited Members
-
MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.GetComponent<T>()Component.TryGetComponent<T>(out T)Component.GetComponentInChildren<T>()Component.GetComponentsInChildren<T>()Component.GetComponentInParent<T>()Component.GetComponentsInParent<T>()Component.GetComponents<T>()Component.GetComponentIndex()Component.CompareTag(TagHandle)Component.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.GetEntityId()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.ToString()Object.nameObject.hideFlags
Constructors
MusicPlayer()
public MusicPlayer()
Properties
BattleRoot
The object whose visibility selects battle music (null: battle music whenever a simulation runs).
public GameObject BattleRoot { get; set; }
Property Value
- GameObject
Crossfade
Crossfade time in real seconds.
public float Crossfade { get; set; }
Property Value
Current
What is playing.
public MusicPlayer.State Current { get; }
Property Value
CurrentClip
The clip of the current loop, or null.
public AudioClip CurrentClip { get; }
Property Value
- AudioClip
IsPlaying
Whether a loop is sounding.
public bool IsPlaying { get; }
Property Value
IsStingerPlaying
Whether a stinger is sounding.
public bool IsStingerPlaying { get; }
Property Value
MenuMusic
The default menu loop.
public AudioClip MenuMusic { get; set; }
Property Value
- AudioClip
StingerClip
The stinger clip last started, or null.
public AudioClip StingerClip { get; }
Property Value
- AudioClip
Methods
Configure(SimulationRunner, GameObject, AudioClip, AudioClip, AudioClip, AudioClip, AudioClip)
Assigns the runner, the optional battle root and the default clips; call before enabling.
public void Configure(SimulationRunner source, GameObject battle = null, AudioClip menu = null, AudioClip battleLoop = null, AudioClip intenseLoop = null, AudioClip victory = null, AudioClip defeat = null)
Parameters
sourceSimulationRunnerbattleGameObjectmenuAudioClipbattleLoopAudioClipintenseLoopAudioClipvictoryAudioClipdefeatAudioClip
CrossfadeTo(AudioClip, float)
Crossfades to clip at trackVolume (null fades out). The same clip already playing
only changes its volume.
public void CrossfadeTo(AudioClip clip, float trackVolume)
Parameters
clipAudioCliptrackVolumefloat
IsIntenseWave(int)
Whether wave wave (one-based) switches the current level to its intense loop.
public bool IsIntenseWave(int wave)
Parameters
waveint
Returns
PlayBattle(bool)
Crossfades to the level's battle loop, or its intense loop (falls back to the battle loop when there is none).
public void PlayBattle(bool intense)
Parameters
intensebool
PlayMenu()
Crossfades to the menu loop (silence when there is none).
public void PlayMenu()
PlayOutcome(bool)
Plays the victory or defeat stinger and stops or ducks the loop (once per run).
public void PlayOutcome(bool victory)
Parameters
victorybool
Stop()
Fades the loop out.
public void Stop()