コード例 #1
0
    /// <summary>
    /// Method used to Play the Sound effects of the game.
    ///  Optional values in the signature of the method allow the customization of the call according to the needs.
    /// </summary>
    public static void PlaySoundEffect(AudioAssets.Soundeffects soundeffect, Vector2 position, float volume = 1f)
    {
        SingleAudioPlayer pooledAudioPlayer = AudioPlayerPoolSystem.Instance.AvailableAudioPlayer();
        AudioClip         clipToPlay        = GetSoundEffectClip(soundeffect);

        pooledAudioPlayer.transform.position = position;

        bool shouldDeactivate = true;

        pooledAudioPlayer.SetAudioClip(clipToPlay, shouldDeactivate);
        pooledAudioPlayer.PlayCurrentAudioClip(volume);
    }
コード例 #2
0
    /// <summary>
    /// Provides the audioclip for the given soundeffect requested.
    /// IF the soundeffect is not in the soundeffect list, there is a fallback on a default soundeffect.
    /// </summary>
    /// <param name="requestedSoundEffect">Requires a soundeffect name.</param>
    /// <returns></returns>
    private static AudioClip GetSoundEffectClip(AudioAssets.Soundeffects requestedSoundEffect)
    {
        for (int i = 0; i < AudioAssets.Instance.soundEffectCollection.Count; i++)
        {
            if (requestedSoundEffect == AudioAssets.Instance.soundEffectCollection[i].soundEffectName)
            {
                return(AudioAssets.Instance.soundEffectCollection[i].audioClip);
            }
        }

        //Fallback to a default value
        return(AudioAssets.Instance.soundEffectFallback.audioClip);
    }