Adventure Creator  1.79.1
An adventure game toolkit for Unity, by Chris Burton, ICEBOX Studios 2013-2022
AC.Soundtrack Class Reference
Inheritance diagram for AC.Soundtrack:
AC.Sound AC.Ambience AC.Music

Classes

struct  QueuedSoundtrack
 
struct  SoundtrackSample
 

Public Member Functions

override void _Update ()
 
float Play (int trackID, bool loop, bool isQueued, float fadeTime, bool resumeIfPlayedBefore=false, int newTrackTimeSamples=0, float loopingOverlapTime=0f)
 Plays a new soundtrack More...
 
float Crossfade (int trackID, bool loop, bool isQueued, float fadeTime, bool resumeIfPlayedBefore=false, int newTrackTimeSamples=0, float loopingOverlapTime=0f)
 Crossfade a new soundtrack More...
 
float ResumeLastQueue (float fadeTime, bool playFromStart)
 Resumes the last-played soundtrack queue More...
 
float StopAll (float fadeTime, bool storeCurrentIndex=true)
 Stops the currently-playing track, and cancels all those in the queue. More...
 
virtual MainData SaveMainData (MainData mainData)
 Updates a MainData class with its own variables that need saving. More...
 
virtual void LoadMainData (MainData mainData)
 Updates its own variables from a MainData class. More...
 
int GetCurrentTrackID ()
 
void SyncTrackWithCurrent (int trackID, int sampleOffset=0)
 Sets the recorded 'time sample' of a track to match the currently-playing audio. This is useful if you want to blend into a new track at the same position as the current one, via the 'resumeIfPlayedBefore' option in the Play function. More...
 
- Public Member Functions inherited from AC.Sound
void Interact ()
 
void FadeIn (float _fadeTime, bool loop, int _timeSamples=0)
 Fades in the AudioSource's current AudioClip, after which it continues to play. More...
 
void FadeOut (float _fadeTime)
 Fades out the AudioSource's current AudioClip, after which it stops. More...
 
bool IsFadingOut ()
 Checks if the AudioSource's AudioClip is being faded out. More...
 
void Play ()
 
void Play (bool loop)
 Plays the AudioSource's current AudioClip. More...
 
void Play (AudioClip clip, bool loop, int _timeSamples=0)
 Plays an AudioClip. More...
 
void PlayAtPoint (bool loop, int samplePoint)
 Plays the AudioSource's current AudioClip from a set point. More...
 
void SetMaxVolume ()
 
void SetVolume (float volume)
 Sets the volume, but takes relativeVolume into account as well. More...
 
void ChangeRelativeVolume (float newRelativeVolume, float changeTime=0f)
 Changes the relativeVolume value. More...
 
void Stop ()
 
bool IsFading ()
 Checks if the sound is fading in or out. More...
 
bool IsPlaying ()
 Checks if sound is playing. More...
 
bool IsPlaying (AudioClip clip)
 Checks if a particular AudioClip is playing. More...
 
void TryDestroy ()
 
void EndOld (SoundType _soundType, Sound ignoreSound)
 Fades out all sounds of a particular type being played. More...
 
SoundData GetSaveData (SoundData soundData)
 Updates a SoundData class with its own variables that need saving. More...
 
void LoadData (SoundData soundData)
 Updates its own variables from a SoundData class. More...
 

Protected Member Functions

void Awake ()
 
override void OnEnable ()
 
override void OnDisable ()
 
bool IsCrossfading ()
 
void CreateNewCrossfade (float fadeTime)
 
void EndOthers ()
 
virtual bool EndsOthers ()
 
float HandlePlay (int trackID, bool loop, bool isQueued, float fadeTime, bool isCrossfade, bool resumeIfPlayedBefore, int newTrackTimeSamples=0, float loopingOverlapTime=0f)
 
float ForceStopAll (float fadeTime, bool storeCurrentIndex=true)
 
void ClearSoundtrackQueue ()
 
void FadeOutThenIn (MusicStorage musicStorage, float fadeTime, bool loop, bool resumeIfPlayedBefore, int newTrackTimeSamples)
 
void AfterDelay ()
 
void Resume (int _timeSamples, float fadeTime=0f)
 
void HandleFadeIn (float _fadeTime, bool loop, int _timeSamples)
 
string CreateTimesampleString ()
 
string CreateLastSoundtrackString ()
 
string CreateOldTimesampleString ()
 
void LoadMainData (int _timeSamples, string _oldTimeSamples, int _lastTimeSamples, string _lastQueueData, string _queueData)
 
MusicStorage GetSoundtrack (int ID)
 
void SetRelativeVolume (float _relativeVolume)
 
void StoreSoundtrackSampleByIndex (int index)
 
int GetSoundtrackSample (int trackID)
 
void ClearSoundtrackSample (int trackID)
 
void SetSoundtrackSample (int trackID, int timeSample)
 
- Protected Member Functions inherited from AC.Sound
void Start ()
 
void OnEnterGameState (GameState gameState)
 
void OnInitialiseScene ()
 
void OnChangeVolume (SoundType _soundType, float newVolume)
 
void SetSmoothVolume ()
 
void SnapSmoothVolume ()
 
void SetFinalVolume ()
 
void TurnOn ()
 
void TurnOff ()
 
void Kill ()
 

Protected Attributes

List< QueuedSoundtrackqueuedSoundtrack = new List<QueuedSoundtrack>()
 
List< MusicCrossfadecrossfades = new List<MusicCrossfade>()
 
List< QueuedSoundtracklastQueuedSoundtrack = new List<QueuedSoundtrack>()
 
