Hydrogen Framework  1.3.1
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Hydrogen.Core.AudioStackItem Class Reference

A class represention of all information needed for an AudioClip to be played via the AudioStack. More...

Public Member Functions

 AudioStackItem ()
 Initializes a new instance of the Hydrogen.Core.AudioStackItem class. More...
 
 AudioStackItem (AudioClip clip)
 Initializes a new instance of the Hydrogen.Core.AudioStackItem class. More...
 
 AudioStackItem (AudioClip clip, bool loop)
 Initializes a new instance of the Hydrogen.Core.AudioStackItem class. More...
 
 AudioStackItem (AudioClip clip, string key)
 Initializes a new instance of the Hydrogen.Core.AudioStackItem class. More...
 
 AudioStackItem (AudioClip clip, string key, bool loop)
 Initializes a new instance of the Hydrogen.Core.AudioStackItem class. More...
 
void Pause ()
 Instruct the AudioSource to Pause playback. More...
 
void Play ()
 Instruct the AudioSource to play the currently loaded clip from its currently set position. More...
 
void Process ()
 Process / Update our AudioStackItem More...
 
void Restart ()
 Instruct the AudioSource to Restart playback, resetting the position to the start of the clip, and playing it. More...
 
void Stop ()
 Instruct the AudioSource to Stop playback, resetting the position in the clip. More...
 

Public Attributes

AudioClip Clip
 The associated AudioClip More...
 
string Key
 Key to be used by the AudioStack More...
 
float FadeInSpeed = 4.5f
 /// Fade In Speed, used in a Lerp. More...
 
float FadeOutSpeed = 5.0f
 Fade Out Speed, used in a Lerp. More...
 
bool Fade
 Should the AudioSource fade between volume levels? More...
 
bool Loop
 Should the AudioSource loop the clip? More...
 
float MaxVolume = 1f
 The max volume for the item. More...
 
bool Persistant
 Do not remove the AudioItem when finished playing, useful for menu clicks etc More...
 
bool PlayOnLoad = true
 Should the Audio Clip be played automatically upon load? More...
 
int Priority = 128
 The priority that this Audio Stack Item takes over all other sounds playing through the stack. More...
 
bool RemoveAfterFadeOut = true
 Should the AudioPoolItem be destroyed, freeing it's AudioSource when it's volume reaches 0 after fading More...
 
float StartVolume = 1f
 The volume to use when the sound is first played. More...
 
float TargetVolume = 1f
 The volume which the AudioSource should gravitate towards. More...
 

Detailed Description

A class represention of all information needed for an AudioClip to be played via the AudioStack.

Definition at line 36 of file AudioStackItem.cs.

Constructor & Destructor Documentation

Hydrogen.Core.AudioStackItem.AudioStackItem ( )

Initializes a new instance of the Hydrogen.Core.AudioStackItem class.

Definition at line 110 of file AudioStackItem.cs.

111  {
112  }
Hydrogen.Core.AudioStackItem.AudioStackItem ( AudioClip  clip)

Initializes a new instance of the Hydrogen.Core.AudioStackItem class.

Parameters
clipAn AudioClip

Definition at line 118 of file AudioStackItem.cs.

119  {
120  Clip = clip;
121  Key = clip.name;
122  }
string Key
Key to be used by the AudioStack
AudioClip Clip
The associated AudioClip
Hydrogen.Core.AudioStackItem.AudioStackItem ( AudioClip  clip,
bool  loop 
)

Initializes a new instance of the Hydrogen.Core.AudioStackItem class.

Parameters
clipAn AudioClip.
loopShould the AudioSource loop?

Definition at line 129 of file AudioStackItem.cs.

130  {
131  Clip = clip;
132  Key = clip.name;
133  Loop = loop;
134  }
string Key
Key to be used by the AudioStack
AudioClip Clip
The associated AudioClip
bool Loop
Should the AudioSource loop the clip?
Hydrogen.Core.AudioStackItem.AudioStackItem ( AudioClip  clip,
string  key 
)

Initializes a new instance of the Hydrogen.Core.AudioStackItem class.

Parameters
clipAn AudioClip.
keyDesignate Reference Key.

Definition at line 141 of file AudioStackItem.cs.

142  {
143  Clip = clip;
144  Key = key;
145  }
string Key
Key to be used by the AudioStack
AudioClip Clip
The associated AudioClip
Hydrogen.Core.AudioStackItem.AudioStackItem ( AudioClip  clip,
string  key,
bool  loop 
)

Initializes a new instance of the Hydrogen.Core.AudioStackItem class.

Parameters
clipAn AudioClip.
keyDesignate Reference Key.
loopShould the AudioSource loop?

Definition at line 153 of file AudioStackItem.cs.

154  {
155  Clip = clip;
156  Key = key;
157  Loop = loop;
158  }
string Key
Key to be used by the AudioStack
AudioClip Clip
The associated AudioClip
bool Loop
Should the AudioSource loop the clip?

Member Function Documentation

void Hydrogen.Core.AudioStackItem.Pause ( )

