Beispiel #1
0
 public ActiveEvent(AudioEvent audioEvent, GameObject emitter, AudioSource primarySource, AudioSource secondarySource)
 {
     this.audioEvent = audioEvent;
     AudioEmitter    = emitter;
     PrimarySource   = primarySource;
     SecondarySource = secondarySource;
     SetSourceProperties();
 }
 public ActiveEvent(AudioEvent audioEvent, GameObject emitter, AudioSource primarySource, AudioSource secondarySource, string messageOnAudioEnd = null)
 {
     this.audioEvent   = audioEvent;
     AudioEmitter      = emitter;
     PrimarySource     = primarySource;
     SecondarySource   = secondarySource;
     MessageOnAudioEnd = messageOnAudioEnd;
     SetSourceProperties();
 }
Beispiel #3
0
        public void Initialize(AudioEvent audioEvent, GameObject emitter, AudioSource primarySource = null, AudioSource secondarySource = null)
        {
            this.audioEvent = audioEvent;
            AudioEmitter    = emitter;

            audioSourcesReference = AudioEmitter.GetComponent <AudioSourcesReference>();

            if (audioSourcesReference == null)
            {
                audioSourcesReference = AudioEmitter.AddComponent <AudioSourcesReference>();
            }

            SetEventProperties();

            this.PrimarySource   = primarySource;
            this.SecondarySource = secondarySource;

            initialized = true;
        }
Beispiel #4
0
        /// <summary>
        /// Set the volume, spatialization, etc., on our AudioSources to match the settings on the event to play.
        /// </summary>
        private void SetSourceProperties()
        {
            Action <Action <AudioSource> > forEachSource = (action) =>
            {
                action(PrimarySource);
                if (SecondarySource != null)
                {
                    action(SecondarySource);
                }
            };

            AudioEvent audioEvent = this.audioEvent;

            switch (audioEvent.spatialization)
            {
            case SpatialPositioningType.TwoD:
                forEachSource((source) =>
                {
                    source.spatialBlend = 0f;
                    source.spatialize   = false;
                });
                break;

            case SpatialPositioningType.ThreeD:
                forEachSource((source) =>
                {
                    source.spatialBlend = 1f;
                    source.spatialize   = false;
                });
                break;

            case SpatialPositioningType.SpatialSound:
                forEachSource((source) =>
                {
                    source.spatialBlend = 1f;
                    source.spatialize   = true;
                });
                break;

            default:
                Debug.LogErrorFormat("Unexpected spatialization type: {0}", audioEvent.spatialization.ToString());
                break;
            }

            if (audioEvent.spatialization == SpatialPositioningType.SpatialSound)
            {
                CreateFlatSpatialRolloffCurve();
                forEachSource((source) =>
                {
                    source.rolloffMode = AudioRolloffMode.Custom;
                    source.SetCustomCurve(AudioSourceCurveType.CustomRolloff, SpatialRolloff);
                    SpatialSoundSettings.SetRoomSize(source, audioEvent.roomSize);
                    SpatialSoundSettings.SetMinGain(source, audioEvent.minGain);
                    SpatialSoundSettings.SetMaxGain(source, audioEvent.maxGain);
                    SpatialSoundSettings.SetUnityGainDistance(source, audioEvent.unityGainDistance);
                });
            }
            else
            {
                forEachSource((source) =>
                {
                    source.rolloffMode = AudioRolloffMode.Logarithmic;
                });
            }

            if (audioEvent.bus != null)
            {
                forEachSource((source) => source.outputAudioMixerGroup = audioEvent.bus);
            }

            float pitch = 1f;

            if (audioEvent.pitchRandomization != 0)
            {
                pitch = UnityEngine.Random.Range(audioEvent.pitchCenter - audioEvent.pitchRandomization, audioEvent.pitchCenter + audioEvent.pitchRandomization);
            }
            else
            {
                pitch = audioEvent.pitchCenter;
            }
            forEachSource((source) => source.pitch = pitch);

            float vol = 1f;

            if (audioEvent.fadeInTime > 0)
            {
                forEachSource((source) => source.volume = 0f);
                this.currentFade = audioEvent.fadeInTime;
                if (audioEvent.volumeRandomization != 0)
                {
                    vol = UnityEngine.Random.Range(audioEvent.volumeCenter - audioEvent.volumeRandomization, audioEvent.volumeCenter + audioEvent.volumeRandomization);
                }
                else
                {
                    vol = audioEvent.volumeCenter;
                }
                this.volDest = vol;
            }
            else
            {
                if (audioEvent.volumeRandomization != 0)
                {
                    vol = UnityEngine.Random.Range(audioEvent.volumeCenter - audioEvent.volumeRandomization, audioEvent.volumeCenter + audioEvent.volumeRandomization);
                }
                else
                {
                    vol = audioEvent.volumeCenter;
                }
                forEachSource((source) => source.volume = vol);
            }

            float pan = audioEvent.panCenter;

            if (audioEvent.panRandomization != 0)
            {
                pan = UnityEngine.Random.Range(audioEvent.panCenter - audioEvent.panRandomization, audioEvent.panCenter + audioEvent.panRandomization);
            }
            forEachSource((source) => source.panStereo = pan);
        }
