Exemple #1
0
        void Start()
        {
            SoundInstance sound = null;

            switch (_position)
            {
            case SoundPosition.TwoDimensional:
                sound = _soundBank.Play();
                break;

            case SoundPosition.TransformPosition:
                sound = _soundBank.Play(transform.position);
                break;

            case SoundPosition.FollowTransform:
                sound = _soundBank.Play(transform);
                break;
            }

            if (_loop)
            {
                EffectSoundInstance effectSound = sound as EffectSoundInstance;
                if (effectSound != null)
                {
                    effectSound.SetLooping(true);
                }
            }

            if (sound != null && _fadeInDuration > 0)
            {
                sound.FadeIn(_fadeInDuration, true);
            }
        }
        public SequenceSoundInstance AddSection(SequenceSoundBank.SectionData sectionData)
        {
            Assert.IsFalse(IsPooled, "Tried to use SoundInstance while in pool. Make sure not to keep references to SoundInstances that have been destroyed.");
            Assert.IsNotNull(sectionData);

            SoundInstance       sound       = sectionData.Sound.Fetch(_soundPool);
            EffectSoundInstance effectSound = sound as EffectSoundInstance;

            if (effectSound != null)
            {
                effectSound.SetLooping(sectionData.Loop);
            }

            sound.SetDelay(sectionData.Delay);
            sound.SetAutoDestroy(false);

            if (sectionData.Sound.IsClip)
            {
                effectSound.SetRolloffDistance(sectionData.RolloffDistance.Min, sectionData.RolloffDistance.Max);
            }

            _sectionSounds.Add(sound);
            _sectionData.Add(sectionData);

            RegisterChildSound(sound);

            return(this);
        }
        public AmbienceSoundInstance AddLoop(AmbienceSoundBank.LoopData loopData)
        {
            Assert.IsFalse(IsPooled, "Tried to use SoundInstance while in pool. Make sure not to keep references to SoundInstances that have been destroyed.");
            Assert.IsNotNull(loopData);

            SoundInstance       loop       = loopData.Sound.Fetch(_soundPool);
            EffectSoundInstance effectLoop = loop as EffectSoundInstance;

            if (effectLoop != null)
            {
                effectLoop.SetLooping(true);
            }

            loop.SetDelay(_delayDuration);
            loop.SetAutoDestroy(false);

            if (loopData.Sound.IsClip)
            {
                effectLoop.SetRolloffDistance(loopData.RolloffDistance.Min, loopData.RolloffDistance.Max);
            }

            _loopSounds.Add(loop);
            _loopData.Add(loopData);
            _loopSeeds.Add(Random.value);

            RegisterChildSound(loop);

            return(this);
        }
        public override void OnAdded(EffectSoundInstance sound)
        {
            base.OnAdded(sound);

            for (int i = 0; i < _filterComponents.Count; i++)
            {
                _filterComponents[i].distortionLevel = distortionLevel;
            }
        }
        public override void OnAdded(EffectSoundInstance sound)
        {
            base.OnAdded(sound);

            for (int i = 0; i < _filterComponents.Count; i++)
            {
                _filterComponents[i].cutoffFrequency   = cutoffFrequency;
                _filterComponents[i].lowpassResonanceQ = lowpassResonanceQ;
            }
        }
        public override void UpdateSound(float deltaTime)
        {
            Assert.IsFalse(IsPooled, "Tried to use SoundInstance while in pool. Make sure not to keep references to SoundInstances that have been destroyed.");

            base.UpdateSound(deltaTime);

            if (_state == State.Playing)
            {
                SoundInstance currentSound = GetCurrentSound();

                if (currentSound.HasFinished)
                {
                    if (HasNextSection)
                    {
                        PlayNextSection();
                    }
                    else
                    {
                        Finish();
                    }
                }
                else if (HasNextSection)
                {
                    SequenceSoundBank.SectionData nextData = GetNextData();
                    float delay = nextData == null ? 0 : nextData.Delay;

                    if (delay < 0)
                    {
                        EffectSoundInstance effectSound = currentSound as EffectSoundInstance;
                        if (effectSound != null && effectSound.TimeRemaining < Mathf.Abs(delay))
                        {
                            _effectiveSectionIndex++;
                            GetCurrentSound().Play(_positionMode, _followTransform, transform.position);
                        }
                    }
                }

                if (!HasFinished)
                {
                    currentSound = GetCurrentSound();
                    if (!currentSound.IsPlaying)
                    {
                        currentSound.Play(_positionMode, _followTransform, transform.position);
                    }

                    currentSound.SetParentMultipliers(_volumeMultiplier * _parentVolumeMultiplier, _pitchMultiplier * _parentPitchMultiplier);
                }
            }

            if (HasFinished && _autoDestroy)
            {
                StopAndDestroy();
            }
        }
