コード例 #1
0
        public void RecycleSound(SKSound sound)
        {
            if (sound == backgroundSound)
            {
                return;
            }

            int index = 0;

            while (index < playingSounds.Count)
            {
                if (playingSounds[index] == sound)
                {
                    break;
                }

                index++;
            }

            playingSounds.RemoveAt(index);

            if (availableSounds.Count + playingSounds.Count >= maxCapacity)
            {
                Destroy(sound.audioSource);
            }
            else
            {
                availableSounds.Push(sound);
            }
        }
コード例 #2
0
    /// <summary>
    /// used internally to recycle SKSounds and their AudioSources
    /// </summary>
    /// <param name="sound">Sound.</param>
    public void recycleSound(SKSound sound)
    {
        var index = 0;

        while (index < _playingSounds.Count)
        {
            if (_playingSounds[index] == sound)
            {
                break;
            }
            index++;
        }
        _playingSounds.RemoveAt(index);


        // if we are already over capacity dont recycle this sound but destroy it instead
        if (_availableSounds.Count + _playingSounds.Count >= maxCapacity)
        {
            Destroy(sound.audioSource);
        }
        else
        {
            _availableSounds.Push(sound);
        }
    }
コード例 #3
0
    /// <summary>
    /// used internally to recycle SKSounds and their AudioSources
    /// </summary>
    /// <param name="sound">Sound.</param>
    public void RecycleSound(SKSound sound)
    {
        // we dont recycle the BackgroundSound since it always stays alive
        if (sound == BackgroundSound || sound == OneShotSound)
        {
            return;
        }

        var index = 0;

        while (index < PlayingSounds.Count)
        {
            if (PlayingSounds[index] == sound)
            {
                break;
            }
            index++;
        }
        PlayingSounds.RemoveAt(index);


        // if we are already over capacity dont recycle this sound but destroy it instead
        if (AvailableSounds.Count + PlayingSounds.Count >= MaxCapacity)
        {
            Destroy(sound.AudioSource);
        }
        else
        {
            AvailableSounds.Push(sound);
        }
    }
コード例 #4
0
ファイル: SoundKit.cs プロジェクト: imec-int/arcadeGameJam
    /// <summary>
    /// used internally to recycle SKSounds and their AudioSources
    /// </summary>
    /// <param name="sound">Sound.</param>
    public void recycleSound(SKSound sound)
    {
        // we dont recycle the backgroundSound since it always stays alive
        if (sound == backgroundSound)
        {
            return;
        }

        var index = 0;

        while (index < _playingSounds.Count)
        {
            if (_playingSounds[index] == sound)
            {
                break;
            }
            index++;
        }
        _playingSounds.RemoveAt(index);


        // if we are already over capacity dont recycle this sound but destroy it instead
        if (_availableSounds.Count + _playingSounds.Count >= maxCapacity)
        {
            Destroy(sound.audioSource);
        }
        else
        {
            _availableSounds.Push(sound);
        }
    }
コード例 #5
0
    /// <summary>
    /// fetches any AudioSource it can find and uses the standard PlayOneShot to play. Use this if you don't require any
    /// extra control over a clip and don't care about when it completes. It avoids the call to StartCoroutine.
    /// nb. pan/pitch are not supported as the chosen AudioSource might be in use with another pan/pitch setting and Unity does not support setting
    /// them natively in PlayOneShot, so updating them here can result in bad audio.
    /// </summary>
    /// <param name="audioClip">Audio clip.</param>
    /// <param name="volumeScale">Volume scale.</param>
    public void playOneShot( AudioClip audioClip, float volumeScale = 1f )
    {
        if (oneShotSound == null)
            oneShotSound = new SKSound(this);

        oneShotSound.audioSource.PlayOneShot( audioClip, volumeScale * soundEffectVolume );
    }
コード例 #6
0
        public SKSound PlaySound(AudioClip audioClip, float volumeScale, float pitch, float pan)
        {
            SKSound sound = NextAvailableSound();

            sound.PlayAudioClip(audioClip, volumeScale * soundEffectVolume, pitch, pan);

            return(sound);
        }
コード例 #7
0
 private void checkSound(SKSound sound)
 {
     sound._elapsedTime += Time.deltaTime;
     if (sound._elapsedTime > sound.audioSource.clip.length)
     {
         sound.stop();
     }
 }
