private void PlaySound(MyCueId sound)
        {
            if (m_sound == null || !m_sound.IsPlaying)
            {
                m_sound = MyAudio.Static.PlaySound(sound);
                if (!sound.IsNull)
                {
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeIn, null);
                }
                if (m_effect != null)
                {
                    m_sound = m_effect.OutputSound;
                }
            }
            else if (m_effect != null && m_effect.Finished && sound.IsNull)
            {
                m_sound.Stop(true);
            }
            else if (m_sound.CueEnum != sound)
            {
                if (m_effect != null && !m_effect.Finished)
                {
                    //m_effect.SetPositionRelative(1f);
                    m_effect.AutoUpdate = true;
                }
                if (sound.IsNull)
                {
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeOut, null, 5000f);
                }
                else
                {
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_crossFade, new MyCueId[] { sound }, 5000f);
                }

                if (m_effect != null && !m_effect.Finished)
                {
                    m_effect.AutoUpdate = true;
                    m_sound             = m_effect.OutputSound;
                }
            }
            if (m_sound != null)
            {
                MySoundData data = MyAudio.Static.GetCue(sound);
                m_volumeOriginal = data != null ? data.Volume :1f;
                m_sound.SetVolume(m_volumeOriginal * m_volumeModifier * VolumeModifierGlobal);
            }
        }
Exemplo n.º 2
0
 private void PlaySound(MyCueId soundId, bool useCrossfade)
 {
     if (((this.m_sound != null) && this.m_sound.IsPlaying) & useCrossfade)
     {
         MyCueId[]      cueIds = new MyCueId[] { soundId };
         IMyAudioEffect effect = MyAudio.Static.ApplyEffect(this.m_sound, MyStringHash.GetOrCompute("CrossFade"), cueIds, new float?((float)0x7d0), false);
         this.m_sound = effect.OutputSound;
     }
     else
     {
         if (this.m_sound != null)
         {
             this.m_sound.Stop(true);
         }
         this.m_sound = MyAudio.Static.PlaySound(soundId, null, MySoundDimensions.D2, false, false);
     }
 }
 private void PlaySound(MyCueId sound)
 {
     if (m_sound == null || !m_sound.IsPlaying)
     {
         m_sound = MyAudio.Static.PlaySound(sound);
         if (!sound.IsNull)
         {
             m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeIn, null);
         }
         if (m_effect != null)
         {
             m_sound = m_effect.OutputSound;
         }
     }
     else if (m_sound.CueEnum != sound)
     {
         if (m_effect != null && !m_effect.Finished)
         {
             //m_effect.SetPositionRelative(1f);
             m_effect.AutoUpdate = true;
         }
         if (!sound.IsNull)
         {
             m_effect = MyAudio.Static.ApplyEffect(m_sound, m_crossFade, new MyCueId[] { sound }, 5000f);
         }
         if (m_effect != null && !m_effect.Finished)
         {
             m_effect.AutoUpdate = true;
             m_sound             = m_effect.OutputSound;
         }
         else
         {
             m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeOut, null, 5000f);
         }
     }
 }
        private void PlaySound(MyCueId sound)
        {
            if (m_sound == null || !m_sound.IsPlaying)
            {
                m_sound = MyAudio.Static.PlaySound(sound);
                if (!sound.IsNull)
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeIn, null);
                if (m_effect != null)
                    m_sound = m_effect.OutputSound;
            }
            else if (m_effect != null && m_effect.Finished && sound.IsNull)
                m_sound.Stop(true);
            else if (m_sound.CueEnum != sound)
            {
                if (m_effect != null && !m_effect.Finished)
                {
                    //m_effect.SetPositionRelative(1f);
                    m_effect.AutoUpdate = true;
                }
                if (sound.IsNull)
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeOut, null, 5000f);
                else
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_crossFade, new MyCueId[] { sound }, 5000f);

                if (m_effect != null && !m_effect.Finished)
                {
                    m_effect.AutoUpdate = true;
                    m_sound = m_effect.OutputSound;
                }
            }
            if (m_sound != null)
            {
                MySoundData data = MyAudio.Static.GetCue(sound);
                m_volumeOriginal = data != null ? data.Volume :1f;
                m_sound.SetVolume(m_volumeOriginal * m_volumeModifier * VolumeModifierGlobal);
            }
        }
        private void PlaySound(MyCueId sound)
        {

            if (m_sound == null || !m_sound.IsPlaying)
            {
                m_sound = MyAudio.Static.PlaySound(sound);
                if(!sound.IsNull)
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeIn, null);
                if (m_effect != null)
                    m_sound = m_effect.OutputSound;
            }
            else if (m_sound.CueEnum != sound)
            {
                if (m_effect != null && !m_effect.Finished)
                {
                    //m_effect.SetPositionRelative(1f);
                    m_effect.AutoUpdate = true;
                }
                if(!sound.IsNull)
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_crossFade, new MyCueId[] { sound }, 5000f);
                if (m_effect != null && !m_effect.Finished)
                {
                    m_effect.AutoUpdate = true;
                    m_sound = m_effect.OutputSound;
                }
                else
                {
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeOut, null, 5000f);
                }
            }
        }
