DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
EffectSound.c
См. документацию.
1
5{
15
25
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;
42
47 protected bool m_SoundWaveStarting;
48 protected bool m_SoundWaveStopping;
49 protected bool m_SoundFadedOut;
50
51 protected float m_SoundFadeInDuration;
52
53 protected float m_SoundFadeOutStartTime;
54 protected float m_SoundFadeOutDuration;
55 protected float m_SoundFadeOutInitVolume;
57
58
59
64 {
65 m_SoundWaveKind = WaveKind.WAVEEFFECTEX;
68 m_SoundAutodestroy = false;
69 m_SoundWaveStopping = false;
70 m_SoundFadedOut = false;
71 m_SoundDoppler = -1;
72 }
73
78 {
79
80 }
81
85 override void InitEffect()
86 {
87 super.InitEffect();
88
89 // These will be called by the sound events
92 }
93
97 override string GetDebugName()
98 {
99 string identifier;
100 if (m_SoundSetName != "")
101 {
102 identifier = m_SoundSetName;
103 }
104 else
105 {
106 identifier = "NO_SOUNDSET";
107 }
108
109 return string.Format("%1:%2", super.GetDebugName(), identifier);
110 }
111
112
113
118
124 {
125 return EffectType.SOUND;
126 }
127
132 override bool IsSound()
133 {
134 return true;
135 }
136
138
139
140
146
152 bool SoundPlayEx(out SoundParams params)
153 {
154 super.Start();
155
156 if (m_SoundSetName != "")
157 {
158 vector position = GetCurrentLocalPosition();
159
160 if ( SoundLoadEx(params) )
161 {
163 {
164 m_SoundObjectBuilder.AddEnvSoundVariables(GetPosition());
165 m_SoundObject = m_SoundObjectBuilder.BuildSoundObject();
167 m_SoundObject.SetParent( m_ParentObject );
168 }
169
170 if ( m_SoundObject )
171 {
172 SetCurrentLocalPosition(position, false);
174 if ( !m_SoundWaveObject )
175 return false;
176
177 // Wait for header to be loaded before asking for its length, else we block the main thread
178 if (m_SoundWaveObject.IsHeaderLoaded())
180 else
181 m_SoundWaveObject.GetEvents().Event_OnSoundWaveHeaderLoaded.Insert(ValidateSoundWave);
182
183 return true;
184 }
185 else
186 {
187 SoundError("m_SoundObject is null.");
188 }
189 }
190 }
191
192 return false;
193 }
194
200 {
201 SoundParams params;
202 return SoundPlayEx(params);
203 }
204
208 override void Start()
209 {
210 SoundPlay();
211 }
212
218 {
219 super.Stop();
220
221 if ( IsSoundPlaying() )
222 {
224 {
225 m_SoundWaveStopping = true;
226 m_SoundFadedOut = false;
227 m_SoundWaveStarting = false;
229 }
230 else
231 {
232 m_SoundWaveObject.Stop();
233 }
234 }
235 else if (!IsPendingDeletion()) // not about to be destroyed
236 {
237 SoundReset();
238 }
239 }
240
244 override void Stop()
245 {
246 SoundStop();
247 }
248
252 protected void SoundReset()
253 {
254 m_IsPlaying = false;
255 m_SoundWaveIsPlaying = false;
256 m_SoundWaveStopping = false;
257 m_SoundFadedOut = false;
259 m_SoundWaveTime = 0;
262
263 if ( m_SoundWaveObject )
264 {
265 m_SoundWaveObject.Stop();
266 m_SoundWaveObject.SetVolumeRelative( m_SoundWaveVolumeMax );
267 }
268 }
269
275 {
277 }
278
282 override bool IsPlaying()
283 {
284 return IsSoundPlaying(); // Just in case, as that's what used to be the actual way to check
285 }
286
288
289
290
295
300 bool SoundLoadEx(out SoundParams params)
301 {
302 if ( !m_SoundParams || !m_SoundParams.IsValid() )
303 {
304 if (!params)
305 {
306 params = new SoundParams( m_SoundSetName );
307 }
308
309 //Print("SoundLoad is loading..");
310 m_SoundParams = params;
311 if ( !m_SoundParams.IsValid() )
312 {
313 SoundError("Invalid sound set.");
314 return false;
315 }
316
319 {
320 m_SoundObjectBuilder.AddEnvSoundVariables(GetPosition());
321 }
322
323 m_SoundObject = m_SoundObjectBuilder.BuildSoundObject();
324
325 if ( m_SoundObject )
326 {
328 m_SoundObject.SetParent( m_ParentObject );
329 }
330 else
331 {
332 SoundError("m_SoundObject is null.");
333 }
334 }
335 else
336 {
337 //Print("SoundLoad is loaded.");
338 }
339
340 return true;
341 }
342
348 {
349 SoundParams params;
350 return SoundLoadEx(params);
351 }
352
357 {
358 return m_SoundParams.IsValid();
359 }
360
365 protected void ValidateSoundWave()
366 {
368 {
369 ErrorEx(string.Format("%1 SoundWaveObject is null. SoundSet: %2", this.ToString(), m_SoundSetName));
370 return;
371 }
372
374
375 if ( SoundWaveValidation() )
376 {
377 if ( m_SoundFadeInDuration > 0 )
378 {
379 m_SoundWaveObject.SetVolumeRelative( 0 );
381 }
382
384
385 m_SoundWaveStarting = true;
386
387 AbstractWaveEvents events = m_SoundWaveObject.GetEvents();
390
391 UpdateEvents();
392 }
393 else
394 {
395 m_SoundWaveObject.Stop();
396 }
397 }
398
403 protected bool SoundWaveValidation()
404 {
405 bool valid = true;
406
408 {
409 SoundError("FadeIn is longer than sound wave length.");
410 valid = false;
411 }
412
414 {
415 SoundError("FadeOut is longer than sound wave length.");
416 valid = false;
417 }
418
420 {
421 SoundError("FadeIn & FadeOut are longer than sound wave length.");
422 valid = false;
423 }
424
425 return valid;
426 }
427
433 protected void UpdateEvents()
434 {
435 if ( m_SoundWaveObject )
436 {
438 }
439 else
440 {
441 SetEnableEventFrame(false);
442 }
443 }
444
446
447
448
453
460 override void Event_OnFrameUpdate(float time_delta)
461 {
462 if ( IsSoundPlaying() )
463 {
464 if (m_SoundDoppler != -1)
465 {
467 }
468 // FadeIn
470 {
471 if ( m_SoundFadeInDuration > 0 )
472 {
474
476 {
479 m_SoundWaveStarting = false;
480 }
481 }
482 else
483 {
485 m_SoundWaveStarting = false;
486 }
487 }
488
489 // FadeOut
491 {
492 if ( m_SoundFadeOutDuration > 0 )
493 {
494 if ( m_SoundFadeOutInitVolume == 0 )
495 {
498 }
500 }
501 else
502 {
503 SetSoundVolume( 0 );
504 }
505
506 if ( GetSoundVolume() <= 0 )
507 {
508 if ( m_SoundWaveObject )
509 {
510 m_SoundWaveObject.Stop();
511 m_SoundWaveStopping = false;
512 m_SoundFadedOut = true;
513 }
514 }
515 }
516
517 // Counting timer here because loop play
518 m_SoundWaveTime += time_delta;
519 }
520 }
521
527 override void Event_OnRegistered(int id)
528 {
529 super.Event_OnRegistered(id);
530
532 }
533
538 override void Event_OnUnregistered()
539 {
540 super.Event_OnUnregistered();
541
543 }
544
550 {
552
553 Event_OnSoundWaveStarted.Invoke(this);
554
556 }
557
563 {
564 m_SoundWaveIsPlaying = false;
565
566 Event_OnSoundWaveEnded.Invoke(this);
567
569 }
570
576 {
577 Event_OnSoundFadeInStopped.Invoke(this);
578 }
579
585 {
586 Event_OnSoundFadeOutStarted.Invoke(this);
587 }
588
590
591
592
597
603 override void SetAutodestroy(bool auto_destroy)
604 {
605 super.SetAutodestroy(auto_destroy);
606 m_SoundAutodestroy = auto_destroy;
607 }
608
613 override bool IsAutodestroy()
614 {
615 return IsSoundAutodestroy();
616 }
617
622 void SetSoundAutodestroy(bool auto_destroy)
623 {
624 SetAutodestroy(auto_destroy);
625 }
626
632 {
633 return m_SoundAutodestroy;
634 }
635
636 override bool CanDestroy()
637 {
639 }
640
642
643
644
649
654 override void SetParent(Object parent_obj)
655 {
656 super.SetParent(parent_obj); // ...
657
658 if (m_SoundObject)
659 {
660 m_SoundObject.SetParent(parent_obj);
661 }
662 }
663
668 override Object GetParent()
669 {
670 if (m_SoundObject)
671 return Object.Cast(m_SoundObject.GetParent());
672 else
673 return super.GetParent();
674 }
675
682 {
683 if (m_SoundObject)
684 return Object.Cast(m_SoundObject.GetParent());
685 else
686 return super.GetParent(); // Yes, intentionally this one
687 }
688
694 override void SetCurrentPosition( vector pos, bool updateCached = true )
695 {
696 super.SetCurrentPosition(pos, updateCached);
697
698 if (m_SoundObject)
699 {
700 Object parent = GetParent();
701
702 if (parent)
703 pos = parent.WorldToModel(pos);
704
705 m_SoundObject.SetPosition(pos);
706 }
707 }
708
714 {
715 if (m_SoundObject)
716 return m_SoundObject.GetPosition();
717
718 if (m_ParentObject)
719 return m_ParentObject.ModelToWorld(GetPosition());
720
721 return GetPosition();
722 }
723
729 override void SetCurrentLocalPosition( vector pos, bool updateCached = true )
730 {
731 super.SetCurrentLocalPosition(pos, updateCached);
732
733 if (m_SoundObject)
734 {
735 m_SoundObject.SetPosition(pos);
736 }
737 }
738
744 {
745 Object parent = GetParent();
746
747 if (m_SoundObject)
748 {
749 //TODO(kumarjac): Create and expose 'SoundObject.GetLocalPosition'
750 if (parent)
751 return parent.WorldToModel(m_SoundObject.GetPosition());
752 else
753 return m_SoundObject.GetPosition();
754 }
755 else
756 {
757 if (parent)
758 return GetLocalPosition();
759 else
760 return GetPosition();
761 }
762
763 return vector.Zero;
764 }
765
772 {
773 m_SoundWaveKind = wave_kind;
774 }
775
781 void SetSoundSet(string snd)
782 {
783 m_SoundSetName = snd;
784 }
785
790 string GetSoundSet()
791 {
792 return m_SoundSetName;
793 }
794
799 void SetSoundLoop(bool loop)
800 {
801 m_SoundLoop = loop;
802
803 if ( m_SoundWaveObject )
804 m_SoundWaveObject.Loop( loop );
805 }
806
811 void SetEnviromentVariables(bool setEnvVariables)
812 {
813 m_SetEnvVariables = setEnvVariables;
814 }
815
822 {
823 return GetSoundWaveLength();
824 }
825
831 {
832 return m_SoundWaveLenght;
833 }
834
839 void SetSoundVolume(float volume)
840 {
841 m_SoundWaveVolume = volume;
842 if ( m_SoundWaveObject )
843 m_SoundWaveObject.SetVolumeRelative( volume );
844 }
845
851 {
852 return m_SoundWaveVolume;
853 }
854
861 void SetSoundMaxVolume(float volume)
862 {
863 m_SoundWaveVolumeMax = volume;
864 if ( m_SoundWaveObject )
865 m_SoundWaveObject.SetVolumeRelative( m_SoundWaveVolume );
866 }
867
874 {
875 return m_SoundWaveTime;
876 }
877
882 void SetSoundFadeIn(float fade_in)
883 {
884 m_SoundFadeInDuration = fade_in;
885 }
886
891 void SetSoundFadeOut(float fade_out)
892 {
893 m_SoundFadeOutDuration = fade_out;
894 }
895
900 void SetDoppler(bool setDoppler)
901 {
903 m_SoundDoppler = 0;
904 if (setDoppler)
905 {
906 m_SoundDoppler = 1;
907 }
908 }
909
911
912
913
917 protected void SoundError(string err_msg)
918 {
919 ErrorEx(string.Format("%1: SoundSetName: '%2' :: %3", this, m_SoundSetName, err_msg));
920 }
921}
bool m_IsPlaying
Whether the Effect is currently playing.
Определения Effect.c:37
Object m_ParentObject
Cached parent.
Определения Effect.c:39
ref ScriptInvoker Event_OnEffectStarted
Event used when the actual effect started playing.
Определения Effect.c:24
EffectType
Enum to determine what type of effect the Effect is.
Определения Effect.c:3
ref ScriptInvoker Event_OnEffectEnded
Event used when the actual effect stopped playing.
Определения Effect.c:25
vector GetLocalPosition()
Get the local position of the Effect.
Определения Effect.c:488
ref ScriptInvoker Event_OnStopped
Event used when Stop was called.
Определения Effect.c:23
void Effect()
ctor
Определения Effect.c:70
Event_OnStarted
Event used when Start was called.
Определения Effect.c:302
proto string ToString()
WaveKind
Определения Sound.c:2
Определения Sound.c:147
proto native AbstractSoundScene GetSoundScene()
void ~EffectSound()
dtor
Определения EffectSound.c:77
bool SoundLoadEx(out SoundParams params)
Loads in the sound when it is requested for playing through 'SoundPlayEx'.
Определения EffectSound.c:300
override void SetCurrentLocalPosition(vector pos, bool updateCached=true)
Set the current local position of the managed sound.
Определения EffectSound.c:729
void SetSoundSet(string snd)
Set soundset for the sound.
Определения EffectSound.c:781
void Event_OnSoundWaveEnded()
Event called when sound stops playing.
Определения EffectSound.c:562
override vector GetCurrentLocalPosition()
Get the current local position of the managed sound.
Определения EffectSound.c:743
override bool IsPlaying()
Returns true when the effect is playing, false otherwise.
Определения EffectSound.c:282
ref SoundParams m_SoundParams
Определения EffectSound.c:20
bool m_SetEnvVariables
Определения EffectSound.c:33
void UpdateEvents()
Enables the frame event on the EffectSound.
Определения EffectSound.c:433
ref ScriptInvoker Event_OnSoundWaveStarted
Определения EffectSound.c:10
string m_SoundSetName
Определения EffectSound.c:31
override void Start()
Plays sound.
Определения EffectSound.c:208
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
Определения EffectSound.c:603
void SetSoundAutodestroy(bool auto_destroy)
Sets whether EffectSound automatically cleans up when sound stops.
Определения EffectSound.c:622
override void SetParent(Object parent_obj)
Set parent for the sound to follow.
Определения EffectSound.c:654
override Object GetParent()
Get parent for the EffectSound.
Определения EffectSound.c:668
float m_SoundWaveVolume
Определения EffectSound.c:37
float GetSoundWaveLenght()
Get the sound wave length.
Определения EffectSound.c:821
float GetSoundVolume()
Get the RELATIVE volume set by 'SetSoundVolume'.
Определения EffectSound.c:850
float m_SoundFadeInDuration
Определения EffectSound.c:51
void SoundError(string err_msg)
Helper for throwing sound errors.
Определения EffectSound.c:917
void SetSoundMaxVolume(float volume)
Set the sound max volume.
Определения EffectSound.c:861
void SoundReset()
Resets EffectSound.
Определения EffectSound.c:252
AbstractWave m_SoundWaveObject
Определения EffectSound.c:23
string GetSoundSet()
Get soundset for the sound.
Определения EffectSound.c:790
WaveKind m_SoundWaveKind
Определения EffectSound.c:30
override void Event_OnRegistered(int id)
Event called from SEffectManager when the Effect is registered.
Определения EffectSound.c:527
void SetDoppler(bool setDoppler)
Set if the sound has the doppler effect enabled.
Определения EffectSound.c:900
override void InitEffect()
init
Определения EffectSound.c:85
bool m_SoundWaveIsPlaying
Определения EffectSound.c:35
override vector GetCurrentPosition()
Get the current world position of the managed sound.
Определения EffectSound.c:713
bool SoundPlayEx(out SoundParams params)
Plays sound.
Определения EffectSound.c:152
ref ScriptInvoker Event_OnSoundFadeOutStarted
Определения EffectSound.c:13
void EffectSound()
ctor
Определения EffectSound.c:63
void SetSoundLoop(bool loop)
Set if the sound loops.
Определения EffectSound.c:799
float m_SoundWaveTime
Определения EffectSound.c:39
float m_SoundFadeOutInitVolume
Определения EffectSound.c:55
ref ScriptInvoker Event_OnSoundFadeInStopped
Определения EffectSound.c:12
float m_SoundWaveLenght
Определения EffectSound.c:36
void ValidateSoundWave()
Gets called to fill in the necessary data when the header has finished loading.
Определения EffectSound.c:365
override void Event_OnFrameUpdate(float time_delta)
Event called on frame when enabled by SetEnableEventFrame(true)
Определения EffectSound.c:460
override Object GetCurrentParent()
Get parent for the EffectSound.
Определения EffectSound.c:681
void Event_OnSoundFadeOutStarted()
Event called when sound fade out starts.
Определения EffectSound.c:584
void SetSoundVolume(float volume)
Set the RELATIVE volume for the sound.
Определения EffectSound.c:839
bool m_SoundAutodestroy
Определения EffectSound.c:34
override EffectType GetEffectType()
Get what type of effect the Effect is.
Определения EffectSound.c:123
bool SoundLoad()
Loads in the sound when it is requested for playing.
Определения EffectSound.c:347
void SetSoundFadeIn(float fade_in)
Set the sound fade in duration.
Определения EffectSound.c:882
override void Stop()
Stops sound.
Определения EffectSound.c:244
void Event_OnSoundFadeInStopped()
Event called when sound fade in stops.
Определения EffectSound.c:575
override bool IsSound()
Check whether the Effect is EffectSound without casting.
Определения EffectSound.c:132
override bool CanDestroy()
Определения EffectSound.c:636
void SetSoundWaveKind(WaveKind wave_kind)
Set WaveKind for the sound.
Определения EffectSound.c:771
void SetSoundFadeOut(float fade_out)
Set the sound fade out duration.
Определения EffectSound.c:891
float m_SoundFadeOutStartTime
Определения EffectSound.c:53
bool IsSoundPlaying()
Get whether EffectSound is currently playing.
Определения EffectSound.c:274
float GetSoundWaveLength()
Get the sound wave length.
Определения EffectSound.c:830
void SetEnviromentVariables(bool setEnvVariables)
Sets whether AddEnvSoundVariables needs to be called during Loading.
Определения EffectSound.c:811
bool m_SoundWaveStarting
Определения EffectSound.c:47
int m_SoundDoppler
Определения EffectSound.c:40
override bool IsAutodestroy()
Get whether Effect automatically cleans up when it stops.
Определения EffectSound.c:613
bool SoundWaveValidation()
Validation of fade settings.
Определения EffectSound.c:403
void Event_OnSoundWaveStarted()
Event called when sound starts playing.
Определения EffectSound.c:549
bool IsSoundValid()
Helper for checking if params are valid.
Определения EffectSound.c:356
ref SoundObjectBuilder m_SoundObjectBuilder
Определения EffectSound.c:21
float m_SoundFadeOutDuration
Определения EffectSound.c:54
override string GetDebugName()
Override when getting debug information.
Определения EffectSound.c:97
bool m_SoundLoop
Определения EffectSound.c:32
bool m_SoundFadedOut
Определения EffectSound.c:49
bool IsSoundAutodestroy()
Get whether EffectSound automatically cleans up when sound stops.
Определения EffectSound.c:631
ref SoundObject m_SoundObject
Определения EffectSound.c:22
ref ScriptInvoker Event_OnSoundWaveEnded
Определения EffectSound.c:11
bool SoundPlay()
Plays sound.
Определения EffectSound.c:199
override void SetCurrentPosition(vector pos, bool updateCached=true)
Set the world position of the managed sound.
Определения EffectSound.c:694
override void Event_OnUnregistered()
Event called from SEffectManager when the Effect is unregistered.
Определения EffectSound.c:538
float m_SoundWaveVolumeMax
Определения EffectSound.c:38
bool m_SoundWaveStopping
Определения EffectSound.c:48
void SoundStop()
Stops sound.
Определения EffectSound.c:217
float GetSoundWaveTime()
Get the time since EffectSound started playing.
Определения EffectSound.c:873
Определения ObjectTyped.c:2
static void Event_OnSoundWaveEnded(EffectSound effect_sound)
Event called from EffectSound.Event_OnSoundWaveEnded.
Определения EffectManager.c:468
Manager class for managing Effect (EffectParticle, EffectSound)
Определения EffectManager.c:6
proto bool Insert(func fn, int flags=EScriptInvokerInsertFlags.IMMEDIATE)
insert method to list
ScriptInvoker Class provide list of callbacks usage:
Определения tools.c:116
Определения Sound.c:112
static const vector Zero
Определения EnConvert.c:110
Определения EnConvert.c:106
proto native CGame GetGame()
void SetEnableEventFrame(bool enable)
Enable Event_OnFrameUpdate for the effect.
Определения Effect.c:280
enum ShapeType ErrorEx
bool IsPendingDeletion()
Get whether the Effect is queued up for being cleaned up.
Определения Effect.c:258
proto native AbstractWave Play3D(SoundObject soundObject, SoundObjectBuilder soundBuilder)
ref ScriptInvoker Event_OnSoundWaveEnded
Определения Sound.c:152
class AbstractSoundScene SoundObjectBuilder(SoundParams soundParams)
class JsonUndergroundAreaTriggerData GetPosition
Определения UndergroundAreaLoader.c:9
void AbstractWave()
Определения Sound.c:167
class SoundObject SoundParams(string name)
ref ScriptInvoker Event_OnSoundWaveStarted
Определения Sound.c:148
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.