コード例 #1
0
        public void Update()
        {
            bool validSoundIsPlaying = m_sound != null && m_sound.IsPlaying;

            if (!CanHearSound())
            {
                if (validSoundIsPlaying)
                {
                    StopSound(true, false);
                    m_sound = null;
                }
                return;
            }
            else if (!validSoundIsPlaying && Loop)
            {
                PlaySound(m_closeSoundSoundPair, true, true);
            }
            else if (validSoundIsPlaying && Loop && m_playing2D != ShouldPlay2D() && ((Force2D == true && m_playing2D == false) || (Force3D == true && m_playing2D == true)))
            {
                StopSound(true, false);
                PlaySound(m_closeSoundSoundPair, true, true);
            }
            else if (validSoundIsPlaying && Loop && m_playing2D == false && m_usesDistanceSounds)
            {
                MyCueId oldSecondary = (m_secondaryEnabled ? m_secondaryCueEnum : myEmptyCueId);
                MyCueId newSound     = CheckDistanceSounds(m_closeSoundCueId);
                if (newSound != m_cueEnum || oldSecondary != m_secondaryCueEnum)
                {
                    PlaySoundWithDistance(newSound, true, true, useDistanceCheck: false);
                }
                else if (m_secondaryEnabled)
                {
                    if (Sound != null)
                    {
                        Sound.SetVolume(RealisticVolumeChange * m_baseVolume * (1f - m_secondaryVolumeRatio));
                    }
                    if (m_secondarySound != null)
                    {
                        m_secondarySound.SetVolume(RealisticVolumeChange * m_secondaryBaseVolume * m_secondaryVolumeRatio);
                    }
                }
            }
            if (validSoundIsPlaying && Loop)
            {
                //arcade/real sound change
                MyCueId newCueId = SelectCue(m_soundPair);
                if (newCueId.Equals(m_cueEnum) == false)
                {
                    PlaySoundWithDistance(newCueId, true, true);
                }

                //active filter changed
                MyStringHash newEffect = SelectEffect();
                if (m_activeEffect != newEffect)
                {
                    PlaySoundWithDistance(newCueId, true, true);
                }
            }
        }
コード例 #2
0
        public void Update()
        {
            if (m_frameCounter % 60 == 0)
            {
                Update_1s();
            }

            if (MusicIsPlaying)
            {
                m_musicSourceVoice.SetVolume(m_lastMusicData != null ? MyAudio.Static.VolumeMusic * m_lastMusicData.Volume: MyAudio.Static.VolumeMusic);
            }
            else
            {
                if (m_noMusicTimer > 0f)
                {
                    m_noMusicTimer -= MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
                }
                else
                {
                    if (m_fightHeavy >= FIGHTING_NEED)
                    {
                        m_currentMusicCategory = MusicCategory.heavyFight;
                    }
                    else if (m_fightLight >= FIGHTING_NEED)
                    {
                        m_currentMusicCategory = MusicCategory.lightFight;
                    }
                    else if (m_meteorShower > 0)
                    {
                        m_currentMusicCategory = MusicCategory.danger;
                    }
                    else if (m_building >= BUILDING_NEED)
                    {
                        m_currentMusicCategory = MusicCategory.building;
                    }
                    else
                    {
                        m_currentMusicCategory = MusicCategory.location;
                    }

                    switch (m_currentMusicCategory)
                    {
                    case MusicCategory.building:
                        PlayBuildingMusic();
                        break;

                    case MusicCategory.danger:
                        PlayDangerMusic();
                        break;

                    default:
                        CalculateNextCue();
                        break;
                    }
                }
            }

            m_frameCounter++;
        }
