コード例 #1
0
        public void playSound(string soundName, Vector3 position)
        {
            if (streamingSound == null)
            {
                StreamingSource streamingSource = ContentManager.Get <StreamingSource>(soundName).Duplicate();
                streamingSource.Position = 0;
                streamingSound           = new StreamingSound(streamingSource, 1, 1, 0, true);
            }
            Vector3 vector3 = subsystemViews.Views[0].ActiveCamera.ViewPosition;
            float   f       = Vector3.Distance(position, vector3);

            if (f >= 10)
            {
                f = 0;
            }
            else
            {
                f = 1f - f / 10;
            }
            if (streamingSound.State == SoundState.Disposed || streamingSound.State == SoundState.Paused || streamingSound.State == SoundState.Stopped)
            {
                streamingSound.Play();
            }
            streamingSound.Volume = f;
        }
コード例 #2
0
 public static void StopMusic()
 {
     if (m_sound != null)
     {
         if (m_fadeSound != null)
         {
             m_fadeSound.Dispose();
         }
         m_fadeSound = m_sound;
         m_sound     = null;
     }
 }
コード例 #3
0
        public static void Update()
        {
            if (m_fadeSound != null)
            {
                m_fadeSound.Volume = MathUtils.Min(m_fadeSound.Volume - 0.33f * Volume * Time.FrameDuration, Volume);
                if (m_fadeSound.Volume <= 0f)
                {
                    m_fadeSound.Dispose();
                    m_fadeSound = null;
                }
            }
            if (m_sound != null && Time.FrameStartTime >= m_fadeStartTime)
            {
                m_sound.Volume = MathUtils.Min(m_sound.Volume + 0.33f * Volume * Time.FrameDuration, Volume);
            }
            if (m_currentMix == Mix.None || Volume == 0f)
            {
                StopMusic();
            }
            else if (m_currentMix == Mix.Menu && (Time.FrameStartTime >= m_nextSongTime || !IsPlaying))
            {
                float startPercentage = IsPlaying ? m_random.Float(0f, 0.75f) : 0f;
                switch (m_random.Int(0, 5))
                {
                case 0:
                    PlayMusic("Music/NativeAmericanFluteSpirit", startPercentage);
                    break;

                case 1:
                    PlayMusic("Music/AloneForever", startPercentage);
                    break;

                case 2:
                    PlayMusic("Music/NativeAmerican", startPercentage);
                    break;

                case 3:
                    PlayMusic("Music/NativeAmericanHeart", startPercentage);
                    break;

                case 4:
                    PlayMusic("Music/NativeAmericanPeaceFlute", startPercentage);
                    break;

                case 5:
                    PlayMusic("Music/NativeIndianChant", startPercentage);
                    break;
                }
                m_nextSongTime = Time.FrameStartTime + (double)m_random.Float(40f, 60f);
            }
        }
コード例 #4
0
 public static void PlayMusic(string name, float startPercentage)
 {
     if (string.IsNullOrEmpty(name))
     {
         StopMusic();
     }
     else
     {
         try
         {
             StopMusic();
             m_fadeStartTime = Time.FrameStartTime + 2.0;
             float           volume          = (m_fadeSound != null) ? 0f : Volume;
             StreamingSource streamingSource = ContentManager.Get <StreamingSource>(name).Duplicate();
             streamingSource.Position = (long)(MathUtils.Saturate(startPercentage) * (float)(streamingSource.BytesCount / streamingSource.ChannelsCount / 2)) / 16 * 16;
             m_sound = new StreamingSound(streamingSource, volume, 1f, 0f, isLooped: false, disposeOnStop: false, 1f);
             m_sound.Play();
         }
         catch
         {
             Log.Warning("Error playing music \"{0}\".", name);
         }
     }
 }