示例#1
0
        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);
        }
示例#2
0
        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();
            }
        }