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

Public Member Functions

virtual void _Update ()
 
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...
 

Public Attributes

SoundType soundType
 
bool playWhilePaused = false
 
float relativeVolume = 1f
 
bool surviveSceneChange = false
 

Protected Member Functions

virtual void OnEnable ()
 
void Start ()
 
virtual void OnDisable ()
 
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

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

AudioSource audioSource [get]
 

Detailed Description

This component controls the volume of the AudioSource component it is attached beside, according to the volume levels set within OptionsData by the player. It also allows for AudioSources to be controlled using Actions.

Member Function Documentation

◆ _Update()

virtual void AC.Sound._Update ( )
virtual

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

Reimplemented in AC.Soundtrack.

◆ ChangeRelativeVolume()

void AC.Sound.ChangeRelativeVolume ( float  newRelativeVolume,
float  changeTime = 0f 
)

Changes the relativeVolume value.

Parameters
newRelativeVolumeThe new value for relativeVolume
changeTimeThe time, in seconds, to make the change in

◆ EndOld()

void AC.Sound.EndOld ( SoundType  _soundType,
Sound  ignoreSound 
)

Fades out all sounds of a particular type being played.

Parameters
soundTypeIf the soundType matches this, the sound will end
ignoreSoundThe Sound object to not affect

◆ FadeIn()

void AC.Sound.FadeIn ( float  _fadeTime,
bool  loop,
int  _timeSamples = 0 
)

Fades in the AudioSource's current AudioClip, after which it continues to play.

Parameters
_fadeTimeThe fade duration, in seconds
loopIf True, then the AudioClip will loop
_timeSamplesThe timeSamples to play from

◆ FadeOut()

void AC.Sound.FadeOut ( float  _fadeTime)

Fades out the AudioSource's current AudioClip, after which it stops.

Parameters
_fadeTimeThe fade duration, in seconds

◆ GetSaveData()

SoundData AC.Sound.GetSaveData ( SoundData  soundData)

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

Parameters
soundDataThe original SoundData class
Returns
The updated SoundData class

◆ Interact()

void AC.Sound.Interact ( )

Plays the AudioSource's current AudioClip.

◆ IsFading()

bool AC.Sound.IsFading ( )

Checks if the sound is fading in or out.

Returns
True if the sound is fading in or out

◆ IsFadingOut()

bool AC.Sound.IsFadingOut ( )

Checks if the AudioSource's AudioClip is being faded out.

Returns
True if the AudioSource's AudioClip is being faded out

◆ IsPlaying() [1/2]

bool AC.Sound.IsPlaying ( )

Checks if sound is playing.

Returns
True if sound is playing

◆ IsPlaying() [2/2]

bool AC.Sound.IsPlaying ( AudioClip  clip)

Checks if a particular AudioClip is playing.

Parameters
clipThe AudioClip to check for
Returns
True if the AudioClip is playing

◆ LoadData()

void AC.Sound.LoadData ( SoundData  soundData)

Updates its own variables from a SoundData class.

Parameters
soundDataThe SoundData class to load from

◆ Play() [1/3]

void AC.Sound.Play ( )

Plays the AudioSource's current AudioClip, without starting over if it was paused or changing its "loop" variable.

◆ Play() [2/3]

void AC.Sound.Play ( AudioClip  clip,
bool  loop,
int  _timeSamples = 0 
)

Plays an AudioClip.

Parameters
clipThe AudioClip to play
loopIf true, the AudioClip will be looped
_timeSamplesThe timeSamples to play from

◆ Play() [3/3]

void AC.Sound.Play ( bool  loop)

Plays the AudioSource's current AudioClip.

Parameters
loopIf true, the AudioClip will be looped

◆ PlayAtPoint()

void AC.Sound.PlayAtPoint ( bool  loop,
int  samplePoint 
)

Plays the AudioSource's current AudioClip from a set point.

Parameters
loopIf true, the AudioClip will be looped
samplePointThe playback position in PCM samples

◆ SetMaxVolume()

void AC.Sound.SetMaxVolume ( )

Calculates the maximum volume that the AudioSource can have. This should be called whenever the volume in OptionsData is changed.

◆ SetVolume()

void AC.Sound.SetVolume ( float  volume)

Sets the volume, but takes relativeVolume into account as well.

Parameters
volumeThe volume to set

◆ Stop()

void AC.Sound.Stop ( )

Abruptly stops the currently-playing sound.

◆ TryDestroy()

void AC.Sound.TryDestroy ( )

Destroys itself, if it should do.

Member Data Documentation

◆ playWhilePaused

bool AC.Sound.playWhilePaused = false

If True, then the sound can play when the game is paused

◆ relativeVolume

float AC.Sound.relativeVolume = 1f

The volume of the sound, relative to its categoriy's "global" volume set within OptionsData

◆ soundType

SoundType AC.Sound.soundType

The type of sound, so far as volume levels go (SFX, Music, Other)

◆ surviveSceneChange

bool AC.Sound.surviveSceneChange = false

If True, then the GameObject this is attached to will not be destroyed when changing scene

Property Documentation

◆ audioSource

AudioSource AC.Sound.audioSource
get

The AudioSource that AudioClip assets are played from