Пример #1
0
        private void InitAudioSource(AudioSource audioSource)
        {
            if (_audioSourcesCache.ContainsKey(audioSource))
            {
                return;
            }

            AudioSourceData data = new AudioSourceData
            {
                audioSource   = audioSource,
                defaultPitch  = audioSource.pitch,
                defaultVolume = audioSource.volume
            };

            _audioSourcesCache.Add(audioSource, data);
        }
Пример #2
0
        //----------- Public Events -----------

        // TODO: Figure out how will this work if there are multiple paremeters affecting the same audio property.
        public static void SetParameter(AudioEvent audioEvent, AudioParameterData audioParameterData, AudioSourceData audioSourceData, float parameterValue)
        {
            for (int i = 0; i < audioParameterData.audioPropertyCurves.Count; ++i)
            {
                AudioParameterData.AudioPropertyCurve audioPropertyCurve = audioParameterData.audioPropertyCurves[i];
                bool  validAudioProperty = true;
                float value = audioPropertyCurve.curve.Evaluate(parameterValue);

                // TODO: Clamp values;
                switch (audioPropertyCurve.audioProperty)
                {
                case AudioProperty.VOLUME:
                    audioEvent.audioSource.volume = audioEvent.volume * value;
                    break;

                case AudioProperty.PITCH:
                    audioEvent.audioSource.pitch = audioEvent.pitch * value;
                    break;

                default:
                    validAudioProperty = false;
                    break;
                }

                if (validAudioProperty)
                {
                    audioEvent.StoreAudioPropertyValue(audioPropertyCurve.audioProperty, value);
                }
            }
        }