List< SoundtrackSampleoldSoundtrackSamples = new List<SoundtrackSample>()
 
int lastTimeSamples
 
float delayTime
 
int delayAudioID = -1
 
float delayFadeTime
 
bool delayLoop
 
bool delayResumeIfPlayedBefore
 
int delayNewTrackTimeSamples
 
bool wasPlayingLastFrame
 
- Protected Attributes inherited from AC.Sound
float maxVolume = 1f
 
float smoothVolume = 1f
 
float smoothUpdateSpeed = 20f
 
float fadeTime
 
float originalFadeTime
 
FadeType fadeType
 
Options options
 
AudioSource _audioSource
 
float otherVolume = 1f
 
float originalRelativeVolume
 
float targetRelativeVolume
 
float relativeChangeTime
 
float originalRelativeChangeTime
 
bool gameIsPaused
 

Properties

virtual List< MusicStorageStorages [get]
 
int LastTimeSamples [get]
 
virtual bool IsMusic [get]
 
virtual float LoadFadeTime [get]
 
virtual bool CrossfadeWhenLoading [get]
 
virtual bool RestartTrackWhenLoading [get]
 
- Properties inherited from AC.Sound
AudioSource audioSource [get]
 

Additional Inherited Members

- Public Attributes inherited from AC.Sound
SoundType soundType
 
bool playWhilePaused = false
 
float relativeVolume = 1f
 
bool surviveSceneChange = false
 

Member Function Documentation

◆ _Update()

override void AC.Soundtrack._Update ( )
virtual

Updates the AudioSource's volume. This is called every frame by StateHandler.

Reimplemented from AC.Sound.

◆ Crossfade()

float AC.Soundtrack.Crossfade ( int  trackID,
bool  loop,
bool  isQueued,
float  fadeTime,
bool  resumeIfPlayedBefore = false,
int  newTrackTimeSamples = 0,
float  loopingOverlapTime = 0f 
)

Crossfade a new soundtrack

Parameters
trackIDThe ID number of the track, as generated by the MusicStorage class that stores the AudioClip
Parameters
loopIf True, the new track will be looped
isQueuedIf True, the track will be queued until the current track has finished playing
fadeTimeThe crossfade duration, in seconds
resumeIfPlayedBeforeIf True, and the track has been both played before and stopped before it finished, the track will be resumed
newTrackTimeSamplesThe timeSamples to play the new track from, if not overridden with resumeIfPlayedBefore
<param name "loopingOverlapTime">The time that the track will overlap itself when looping
Returns
The duration, in seconds, for the new track to begin playing and the previous track transition to end</reuturns>

◆ GetCurrentTrackID()

int AC.Soundtrack.GetCurrentTrackID ( )

The ID number of the currently-playing track.

◆ LoadMainData()

virtual void AC.Soundtrack.LoadMainData ( MainData  mainData)
virtual

Updates its own variables from a MainData class.

Parameters
mainDataThe MainData class to load from

Reimplemented in AC.Music, and AC.Ambience.

◆ Play()

float AC.Soundtrack.Play ( int  trackID,
bool  loop,
bool  isQueued,
float  fadeTime,
bool  resumeIfPlayedBefore = false,
int  newTrackTimeSamples = 0,
float  loopingOverlapTime = 0f 
)

Plays a new soundtrack

Parameters
trackIDThe ID number of the track, as generated by the MusicStorage class that stores the AudioClip
Parameters
loopIf True, the new track will be looped
isQueuedIf True, the track will be queued until the current track has finished playing
fadeTimeThe fade-in duration, in seconds
resumeIfPlayedBeforeIf True, and the track has been both played before and stopped before it finished, the track will be resumed
newTrackTimeSamplesThe timeSamples to play the new track from, if not overridden with resumeIfPlayedBefore
<param name "loopingOverlapTime">The time that the track will overlap itself when looping
Returns
The duration, in seconds, for the new track to begin playing and the previous track transition to end</reuturns>

◆ ResumeLastQueue()

float AC.Soundtrack.ResumeLastQueue ( float  fadeTime,
bool  playFromStart 
)

Resumes the last-played soundtrack queue

Parameters
fadeTimeThe fade-in time in seconds, if greater than zero
playFromStartIf True, the track will play from the beginning
Returns
The duration, in seconds, for the new track to begin playing and the previous track transition to end</reuturns>

◆ SaveMainData()

virtual MainData AC.Soundtrack.SaveMainData ( MainData  mainData)
virtual

Updates a MainData class with its own variables that need saving.

Parameters
mainDataThe original MainData class
Returns
The updated MainData class

Reimplemented in AC.Ambience, and AC.Music.

◆ StopAll()

float AC.Soundtrack.StopAll ( float  fadeTime,
bool  storeCurrentIndex = true 
)

Stops the currently-playing track, and cancels all those in the queue.

Parameters
fadeTimeThe time over which to stop the track
storeCurrentIndexIf the current time index of the track will be stored so that it can be resumed later
Returns
The fade time necessary to stop the track

◆ SyncTrackWithCurrent()

void AC.Soundtrack.SyncTrackWithCurrent ( int  trackID,
int  sampleOffset = 0 
)

Sets the recorded 'time sample' of a track to match the currently-playing audio. This is useful if you want to blend into a new track at the same position as the current one, via the 'resumeIfPlayedBefore' option in the Play function.

Parameters
trackIDThe ID of the track to sync with the currently-playing audio
sampleOffsetAn offset value to apply to the track, on top of the current audio's timeSamples