Instruct the AudioSource to Pause playback.

Definition at line 163 of file AudioStackItem.cs.

164  {
165  Source.Pause ();
166  }
void Hydrogen.Core.AudioStackItem.Play ( )

Instruct the AudioSource to play the currently loaded clip from its currently set position.

Definition at line 171 of file AudioStackItem.cs.

172  {
173  Source.Play ();
174  }
void Hydrogen.Core.AudioStackItem.Process ( )

Process / Update our AudioStackItem

Definition at line 179 of file AudioStackItem.cs.

180  {
181  if (Source == null || Clip == null)
182  return;
183 
184  if (TargetVolume > MaxVolume)
186 
187  if (Source.volume != TargetVolume) {
188  if (Fade) {
189  if (Source.volume > TargetVolume) {
190  Source.volume =
191  Mathf.Lerp (Source.volume, TargetVolume, FadeOutSpeed * Time.deltaTime);
192  } else {
193  Source.volume =
194  Mathf.Lerp (Source.volume, TargetVolume, FadeInSpeed * Time.deltaTime);
195  }
196  } else {
197  Source.volume = TargetVolume;
198  }
199  }
200 
201  // Automatically remove finished processes, but only if they are not marked persistant.
202  // Not checking for Loop as if someone sets it's TargetVolume to 0 its meant to go away.
203  if (!Persistant && ((Fade && RemoveAfterFadeOut && Source.volume < 0.0001f) || Source.time == Clip.length)) {
204 
205  Stack.Remove (this);
206  }
207  }
float FadeOutSpeed
Fade Out Speed, used in a Lerp.
AudioClip Clip
The associated AudioClip
bool RemoveAfterFadeOut
Should the AudioPoolItem be destroyed, freeing it&#39;s AudioSource when it&#39;s volume reaches 0 after fadi...
float FadeInSpeed
/// Fade In Speed, used in a Lerp.
bool Fade
Should the AudioSource fade between volume levels?
bool Persistant
Do not remove the AudioItem when finished playing, useful for menu clicks etc
float TargetVolume
The volume which the AudioSource should gravitate towards.
float MaxVolume
The max volume for the item.
void Hydrogen.Core.AudioStackItem.Restart ( )

Instruct the AudioSource to Restart playback, resetting the position to the start of the clip, and playing it.

Definition at line 212 of file AudioStackItem.cs.

213  {
214  Source.Stop ();
215  Source.Play ();
216  }
void Hydrogen.Core.AudioStackItem.Stop ( )

Instruct the AudioSource to Stop playback, resetting the position in the clip.

Definition at line 221 of file AudioStackItem.cs.

222  {
223  Source.Stop ();
224  }

Member Data Documentation

AudioClip Hydrogen.Core.AudioStackItem.Clip

The associated AudioClip

Definition at line 41 of file AudioStackItem.cs.

bool Hydrogen.Core.AudioStackItem.Fade

Should the AudioSource fade between volume levels?

Definition at line 60 of file AudioStackItem.cs.

float Hydrogen.Core.AudioStackItem.FadeInSpeed = 4.5f

/// Fade In Speed, used in a Lerp.

Definition at line 52 of file AudioStackItem.cs.

float Hydrogen.Core.AudioStackItem.FadeOutSpeed = 5.0f

Fade Out Speed, used in a Lerp.

Definition at line 56 of file AudioStackItem.cs.

string Hydrogen.Core.AudioStackItem.Key

Key to be used by the AudioStack

Should be unique to the AudioClip's file name.

Definition at line 48 of file AudioStackItem.cs.

bool Hydrogen.Core.AudioStackItem.Loop

Should the AudioSource loop the clip?

Definition at line 64 of file AudioStackItem.cs.

float Hydrogen.Core.AudioStackItem.MaxVolume = 1f

The max volume for the item.

Definition at line 68 of file AudioStackItem.cs.

bool Hydrogen.Core.AudioStackItem.Persistant

Do not remove the AudioItem when finished playing, useful for menu clicks etc

Definition at line 72 of file AudioStackItem.cs.

bool Hydrogen.Core.AudioStackItem.PlayOnLoad = true

Should the Audio Clip be played automatically upon load?

Definition at line 76 of file AudioStackItem.cs.

int Hydrogen.Core.AudioStackItem.Priority = 128

The priority that this Audio Stack Item takes over all other sounds playing through the stack.

Definition at line 80 of file AudioStackItem.cs.

bool Hydrogen.Core.AudioStackItem.RemoveAfterFadeOut = true

Should the AudioPoolItem be destroyed, freeing it's AudioSource when it's volume reaches 0 after fading

Definition at line 84 of file AudioStackItem.cs.

float Hydrogen.Core.AudioStackItem.StartVolume = 1f

The volume to use when the sound is first played.

Definition at line 101 of file AudioStackItem.cs.

float Hydrogen.Core.AudioStackItem.TargetVolume = 1f

The volume which the AudioSource should gravitate towards.

Definition at line 105 of file AudioStackItem.cs.