14 private AudioSource primarySource = null;
15 public AudioSource PrimarySource
23 primarySource = value;
24 if (primarySource != null)
26 primarySource.enabled =
true;
31 private AudioSource secondarySource = null;
32 public AudioSource SecondarySource
36 return secondarySource;
40 secondarySource = value;
41 if (secondarySource != null)
43 secondarySource.enabled =
true;
53 (primarySource != null && primarySource.isPlaying) ||
54 (secondarySource != null && secondarySource.isPlaying);
64 public string MessageOnAudioEnd
71 public bool IsStoppable =
true;
72 public float VolDest = 1;
73 public float AltVolDest = 1;
74 public float CurrentFade = 0;
75 public bool PlayingAlt =
false;
76 public bool IsActiveTimeComplete =
false;
77 public float ActiveTime = 0;
78 public bool CancelEvent =
false;
80 public ActiveEvent(AudioEvent audioEvent, GameObject emitter, AudioSource primarySource, AudioSource secondarySource,
string messageOnAudioEnd = null)
82 this.AudioEvent = audioEvent;
84 PrimarySource = primarySource;
85 SecondarySource = secondarySource;
86 MessageOnAudioEnd = messageOnAudioEnd;
87 SetSourceProperties();
95 private void SetSourceProperties()
97 Action<Action<AudioSource>> forEachSource = (action) =>
99 action(PrimarySource);
100 if (SecondarySource != null)
102 action(SecondarySource);
106 AudioEvent audioEvent = this.AudioEvent;
110 forEachSource((source) =>
112 source.spatialBlend = 0f;
113 source.spatialize =
false;
117 forEachSource((source) =>
119 source.spatialBlend = 1f;
120 source.spatialize =
false;
124 forEachSource((source) =>
126 source.spatialBlend = 1f;
127 source.spatialize =
true;
131 Debug.LogErrorFormat(
"Unexpected spatialization type: {0}", audioEvent.
Spatialization.ToString());
137 forEachSource((source) =>
140 source.rolloffMode = AudioRolloffMode.Custom;
142 source.SetCustomCurve(AudioSourceCurveType.CustomRolloff, audioEvent.
AttenuationCurve);
147 forEachSource((source) =>
151 source.rolloffMode = AudioRolloffMode.Custom;
152 source.maxDistance = audioEvent.MaxDistanceAttenuation3D;
153 source.SetCustomCurve(AudioSourceCurveType.CustomRolloff, audioEvent.AttenuationCurve);
154 source.SetCustomCurve(AudioSourceCurveType.SpatialBlend, audioEvent.SpatialCurve);
155 source.SetCustomCurve(AudioSourceCurveType.Spread, audioEvent.SpreadCurve);
156 source.SetCustomCurve(AudioSourceCurveType.ReverbZoneMix, audioEvent.ReverbCurve);
160 source.rolloffMode = AudioRolloffMode.Logarithmic;
167 forEachSource((source) => source.outputAudioMixerGroup = audioEvent.
AudioBus);
180 forEachSource((source) => source.pitch = pitch);
185 forEachSource((source) => source.volume = 0f);
207 forEachSource((source) => source.volume = vol);
215 forEachSource((source) => source.panStereo = pan);
224 if (newPitch <= 0 || newPitch > 3)
226 Debug.LogErrorFormat(
"Invalid pitch {0} set for event", newPitch);
230 this.PrimarySource.pitch = newPitch;
235 if (this.primarySource != null)
237 this.primarySource.enabled =
false;
238 this.primarySource = null;
241 if (this.secondarySource != null)
243 this.secondarySource.enabled =
false;
244 this.secondarySource = null;
253 if (SpatialRolloff != null)
257 SpatialRolloff =
new AnimationCurve();
258 SpatialRolloff.AddKey(0, 1);
259 SpatialRolloff.AddKey(1, 1);