コード例 #8
0
    /// <summary>
    /// starts up the background music and optionally loops it. You can access the SKSound via the backgroundSound field.
    /// </summary>
    /// <param name="audioClip">Audio clip.</param>
    /// <param name="loop">If set to <c>true</c> loop.</param>
    public void playBackgroundMusic( AudioClip audioClip, float volume, bool loop = true )
    {
        if( backgroundSound == null )
            backgroundSound = new SKSound( this );

        backgroundSound.playAudioClip( audioClip, volume, 1f, 0f );
        backgroundSound.setLoop( loop );
    }
コード例 #9
0
        public SKSound PlaySoundLooped(AudioClip audioClip)
        {
            SKSound sound = NextAvailableSound();

            sound.PlayAudioClip(audioClip, soundEffectVolume, 1f, 0f);
            sound.SetLoop(true);

            return(sound);
        }
コード例 #10
0
    /// <summary>
    /// fetches any AudioSource it can find and uses the standard PlayOneShot to play. Use this if you don't require any
    /// extra control over a clip and don't care about when it completes. It avoids the call to StartCoroutine.
    /// nb. pan/pitch are not supported as the chosen AudioSource might be in use with another pan/pitch setting and Unity does not support setting
    /// them natively in PlayOneShot, so updating them here can result in bad audio.
    /// </summary>
    /// <param name="audioClip">Audio clip.</param>
    /// <param name="volumeScale">Volume scale.</param>
    public void playOneShot(AudioClip audioClip, float volumeScale = 1f, SoundType soundType = SoundType.SFX)
    {
        if (oneShotSound == null)
        {
            oneShotSound = new SKSound(this);
        }

        oneShotSound.audioSource.PlayOneShot(audioClip, volumeScale * getVolume(soundType));
    }
コード例 #11
0
ファイル: SoundKit.cs プロジェクト: imec-int/arcadeGameJam
    /// <summary>
    /// fetches any AudioSource it can find and uses the standard PlayOneShot to play. Use this if you don't require any
    /// extra control over a clip and don't care about when it completes. It avoids the call to StartCoroutine.
    /// nb. pan/pitch are not supported as the chosen AudioSource might be in use with another pan/pitch setting and Unity does not support setting
    /// them natively in PlayOneShot, so updating them here can result in bad audio.
    /// </summary>
    /// <param name="audioClip">Audio clip.</param>
    /// <param name="volumeScale">Volume scale.</param>
    public void playOneShot(AudioClip audioClip, float volumeScale = 1f)
    {
        if (oneShotSound == null)
        {
            oneShotSound = new SKSound(this);
        }

        oneShotSound.audioSource.PlayOneShot(audioClip, volumeScale * soundEffectVolume);
    }
コード例 #12
0
    /// <summary>
    /// plays the AudioClip with the specified volumeScale, pitch and pan
    /// </summary>
    /// <returns>The sound.</returns>
    /// <param name="audioClip">Audio clip.</param>
    /// <param name="volume">Volume.</param>
    /// <param name="pitch">Pitch.</param>
    /// <param name="pan">Pan.</param>
    public SKSound playSound(AudioClip audioClip, float volumeScale, float pitch, float pan, SoundType soundType = SoundType.SFX)
    {
        // Find the first SKSound not being used. if they are all in use, create a new one
        SKSound sound = nextAvailableSound();

        sound.playAudioClip(audioClip, volumeScale * getVolume(soundType), pitch, pan, soundType);

        return(sound);
    }
コード例 #13
0
ファイル: SoundKit.cs プロジェクト: imec-int/arcadeGameJam
    /// <summary>
    /// plays the AudioClip with the specified volumeScale, pitch and pan
    /// </summary>
    /// <returns>The sound.</returns>
    /// <param name="audioClip">Audio clip.</param>
    /// <param name="volume">Volume.</param>
    /// <param name="pitch">Pitch.</param>
    /// <param name="pan">Pan.</param>
    public SKSound playSound(AudioClip audioClip, float volumeScale, float pitch, float pan)
    {
        // Find the first SKSound not being used. if they are all in use, create a new one
        SKSound sound = nextAvailableSound();

        sound.playAudioClip(audioClip, volumeScale * soundEffectVolume, pitch, pan);

        return(sound);
    }