コード例 #3
0
 private void PlaySoundInternal(bool skipIntro = false, bool skipToEnd = false, bool force2D = false, bool alwaysHearOnRealistic = false)
 {
     Force2D = force2D;
     m_alwaysHearOnRealistic = alwaysHearOnRealistic;
     m_playing2D             = (ShouldPlay2D() && !Force3D) || force2D || Force2D;
     Loop = MyAudio.Static.IsLoopable(SoundId) && !skipToEnd;
     if (!SoundId.IsNull)
     {
         if (Loop && MySession.Static.ElapsedPlayTime.TotalSeconds < 6)
         {
             skipIntro = true;
         }
         if (m_playing2D && CheckForSynchronizedSounds())
         {
             Sound = MyAudio.Static.PlaySound(SoundId, this, MySoundDimensions.D2, skipIntro, skipToEnd);
         }
         else if (CanHearSound() && CheckForSynchronizedSounds()) //Start 3D sound only if can be heard
         {
             Sound = MyAudio.Static.PlaySound(SoundId, this, MySoundDimensions.D3, skipIntro, skipToEnd);
         }
     }
     if (Sound != null && Sound.IsPlaying)
     {
         if (MyMusicController.Static != null && m_lastSoundData != null && m_lastSoundData.DynamicMusicCategory != MyStringId.NullOrEmpty && m_lastSoundData.DynamicMusicAmount > 0)
         {
             MyMusicController.Static.IncreaseCategory(m_lastSoundData.DynamicMusicCategory, m_lastSoundData.DynamicMusicAmount);
         }
         m_baseVolume = Sound.Volume;
         Sound.SetVolume(Sound.Volume * RealisticVolumeChange);
         if (m_secondaryEnabled && m_secondaryCueEnum != null)
         {
             m_secondarySound = MyAudio.Static.PlaySound(m_secondaryCueEnum, this, MySoundDimensions.D3, skipIntro, skipToEnd);
             if (Sound == null)
             {
                 return;
             }
             if (m_secondarySound != null)
             {
                 m_secondaryBaseVolume = m_secondarySound.Volume;
                 Sound.SetVolume(RealisticVolumeChange * m_baseVolume * (1f - m_secondaryVolumeRatio));
                 m_secondarySound.SetVolume(RealisticVolumeChange * m_secondaryBaseVolume * m_secondaryVolumeRatio);
                 m_secondarySound.VolumeMultiplier = m_volumeMultiplier;
             }
         }
         Sound.VolumeMultiplier = m_volumeMultiplier;
         Sound.StoppedPlaying   = OnStopPlaying;
         if (EmitterMethods[MethodsEnum.ImplicitEffect].Count > 0)
         {
             m_activeEffect = MyStringHash.NullOrEmpty;
             var effectId = ((Func <MyStringHash>)EmitterMethods[MethodsEnum.ImplicitEffect][0])();
             if (effectId != MyStringHash.NullOrEmpty)
             {
                 var effect = MyAudio.Static.ApplyEffect(Sound, effectId);
                 if (effect != null)
                 {
                     Sound          = effect.OutputSound;
                     m_activeEffect = effectId;
                 }
             }
         }
     }
     else
     {
         OnStopPlaying();
     }
 }