Exemplo n.º 6
0
 private void PlaySoundInternal(bool skipIntro = false, bool skipToEnd = false, bool force2D = false, bool alwaysHearOnRealistic = false, bool?force3D = new bool?())
 {
     this.Force2D = force2D;
     if (force3D != null)
     {
         this.Force3D = force3D.Value;
     }
     this.m_alwaysHearOnRealistic = alwaysHearOnRealistic;
     this.Loop = false;
     if (!this.SoundId.IsNull && this.CheckForSynchronizedSounds())
     {
         bool flag1;
         int  canPlayLoopSounds;
         if (!this.ShouldPlay2D() || this.Force3D)
         {
             flag1 = this.Force2D;
         }
         else
         {
             flag1 = true;
         }
         this.m_playing2D = flag1;
         if (!MyAudio.Static.IsLoopable(this.SoundId) || skipToEnd)
         {
             canPlayLoopSounds = 0;
         }
         else
         {
             canPlayLoopSounds = (int)this.CanPlayLoopSounds;
         }
         this.Loop = (bool)canPlayLoopSounds;
         if (this.Loop && (MySession.Static.ElapsedPlayTime.TotalSeconds < 6.0))
         {
             skipIntro = true;
         }
         if (this.m_playing2D)
         {
             this.Sound = MyAudio.Static.PlaySound(this.m_closeSoundCueId, this, MySoundDimensions.D2, skipIntro, skipToEnd);
         }
         else if (this.CanHearSound())
         {
             this.Sound = MyAudio.Static.PlaySound(this.SoundId, this, MySoundDimensions.D3, skipIntro, skipToEnd);
         }
     }
     if ((this.Sound == null) || !this.Sound.IsPlaying)
     {
         this.OnStopPlaying();
     }
     else
     {
         if (((MyMusicController.Static != null) && ((this.m_lastSoundData != null) && (this.m_lastSoundData.DynamicMusicCategory != MyStringId.NullOrEmpty))) && (this.m_lastSoundData.DynamicMusicAmount > 0))
         {
             MyMusicController.Static.IncreaseCategory(this.m_lastSoundData.DynamicMusicCategory, this.m_lastSoundData.DynamicMusicAmount);
         }
         this.m_baseVolume = this.Sound.Volume;
         this.Sound.SetVolume(this.Sound.Volume * this.RealisticVolumeChange);
         if (this.m_secondaryEnabled)
         {
             MyCueId secondaryCueEnum = this.m_secondaryCueEnum;
             this.m_secondarySound = MyAudio.Static.PlaySound(this.m_secondaryCueEnum, this, MySoundDimensions.D3, skipIntro, skipToEnd);
             if (this.Sound == null)
             {
                 return;
             }
             if (this.m_secondarySound != null)
             {
                 this.m_secondaryBaseVolume = this.m_secondarySound.Volume;
                 this.Sound.SetVolume((this.RealisticVolumeChange * this.m_baseVolume) * (1f - this.m_secondaryVolumeRatio));
                 this.m_secondarySound.SetVolume((this.RealisticVolumeChange * this.m_secondaryBaseVolume) * this.m_secondaryVolumeRatio);
                 this.m_secondarySound.VolumeMultiplier = this.m_volumeMultiplier;
             }
         }
         this.Sound.VolumeMultiplier = this.m_volumeMultiplier;
         this.Sound.StoppedPlaying   = new Action(this.OnStopPlaying);
         if (this.EmitterMethods[3].Count > 0)
         {
             this.m_activeEffect = MyStringHash.NullOrEmpty;
             MyStringHash hash = ((Func <MyStringHash>) this.EmitterMethods[3][0])();
             if (hash != MyStringHash.NullOrEmpty)
             {
                 float?         duration = null;
                 IMyAudioEffect effect   = MyAudio.Static.ApplyEffect(this.Sound, hash, null, duration, false);
                 if (effect != null)
                 {
                     this.Sound          = effect.OutputSound;
                     this.m_activeEffect = hash;
                 }
             }
         }
     }
 }