コード例 #14
0
ファイル: SoundKit.cs プロジェクト: imec-int/arcadeGameJam
    /// <summary>
    /// starts up the background music and optionally loops it. You can access the SKSound via the backgroundSound field.
    /// </summary>
    /// <param name="audioClip">Audio clip.</param>
    /// <param name="loop">If set to <c>true</c> loop.</param>
    public void playBackgroundMusic(AudioClip audioClip, float volume, bool loop = true)
    {
        if (backgroundSound == null)
        {
            backgroundSound = new SKSound(this);
        }

        backgroundSound.playAudioClip(audioClip, volume, 1f, 0f);
        backgroundSound.setLoop(loop);
    }
コード例 #15
0
    /// <summary>
    /// loops the AudioClip. Do note that you are responsible for calling either stop or fadeOutAndStop on the SKSound
    /// or it will not be recycled
    /// </summary>
    /// <returns>The sound looped.</returns>
    /// <param name="audioClip">Audio clip.</param>
    public SKSound playSoundLooped(AudioClip audioClip, SoundType soundType = SoundType.SFX)
    {
        // find the first SKSound not being used. if they are all in use, create a new one
        SKSound sound = nextAvailableSound();

        sound.playAudioClip(audioClip, getVolume(soundType), 1f, 0f, soundType);
        sound.setLoop(true);

        return(sound);
    }
コード例 #16
0
ファイル: SoundKit.cs プロジェクト: imec-int/arcadeGameJam
    /// <summary>
    /// loops the AudioClip. Do note that you are responsible for calling either stop or fadeOutAndStop on the SKSound
    /// or it will not be recycled
    /// </summary>
    /// <returns>The sound looped.</returns>
    /// <param name="audioClip">Audio clip.</param>
    public SKSound playSoundLooped(AudioClip audioClip)
    {
        // find the first SKSound not being used. if they are all in use, create a new one
        SKSound sound = nextAvailableSound();

        sound.playAudioClip(audioClip, soundEffectVolume, 1f, 0f);
        sound.setLoop(true);

        return(sound);
    }
コード例 #17
0
    /// <summary>
    /// starts up the background music and optionally loops it. You can access the SKSound via the backgroundSound field.
    /// </summary>
    /// <param name="audioClip">Audio clip.</param>
    /// <param name="loop">If set to <c>true</c> loop.</param>
    public SKSound playBackgroundMusic(AudioClip audioClip, float volume, bool loop = true)
    {
        if (backgroundSound == null)
        {
            backgroundSound = new SKSound(this);
        }

        backgroundSound.playAudioClip(audioClip, volume * getVolume(SoundType.BGM), 1f, 0f, SoundType.BGM);
        backgroundSound.setLoop(loop);

        return(backgroundSound);
    }
