コード例 #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 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);
         }
     }
 }