Exemple #7
0
        public override void OnAdded(EffectSoundInstance sound)
        {
            base.OnAdded(sound);

            for (int i = 0; i < _filterComponents.Count; i++)
            {
                _filterComponents[i].delay      = delay;
                _filterComponents[i].decayRatio = decayRatio;
                _filterComponents[i].wetMix     = wetMix;
                _filterComponents[i].dryMix     = dryMix;
            }
        }
Exemple #8
0
        /// <summary>
        /// Fetches and then plays a sound that will follow a transform around.
        /// </summary>
        /// <param name="followTransform">The transform to follow</param>
        public static EffectSoundInstance Play(this EffectSoundBank soundBank, Transform followTransform)
        {
            if (soundBank != null && (soundBank.Cooldown <= 0 || soundBank.TimeSinceLastPlayed > soundBank.Cooldown))
            {
                EffectSoundInstance sound = soundBank.Fetch(RuntimeSoundPool.Instance);
                sound.Play3D(followTransform);
                soundBank.OnPlayed(sound);

                return(sound);
            }

            return(null);
        }
Exemple #9
0
        /// <summary>
        /// Fetches and then plays a sound at a specific position.
        /// </summary>
        /// <param name="position">The world-space position of the sound emission</param>
        public static EffectSoundInstance Play(this EffectSoundBank soundBank, Vector3 position)
        {
            if (soundBank != null && (soundBank.Cooldown <= 0 || soundBank.TimeSinceLastPlayed > soundBank.Cooldown))
            {
                EffectSoundInstance sound = soundBank.Fetch(RuntimeSoundPool.Instance);
                sound.Play3D(position);
                soundBank.OnPlayed(sound);

                return(sound);
            }

            return(null);
        }
Exemple #10
0
        /// <summary>
        /// Fetches and then plays a non-spatial sound, ie. one that does not emit from a specific location and rolloff.
        /// </summary>
        /// <param name="soundBank">The sound bank used to set-up the sound instance</param>
        public static EffectSoundInstance Play(this ImpactSoundBank soundBank, float velocity)
        {
            if (soundBank != null && soundBank.TimeSinceLastPlayed > soundBank.Cooldown)
            {
                EffectSoundInstance sound = soundBank.Fetch(RuntimeSoundPool.Instance, velocity);
                sound.Play2D();
                soundBank.OnPlayed(sound);

                return(sound);
            }

            return(null);
        }
Exemple #11
0
        public override SoundInstance TestInEditor(ISoundPool soundPool)
        {
            EffectSoundInstance sound = Fetch(soundPool);

            if (sound != null && (_cooldown <= 0 || TimeSinceLastPlayed > _cooldown))
            {
                sound.Play2D();
                OnPlayed(sound);

                return(sound);
            }

            return(null);
        }
        public override void OnAdded(EffectSoundInstance sound)
        {
            base.OnAdded(sound);

            for (int i = 0; i < _filterComponents.Count; i++)
            {
                _filterComponents[i].dryMix  = dryMix;
                _filterComponents[i].wetMix1 = wetMix1;
                _filterComponents[i].wetMix2 = wetMix2;
                _filterComponents[i].wetMix3 = wetMix3;
                _filterComponents[i].delay   = delay;
                _filterComponents[i].rate    = rate;
                _filterComponents[i].depth   = depth;
            }
        }