コード例 #18
0
        void OnLevelWasLoaded(int level)
        {
            if (dontDestroyOnLoad && clearAllAudioClipsOnLevelLoad)
            {
                for (int index = playingSounds.Count - 1; index >= 0; index--)
                {
                    SKSound sound = playingSounds[index];
                    sound.audioSource.clip = null;

                    availableSounds.Push(sound);
                    playingSounds.RemoveAt(index);
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// starts up the background music and optionally loops it. You can access the SKSound via the backgroundSound field.
        /// </summary>
        /// <param name="audioClip">Audio clip.</param>
        /// <param name="loop">If set to <c>true</c> loop.</param>
        public void playBackgroundMusic(AudioClip audioClip, float volume, bool loop = true)
        {
            if (audioClip == null)
            {
                Debug.LogWarning("playBackgroundMusic was called with a null AudioClip.");
                return;
            }
            if (backgroundSound == null)
            {
                backgroundSound = new SKSound(this);
            }

            backgroundSound.playAudioClip(audioClip, volume * bgmVolume, 1f, 0f, bgmGroup);
            backgroundSound.setLoop(loop);
        }
コード例 #20
0
    /// <summary>
    /// plays the AudioClip with the specified volumeScale, pitch and pan
    /// </summary>
    /// <returns>The sound.</returns>
    /// <param name="audioClip">Audio clip.</param>
    /// <param name="volume">Volume.</param>
    /// <param name="pitch">Pitch.</param>
    /// <param name="pan">Pan.</param>
    public SKSound PlaySound(AudioClip audioClip, float volumeScale, float pitch, float pan)
    {
        if (audioClip == null)
        {
            Debug.LogError("Null sound played");
            return(null);
        }

        // Find the first SKSound not being used. if they are all in use, create a new one
        SKSound sound = NextAvailableSound();

        sound.playAudioClip(audioClip, volumeScale * SoundVolume, pitch, pan);

        return(sound);
    }
コード例 #21
0
        /// <summary>
        /// plays the AudioClip with the specified volumeScale, pitch and pan
        /// </summary>
        /// <returns>The sound.</returns>
        /// <param name="audioClip">Audio clip.</param>
        /// <param name="volume">Volume.</param>
        /// <param name="pitch">Pitch.</param>
        /// <param name="pan">Pan.</param>
        public SKSound playSound(AudioClip audioClip, float volumeScale, float pitch, float pan)
        {
            if (audioClip == null)
            {
                Debug.LogWarning("playSound was called with a null AudioClip.");
                return(null);
            }

            // Find the first SKSound not being used. if they are all in use, create a new one
            SKSound sound = nextAvailableSound();

            sound.playAudioClip(audioClip, volumeScale * soundEffectVolume, pitch, pan, sfxGroup);

            return(sound);
        }
コード例 #22
0
        /// <summary>
        /// fetches any AudioSource it can find and uses the standard PlayOneShot to play. Use this if you don't require any
        /// extra control over a clip and don't care about when it completes. It avoids the call to StartCoroutine.
        /// nb. pan/pitch are not supported as the chosen AudioSource might be in use with another pan/pitch setting and Unity does not support setting
        /// them natively in PlayOneShot, so updating them here can result in bad audio.
        /// </summary>
        /// <param name="audioClip">Audio clip.</param>
        /// <param name="volumeScale">Volume scale.</param>
        public void playOneShot(AudioClip audioClip, float volumeScale = 1f)
        {
            if (audioClip == null)
            {
                Debug.LogWarning("playOneShot was called with a null AudioClip.");
                return;
            }
            if (oneShotSound == null)
            {
                oneShotSound = new SKSound(this);
            }

            oneShotSound.audioSource.outputAudioMixerGroup = sfxGroup;
            oneShotSound.audioSource.PlayOneShot(audioClip, volumeScale * soundEffectVolume);
        }
コード例 #23
0
    /// <summary>
    /// fetches any AudioSource it can find and uses the standard PlayOneShot to play. Use this if you don't require any
    /// extra control over a clip and don't care about when it completes. It avoids the call to StartCoroutine.
    /// nb. pan/pitch are not supported as the chosen AudioSource might be in use with another pan/pitch setting and Unity does not support setting
    /// them natively in PlayOneShot, so updating them here can result in bad audio.
    /// </summary>
    /// <param name="audioClip">Audio clip.</param>
    /// <param name="volumeScale">Volume scale.</param>
    public void PlayOneShot(AudioClip audioClip, float volumeScale = 1f)
    {
        if (audioClip == null)
        {
            Debug.LogError("Null sound played");
            return;
        }

        if (OneShotSound == null)
        {
            OneShotSound = new SKSound(this);
        }

        OneShotSound.AudioSource.PlayOneShot(audioClip, volumeScale * SoundVolume);
    }
コード例 #24
0
        /// <summary>
        /// loops the AudioClip. Do note that you are responsible for calling either stop or fadeOutAndStop on the SKSound
        /// or it will not be recycled
        /// </summary>
        /// <returns>The sound looped.</returns>
        /// <param name="audioClip">Audio clip.</param>
        public SKSound playSoundLooped(AudioClip audioClip)
        {
            if (audioClip == null)
            {
                Debug.LogWarning("playSoundLooped was called with a null AudioClip.");
                return(null);
            }

            // find the first SKSound not being used. if they are all in use, create a new one
            SKSound sound = nextAvailableSound();

            sound.playAudioClip(audioClip, soundEffectVolume, 1f, 0f, sfxGroup);
            sound.setLoop(true);

            return(sound);
        }
コード例 #25
0
    /// <summary>
    /// loops the AudioClip. Do note that you are responsible for calling either stop or fadeOutAndStop on the SKSound
    /// or it will not be recycled
    /// </summary>
    /// <returns>The sound looped.</returns>
    /// <param name="audioClip">Audio clip.</param>
    public SKSound PlaySoundLooped(AudioClip audioClip)
    {
        if (audioClip == null)
        {
            Debug.LogError("Null sound played");
            return(null);
        }

        // find the first SKSound not being used. if they are all in use, create a new one
        SKSound sound = NextAvailableSound();

        sound.playAudioClip(audioClip, SoundVolume, 1f, 0f);
        sound.setLoop(true);

        return(sound);
    }
コード例 #26
0
    /// <summary>
    /// starts up the background music and optionally loops it. You can access the SKSound via the BackgroundSound field.
    /// </summary>
    /// <param name="audioClip">Audio clip.</param>
    /// <param name="volume">Volume scale.</param>
    /// <param name="loop">If set to <c>true</c> loop.</param>
    public void PlayBackgroundMusic(AudioClip audioClip, float volume = 1.0f, bool loop = true)
    {
        if (audioClip == null)
        {
            Debug.LogError("Null sound played");
            return;
        }

        if (BackgroundSound == null)
        {
            BackgroundSound = new SKSound(this);
        }

        BackgroundVolume = volume;
        BackgroundSound.playAudioClip(audioClip, volume * MusicVolume, 1f, 0f);
        BackgroundSound.setLoop(loop);
    }
コード例 #27
0
ファイル: SoundKit.cs プロジェクト: imec-int/arcadeGameJam
    /// <summary>
    /// fetches the next available sound and adds the sound to the _playingSounds List
    /// </summary>
    /// <returns>The available sound.</returns>
    private SKSound nextAvailableSound()
    {
        SKSound sound = null;

        if (_availableSounds.Count > 0)
        {
            sound = _availableSounds.Pop();
        }

        // if we didnt find an available found, bail out
        if (sound == null)
        {
            sound = new SKSound(this);
        }
        _playingSounds.Add(sound);

        return(sound);
    }
コード例 #28
0
        void Update()
        {
            for (int index = playingSounds.Count - 1; index >= 0; index--)
            {
                SKSound sound = playingSounds[index];

                if (sound.playingLoopingAudio)
                {
                    continue;
                }

                sound.elapsedTime += Time.deltaTime;
                if (sound.elapsedTime > sound.audioSource.clip.length)
                {
                    sound.Stop();
                }
            }
        }
コード例 #29
0
        private SKSound NextAvailableSound()
        {
            SKSound sound = null;

            if (availableSounds.Count > 0)
            {
                sound = availableSounds.Pop();
            }

            if (sound == null)
            {
                sound = new SKSound(this);
            }

            playingSounds.Add(sound);

            return(sound);
        }
コード例 #30
0
	/// <summary>
	/// fetches any AudioSource it can find and uses the standard PlayOneShot to play. Use this if you don't require any
	/// extra control over a clip and don't care about when it completes. It avoids the call to StartCoroutine.
	/// nb. pan/pitch are not supported as the chosen AudioSource might be in use with another pan/pitch setting and Unity does not support setting
	/// them natively in PlayOneShot, so updating them here can result in bad audio.
	/// </summary>
	/// <param name="audioClip">Audio clip.</param>
	/// <param name="volumeScale">Volume scale.</param>
	public void playOneShot( AudioClip audioClip, float volumeScale = 1f )
	{
	    if (audioClip == null)
	        throw new ArgumentNullException("audioClip");

		if (oneShotSound == null)
			oneShotSound = new SKSound(this);

		oneShotSound.audioSource.PlayOneShot( audioClip, volumeScale * soundEffectVolume );
	}
コード例 #31
0
    /// <summary>
    /// used internally to recycle SKSounds and their AudioSources
    /// </summary>
    /// <param name="sound">Sound.</param>
    public void recycleSound( SKSound sound )
    {
        // we dont recycle the backgroundSound since it always stays alive
        if( sound == backgroundSound )
            return;

        var index = 0;
        while( index < _playingSounds.Count )
        {
            if( _playingSounds[index] == sound )
                break;
            index++;
        }
        _playingSounds.RemoveAt( index );

        // if we are already over capacity dont recycle this sound but destroy it instead
        if( _availableSounds.Count + _playingSounds.Count >= maxCapacity )
            Destroy( sound.audioSource );
        else
            _availableSounds.Push( sound );
    }
コード例 #32
0
    /// <summary>
    /// fetches the next available sound and adds the sound to the _playingSounds List
    /// </summary>
    /// <returns>The available sound.</returns>
    private SKSound nextAvailableSound()
    {
        SKSound sound = null;

        if( _availableSounds.Count > 0 )
            sound = _availableSounds.Pop();

        // if we didnt find an available found, bail out
        if( sound == null )
            sound = new SKSound( this );
        _playingSounds.Add( sound );

        return sound;
    }