Beispiel #5
0
        /// <summary>
        /// Set the volume, spatialization, etc., on our AudioSources to match the settings on the event to play.
        /// </summary>
        private void SetSourceProperties()
        {
            Action <Action <AudioSource> > forEachSource = (action) =>
            {
                action(PrimarySource);
                if (SecondarySource != null)
                {
                    action(SecondarySource);
                }
            };

            AudioEvent audioEvent = AudioEvent;

            switch (audioEvent.Spatialization)
            {
            case SpatialPositioningType.TwoD:
                forEachSource((source) =>
                {
                    source.spatialBlend = 0f;
                    source.spatialize   = false;
                });
                break;

            case SpatialPositioningType.ThreeD:
                forEachSource((source) =>
                {
                    source.spatialBlend = 1f;
                    source.spatialize   = false;
                });
                break;

            case SpatialPositioningType.SpatialSound:
                forEachSource((source) =>
                {
                    source.spatialBlend = 1f;
                    source.spatialize   = true;
                });
                break;

            default:
                Debug.LogErrorFormat("Unexpected spatialization type: {0}", audioEvent.Spatialization.ToString());
                break;
            }

            if (audioEvent.Spatialization == SpatialPositioningType.SpatialSound)
            {
                forEachSource((source) =>
                {
                    SpatialSoundSettings.SetRoomSize(source, audioEvent.RoomSize);
                    source.rolloffMode = AudioRolloffMode.Custom;
                    source.maxDistance = audioEvent.MaxDistanceAttenuation3D;
                    source.SetCustomCurve(AudioSourceCurveType.CustomRolloff, audioEvent.AttenuationCurve);
                });
            }
            else
            {
                forEachSource((source) =>
                {
                    if (audioEvent.Spatialization == SpatialPositioningType.ThreeD)
                    {
                        source.rolloffMode = AudioRolloffMode.Custom;
                        source.maxDistance = audioEvent.MaxDistanceAttenuation3D;
                        source.SetCustomCurve(AudioSourceCurveType.CustomRolloff, audioEvent.AttenuationCurve);
                        source.SetCustomCurve(AudioSourceCurveType.SpatialBlend, audioEvent.SpatialCurve);
                        source.SetCustomCurve(AudioSourceCurveType.Spread, audioEvent.SpreadCurve);
                        source.SetCustomCurve(AudioSourceCurveType.ReverbZoneMix, audioEvent.ReverbCurve);
                    }
                    else
                    {
                        source.rolloffMode = AudioRolloffMode.Logarithmic;
                    }
                });
            }

            if (audioEvent.AudioBus != null)
            {
                forEachSource((source) => source.outputAudioMixerGroup = audioEvent.AudioBus);
            }

            float pitch = 1f;

            if (audioEvent.PitchRandomization != 0)
            {
                pitch = UnityEngine.Random.Range(audioEvent.PitchCenter - audioEvent.PitchRandomization, audioEvent.PitchCenter + audioEvent.PitchRandomization);
            }
            else
            {
                pitch = audioEvent.PitchCenter;
            }
            forEachSource((source) => source.pitch = pitch);

            float vol = 1f;

            if (audioEvent.FadeInTime > 0)
            {
                forEachSource((source) => source.volume = 0f);
                CurrentFade = audioEvent.FadeInTime;
                if (audioEvent.VolumeRandomization != 0)
                {
                    vol = UnityEngine.Random.Range(audioEvent.VolumeCenter - audioEvent.VolumeRandomization, audioEvent.VolumeCenter + audioEvent.VolumeRandomization);
                }
                else
                {
                    vol = audioEvent.VolumeCenter;
                }
                VolDest = vol;
            }
            else
            {
                if (audioEvent.VolumeRandomization != 0)
                {
                    vol = UnityEngine.Random.Range(audioEvent.VolumeCenter - audioEvent.VolumeRandomization, audioEvent.VolumeCenter + audioEvent.VolumeRandomization);
                }
                else
                {
                    vol = audioEvent.VolumeCenter;
                }
                forEachSource((source) => source.volume = vol);
            }

            float pan = audioEvent.PanCenter;

            if (audioEvent.PanRandomization != 0)
            {
                pan = UnityEngine.Random.Range(audioEvent.PanCenter - audioEvent.PanRandomization, audioEvent.PanCenter + audioEvent.PanRandomization);
            }
            forEachSource((source) => source.panStereo = pan);
        }