コード例 #4
0
 private void PlaySoundInternal(bool skipIntro = false, bool skipToEnd = false, bool force2D = false, bool alwaysHearOnRealistic = false)
 {
     Force2D = force2D;
     m_alwaysHearOnRealistic = alwaysHearOnRealistic;
     m_playing2D = (ShouldPlay2D() && !Force3D) || force2D || Force2D;
     Loop = MyAudio.Static.IsLoopable(SoundId) && !skipToEnd;
     if (!SoundId.IsNull)
     {
         if (Loop && MySession.Static.ElapsedPlayTime.TotalSeconds < 6)
             skipIntro = true;
         if (m_playing2D && CheckForSynchronizedSounds())
             Sound = MyAudio.Static.PlaySound(SoundId, this, MySoundDimensions.D2, skipIntro, skipToEnd);
         else if (CanHearSound() && CheckForSynchronizedSounds()) //Start 3D sound only if can be heard
             Sound = MyAudio.Static.PlaySound(SoundId, this, MySoundDimensions.D3, skipIntro, skipToEnd);
     }
     if (Sound != null && Sound.IsPlaying)
     {
         if (MyMusicController.Static != null && m_lastSoundData != null && m_lastSoundData.DynamicMusicCategory != MyStringId.NullOrEmpty && m_lastSoundData.DynamicMusicAmount > 0)
             MyMusicController.Static.IncreaseCategory(m_lastSoundData.DynamicMusicCategory, m_lastSoundData.DynamicMusicAmount);
         m_baseVolume = Sound.Volume;
         Sound.SetVolume(Sound.Volume * RealisticVolumeChange);
         if (m_secondaryEnabled && m_secondaryCueEnum != null)
         {
             m_secondarySound = MyAudio.Static.PlaySound(m_secondaryCueEnum, this, MySoundDimensions.D3, skipIntro, skipToEnd);
             if (Sound == null)
                 return;
             if (m_secondarySound != null)
             {
                 m_secondaryBaseVolume = m_secondarySound.Volume;
                 Sound.SetVolume(RealisticVolumeChange * m_baseVolume * (1f - m_secondaryVolumeRatio));
                 m_secondarySound.SetVolume(RealisticVolumeChange * m_secondaryBaseVolume * m_secondaryVolumeRatio);
                 m_secondarySound.VolumeMultiplier = m_volumeMultiplier;
             }
         }
         Sound.VolumeMultiplier = m_volumeMultiplier;
         Sound.StoppedPlaying = OnStopPlaying;
         if (EmitterMethods[MethodsEnum.ImplicitEffect].Count > 0)
         {
             m_activeEffect = MyStringHash.NullOrEmpty;
             var effectId = ((Func<MyStringHash>)EmitterMethods[MethodsEnum.ImplicitEffect][0])();
             if (effectId != MyStringHash.NullOrEmpty)
             {
                 var effect = MyAudio.Static.ApplyEffect(Sound, effectId);
                 if (effect != null)
                 {
                     Sound = effect.OutputSound;
                     m_activeEffect = effectId;
                 }
             }
         }
     }
     else
         OnStopPlaying();
 }
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            if (MySandboxGame.IsDedicated)
            {
                return;
            }

            if (m_volumeModifier != m_volumeModifierTarget)
            {
                if (m_volumeModifier < m_volumeModifierTarget)
                {
                    m_volumeModifier = MyMath.Clamp(m_volumeModifier + MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * VOLUME_CHANGE_SPEED, 0f, m_volumeModifierTarget);
                }
                else
                {
                    m_volumeModifier = MyMath.Clamp(m_volumeModifier - MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * VOLUME_CHANGE_SPEED, m_volumeModifierTarget, 1f);
                }
                if (m_sound != null && m_sound.IsPlaying)
                {
                    m_sound.SetVolume(m_volumeOriginal * m_volumeModifier * VolumeModifierGlobal);
                }
            }

            long currentFrame = MySession.Static.GameplayFrameCounter;

            if (currentFrame >= m_nextPlanetRecalculation)
            {
                Planet = FindNearestPlanet(MySector.MainCamera.Position);
                if (Planet == null)
                {
                    m_nextPlanetRecalculation = currentFrame + m_planetRecalculationIntervalInSpace;
                }
                else
                {
                    m_nextPlanetRecalculation = currentFrame + m_planetRecalculationIntervalOnPlanet;
                }
            }

            if (Planet == null || Planet.Provider == null || (MyFakes.ENABLE_NEW_SOUNDS && MySession.Static.Settings.RealisticSound && Planet.HasAtmosphere == false))
            {
                if (m_sound != null)
                {
                    m_sound.Stop(true);
                }
                return;
            }
            Vector3D localPosition    = MySector.MainCamera.Position - Planet.PositionComp.GetPosition();
            double   distanceToCenter = localPosition.Length();

            float height = Planet.Provider.Shape.DistanceToRatio((float)distanceToCenter);

            if (height < 0)
            {
                return;
            }

            Vector3D gravity = -localPosition / distanceToCenter;

            float angleFromEquator   = (float)-gravity.Y;
            float sunAngleFromZenith = (float)MySector.DirectionToSunNormalized.Dot(-gravity);

            int ruleIndex;

            if (!FindSoundRuleIndex(angleFromEquator, height, sunAngleFromZenith, m_nearestSoundRules, out ruleIndex))
            {
                PlaySound(new MyCueId());
                return;
            }

            PlaySound(new MyCueId(m_nearestSoundRules[ruleIndex].EnvironmentSound));
        }