Exemple #13
0
        public EffectSoundInstance Fetch(ISoundPool soundPool)
        {
            EffectSoundInstance sound = soundPool.FetchFromPool <EffectSoundInstance>();

            sound.name = name;
            sound.SetClip(GetNextClip());
            sound.SetRolloffDistance(_rolloffDistance.Min, _rolloffDistance.Max);
            sound.SetMixerGroup(_outputMixer);
            sound.SetBaseVolume(_volumeRange.ChooseRandom());
            sound.SetBasePitch(_pitchRange.ChooseRandom());

            AddFilters(sound);

            return(sound);
        }
        public override void OnRemoved(EffectSoundInstance sound)
        {
            base.OnRemoved(sound);

            for (int i = 0; i < _filterComponents.Count; i++)
            {
                if (_filterComponents[i] == null)
                {
                    _filterComponents.RemoveAt(i);
                    i--;
                }
            }

            T component = sound.GetComponent <T>();

            if (component != null)
            {
                component.enabled = false;
                _filterComponents.Remove(component);
            }
        }
Exemple #15
0
        public SoundInstance Fetch(ISoundPool pool)
        {
            if (IsEmpty)
            {
                return(null);
            }

            if (_isBank)
            {
                Type type = _soundBank.GetType();
                if (type == typeof(AmbienceSoundBank))
                {
                    return((_soundBank as AmbienceSoundBank).Fetch(pool));
                }
                if (type == typeof(BlendSoundBank))
                {
                    return((_soundBank as BlendSoundBank).Fetch(pool));
                }
                if (type == typeof(EffectSoundBank))
                {
                    return((_soundBank as EffectSoundBank).Fetch(pool));
                }
                if (type == typeof(ImpactSoundBank))
                {
                    return((_soundBank as ImpactSoundBank).Fetch(pool, 0f));
                }
                if (type == typeof(SequenceSoundBank))
                {
                    return((_soundBank as SequenceSoundBank).Fetch(pool));
                }

                throw new NotImplementedException("SoundBank type not implemented: " + type);
            }

            EffectSoundInstance sound = pool.FetchFromPool <EffectSoundInstance>();

            sound.SetClip(_audioClip);

            return(sound);
        }
        public override void OnAdded(EffectSoundInstance sound)
        {
            base.OnAdded(sound);

            for (int i = 0; i < _filterComponents.Count; i++)
            {
                if (_filterComponents[i] == null)
                {
                    _filterComponents.RemoveAt(i);
                    i--;
                }
            }

            T component = sound.GetComponent <T>();

            if (component == null)
            {
                component = sound.gameObject.AddComponent <T>();
            }

            _filterComponents.Add(component);
            component.enabled = true;
        }
        public override void OnAdded(EffectSoundInstance sound)
        {
            base.OnAdded(sound);

            for (int i = 0; i < _filterComponents.Count; i++)
            {
                _filterComponents[i].reverbPreset     = reverbPreset;
                _filterComponents[i].dryLevel         = dryLevel;
                _filterComponents[i].room             = room;
                _filterComponents[i].roomHF           = roomHF;
                _filterComponents[i].roomLF           = roomLF;
                _filterComponents[i].decayTime        = decayTime;
                _filterComponents[i].decayHFRatio     = decayHFRatio;
                _filterComponents[i].reflectionsLevel = reflectionsLevel;
                _filterComponents[i].reflectionsDelay = reflectionsDelay;
                _filterComponents[i].reverbLevel      = reverbLevel;
                _filterComponents[i].reverbDelay      = reverbDelay;
                _filterComponents[i].hfReference      = HFReference;
                _filterComponents[i].lfReference      = LFReference;
                _filterComponents[i].diffusion        = diffusion;
                _filterComponents[i].density          = density;
            }
        }
Exemple #18
0
 public virtual void OnAdded(EffectSoundInstance sound)
 {
 }
Exemple #19
0
 public virtual void OnRemoved(EffectSoundInstance sound)
 {
 }