31 protected string m_SoundSetName;
32 protected bool m_SoundLoop;
33 protected bool m_SetEnvVariables;
34 protected bool m_SoundAutodestroy;
35 protected bool m_SoundWaveIsPlaying;
36 protected float m_SoundWaveLenght;
37 protected float m_SoundWaveVolume;
38 protected float m_SoundWaveVolumeMax;
39 protected float m_SoundWaveTime;
40 protected int m_SoundDoppler;
47 protected bool m_SoundWaveStarting;
48 protected bool m_SoundWaveStopping;
49 protected bool m_SoundFadedOut;
51 protected float m_SoundFadeInDuration;
53 protected float m_SoundFadeOutStartTime;
54 protected float m_SoundFadeOutDuration;
55 protected float m_SoundFadeOutInitVolume;
65 m_SoundWaveKind =
WaveKind.WAVEEFFECTEX;
66 m_SoundWaveVolume = 0;
67 m_SoundWaveVolumeMax = 1;
68 m_SoundAutodestroy =
false;
69 m_SoundWaveStopping =
false;
70 m_SoundFadedOut =
false;
85 override void InitEffect()
97 override string GetDebugName()
100 if (m_SoundSetName !=
"")
102 identifier = m_SoundSetName;
106 identifier =
"NO_SOUNDSET";
109 return string.Format(
"%1:%2", super.GetDebugName(), identifier);
132 override bool IsSound()
156 if (m_SoundSetName !=
"")
158 vector position = GetCurrentLocalPosition();
160 if ( SoundLoadEx(params) )
162 if (m_SetEnvVariables && m_SoundParams)
166 m_SoundObject.SetKind( m_SoundWaveKind );
172 SetCurrentLocalPosition(position,
false);
174 if ( !m_SoundWaveObject )
178 if (m_SoundWaveObject.IsHeaderLoaded())
181 m_SoundWaveObject.GetEvents().Event_OnSoundWaveHeaderLoaded.Insert(ValidateSoundWave);
187 SoundError(
"m_SoundObject is null.");
202 return SoundPlayEx(params);
208 override void Start()
221 if ( IsSoundPlaying() )
223 if ( m_SoundFadeOutDuration > 0 && !m_SoundWaveStopping )
225 m_SoundWaveStopping =
true;
226 m_SoundFadedOut =
false;
227 m_SoundWaveStarting =
false;
228 m_SoundFadeOutStartTime = m_SoundWaveTime;
232 m_SoundWaveObject.Stop();
252 protected void SoundReset()
255 m_SoundWaveIsPlaying =
false;
256 m_SoundWaveStopping =
false;
257 m_SoundFadedOut =
false;
258 m_SoundWaveVolume = m_SoundWaveVolumeMax;
260 m_SoundFadeOutInitVolume = 0;
261 m_SoundFadeOutStartTime = 0;
263 if ( m_SoundWaveObject )
265 m_SoundWaveObject.Stop();
266 m_SoundWaveObject.SetVolumeRelative( m_SoundWaveVolumeMax );
274 bool IsSoundPlaying()
276 return m_SoundWaveIsPlaying;
282 override bool IsPlaying()
284 return IsSoundPlaying();
302 if ( !m_SoundParams || !m_SoundParams.IsValid() )
310 m_SoundParams = params;
311 if ( !m_SoundParams.IsValid() )
313 SoundError(
"Invalid sound set.");
318 if (m_SetEnvVariables)
327 m_SoundObject.SetKind( m_SoundWaveKind );
332 SoundError(
"m_SoundObject is null.");
350 return SoundLoadEx(params);
358 return m_SoundParams.IsValid();
365 protected void ValidateSoundWave()
367 m_SoundWaveLenght = m_SoundWaveObject.GetLength();
369 if ( SoundWaveValidation() )
371 if ( m_SoundFadeInDuration > 0 )
373 m_SoundWaveObject.SetVolumeRelative( 0 );
374 m_SoundFadeOutStartTime = m_SoundWaveLenght - m_SoundFadeInDuration;
377 SetSoundLoop( m_SoundLoop );
379 m_SoundWaveStarting =
true;
381 AbstractWaveEvents events = m_SoundWaveObject.GetEvents();
389 m_SoundWaveObject.Stop();
397 protected bool SoundWaveValidation()
401 if ( m_SoundFadeInDuration > GetSoundWaveLength() )
403 SoundError(
"FadeIn is longer than sound wave length.");
407 if ( m_SoundFadeOutDuration > GetSoundWaveLength() )
409 SoundError(
"FadeOut is longer than sound wave length.");
413 if ( m_SoundFadeOutDuration + m_SoundFadeInDuration > GetSoundWaveLength() )
415 SoundError(
"FadeIn & FadeOut are longer than sound wave length.");
427 protected void UpdateEvents()
429 if ( m_SoundWaveObject )
454 override void Event_OnFrameUpdate(
float time_delta)
456 if ( IsSoundPlaying() )
458 if (m_SoundDoppler != -1)
460 m_SoundWaveObject.SetDoppler(m_SoundDoppler);
463 if ( m_SoundWaveStarting )
465 if ( m_SoundFadeInDuration > 0 )
467 SetSoundVolume( GetSoundVolume() + (time_delta / m_SoundFadeInDuration) );
469 if ( GetSoundVolume() >= m_SoundWaveVolumeMax )
471 Event_OnSoundFadeInStopped();
472 SetSoundVolume( m_SoundWaveVolumeMax );
473 m_SoundWaveStarting =
false;
478 SetSoundVolume( m_SoundWaveVolumeMax );
479 m_SoundWaveStarting =
false;
484 if ( m_SoundWaveStopping )
486 if ( m_SoundFadeOutDuration > 0 )
488 if ( m_SoundFadeOutInitVolume == 0 )
490 m_SoundFadeOutInitVolume = GetSoundVolume();
491 Event_OnSoundFadeOutStarted();
493 SetSoundVolume( GetSoundVolume() - (m_SoundFadeOutInitVolume / m_SoundFadeOutDuration * time_delta) );
500 if ( GetSoundVolume() <= 0 )
502 if ( m_SoundWaveObject )
504 m_SoundWaveObject.Stop();
505 m_SoundWaveStopping =
false;
506 m_SoundFadedOut =
true;
512 m_SoundWaveTime += time_delta;
521 override void Event_OnRegistered(
int id)
523 super.Event_OnRegistered(
id);
532 override void Event_OnUnregistered()
534 super.Event_OnUnregistered();
545 m_SoundWaveIsPlaying =
true;
558 m_SoundWaveIsPlaying =
false;
569 void Event_OnSoundFadeInStopped()
571 Event_OnSoundFadeInStopped.Invoke(
this);
578 void Event_OnSoundFadeOutStarted()
580 Event_OnSoundFadeOutStarted.Invoke(
this);
597 override void SetAutodestroy(
bool auto_destroy)
599 super.SetAutodestroy(auto_destroy);
600 m_SoundAutodestroy = auto_destroy;
607 override bool IsAutodestroy()
609 return IsSoundAutodestroy();
616 void SetSoundAutodestroy(
bool auto_destroy)
618 SetAutodestroy(auto_destroy);
625 bool IsSoundAutodestroy()
627 return m_SoundAutodestroy;
630 override bool CanDestroy()
632 return m_SoundFadeOutDuration <= 0 || m_SoundFadedOut;
648 override void SetParent(
Object parent_obj)
650 super.SetParent(parent_obj);
654 m_SoundObject.SetParent(parent_obj);
662 override Object GetParent()
665 return Object.Cast(m_SoundObject.GetParent());
667 return super.GetParent();
675 override Object GetCurrentParent()
678 return Object.Cast(m_SoundObject.GetParent());
680 return super.GetParent();
688 override void SetCurrentPosition(
vector pos,
bool updateCached =
true )
690 super.SetCurrentPosition(pos, updateCached);
694 Object parent = GetParent();
697 pos = parent.WorldToModel(pos);
699 m_SoundObject.SetPosition(pos);
707 override vector GetCurrentPosition()
710 return m_SoundObject.GetPosition();
723 override void SetCurrentLocalPosition(
vector pos,
bool updateCached =
true )
725 super.SetCurrentLocalPosition(pos, updateCached);
729 m_SoundObject.SetPosition(pos);
737 override vector GetCurrentLocalPosition()
739 Object parent = GetParent();
745 return parent.WorldToModel(m_SoundObject.GetPosition());
747 return m_SoundObject.GetPosition();
765 void SetSoundWaveKind(
WaveKind wave_kind)
767 m_SoundWaveKind = wave_kind;
775 void SetSoundSet(
string snd)
777 m_SoundSetName = snd;
786 return m_SoundSetName;
793 void SetSoundLoop(
bool loop)
797 if ( m_SoundWaveObject )
798 m_SoundWaveObject.Loop( loop );
805 void SetEnviromentVariables(
bool setEnvVariables)
807 m_SetEnvVariables = setEnvVariables;
815 float GetSoundWaveLenght()
817 return GetSoundWaveLength();
824 float GetSoundWaveLength()
826 return m_SoundWaveLenght;
833 void SetSoundVolume(
float volume)
835 m_SoundWaveVolume = volume;
836 if ( m_SoundWaveObject )
837 m_SoundWaveObject.SetVolumeRelative( volume );
844 float GetSoundVolume()
846 return m_SoundWaveVolume;
855 void SetSoundMaxVolume(
float volume)
857 m_SoundWaveVolumeMax = volume;
858 if ( m_SoundWaveObject )
859 m_SoundWaveObject.SetVolumeRelative( m_SoundWaveVolume );
867 float GetSoundWaveTime()
869 return m_SoundWaveTime;
876 void SetSoundFadeIn(
float fade_in)
878 m_SoundFadeInDuration = fade_in;
885 void SetSoundFadeOut(
float fade_out)
887 m_SoundFadeOutDuration = fade_out;
894 void SetDoppler(
bool setDoppler)
911 protected void SoundError(
string err_msg)
913 ErrorEx(
string.Format(
"%1: SoundSetName: '%2' :: %3",
this, m_SoundSetName, err_msg));