コード例 #1
0
        /// <summary>
        /// Plays the sound of the given name with the given parameters.
        /// </summary>
        /// <param name="soundName">Name of the sound</param>
        /// <param name="volume">Volume, 0.0f to 1.0f</param>
        /// <param name="pitch">Pitch, -1.0f (down one octave) to 1.0f (up one octave)</param>
        /// <param name="pan">Pan, -1.0f (full left) to 1.0f (full right)</param>
        public void PlaySound(string soundName, float volume, float pitch, float pan, I3DSound owner = null, int loopAmnt = 0, bool isStoppable = true)
        {
            SoundEffect sound;

            if (!_sounds.TryGetValue(soundName, out sound))
            {
                throw new ArgumentException(string.Format("Sound '{0}' not found", soundName));
            }

            int index = GetAvailableSoundIndex();
            _playingSounds[index].keyName = soundName;
            _playingSounds[index].owner = owner;
            _playingSounds[index].isStoppable = isStoppable;
            if (index != -1)
            {
                _playingSounds[index].instance = sound.CreateInstance();
                _playingSounds[index].instance.Volume = volume;
                _playingSounds[index].instance.Pitch = pitch;
                _playingSounds[index].instance.Pan = pan;
                if(loopAmnt == -1)
                    _playingSounds[index].instance.IsLooped = true;
                if (owner != null && owner.GetAudioEmitter() != null)
                {
                    _playingSounds[index].instance.Apply3D(NormalizedListener(Player.PlayerListener),
                        NormalizedEmitter(owner.GetAudioEmitter()));
                }

                _playingSounds[index].instance.Play();

                if (loopAmnt > 0)
                {
                    loopingEffects.Add(_playingSounds[index].instance, new SoundLoopInfo(loopAmnt));
                }

                if (!Enabled)
                {
                    _playingSounds[index].instance.Pause();
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Plays the sound of the given name at the given volume.
 /// </summary>
 /// <param name="soundName">Name of the sound</param>
 /// <param name="volume">Volume, 0.0f to 1.0f</param>
 public void PlaySound(string soundName, float volume, I3DSound owner = null, int loopAmnt = 0, bool isStoppable = true)
 {
     PlaySound(soundName, volume, 0.0f, 0.0f, owner, loopAmnt, isStoppable);
 }