protected void PlayAudio(AudioCueSO audioCue, AudioConfigurationSO audioConfiguration, Vector3 positionInSpace = default)
 {
     if (_gameState.CurrentGameState != GameState.Cutscene)
     {
         _sfxEventChannel.RaisePlayEvent(audioCue, audioConfiguration, positionInSpace);
     }
 }
Example #2
0
    public AudioCueKey Add(AudioCueSO cue, SoundEmitter[] emitter)
    {
        AudioCueKey emitterKey = GetKey(cue);

        _emittersKey.Add(emitterKey);
        _emittersList.Add(emitter);

        return(emitterKey);
    }
Example #3
0
 public void PlayAudioCue(AudioCueSO cue)
 {
     if (cue == null)
     {
         return;
     }
     else
     {
         _audioCueEventChannel.RaiseEvent(cue, _audioConfiguration, transform.position);
     }
 }
Example #4
0
 public void RaiseEvent(AudioCueSO audioCue, AudioConfigurationSO audioConfiguration, Vector3 positionInSpace)
 {
     if (OnAudioCueRequested != null)
     {
         OnAudioCueRequested.Invoke(audioCue, audioConfiguration, positionInSpace);
     }
     else
     {
         Debug.LogWarning("An AudioCue was requested, but nobody picked it up. " +
                          "Check why there is no AudioManager already loaded, " +
                          "and make sure it's listening on this AudioCue Event channel.");
     }
 }
Example #5
0
        private void PlayAudioCue(AudioCueSO audioCueSO)
        {
            var source = audioCueSO.type switch
            {
                Type.FX => GetFromPool(),
                Type.Music => _musicSource,
                _ => throw new ArgumentException("Invalid Audio Type"),
            };

            source.volume = audioCueSO.volume;
            source.clip   = audioCueSO.clip;
            source.Play();
        }
Example #6
0
 public void PlayAudioCue(AudioCueSO cue, int chance)
 {
     if (cue == null)
     {
         return;
     }
     else
     {
         int roll = Random.Range(1, 100);
         if (roll <= chance)
         {
             Debug.Log("chance sound played with roll: " + roll);
             _audioCueEventChannel.RaiseEvent(cue, _audioConfiguration, transform.position);
         }
     }
 }
Example #7
0
    public AudioCueKey RaisePlayEvent(AudioCueSO audioCue, AudioConfigurationSO audioConfiguration, Vector3 positionInSpace = default)
    {
        AudioCueKey audioCueKey = AudioCueKey.Invalid;

        if (OnAudioCuePlayRequested != null)
        {
            audioCueKey = OnAudioCuePlayRequested.Invoke(audioCue, audioConfiguration, positionInSpace);
        }
        else
        {
            Debug.LogWarning("An AudioCue play event was requested  for " + audioCue.name + ", but nobody picked it up. " +
                             "Check why there is no AudioManager already loaded, " +
                             "and make sure it's listening on this AudioCue Event channel.");
        }

        return(audioCueKey);
    }
    /// <summary>
    /// Plays an AudioCue by requesting the appropriate number of SoundEmitters from the pool.
    /// </summary>
    public void PlayAudioCue(AudioCueSO audioCue, AudioConfigurationSO settings, Vector3 position = default)
    {
        if (!audioCue.isSolo)
        {
            AudioClip[] clipsToPlay = audioCue.GetClips();
            int         nOfClips    = clipsToPlay.Length;

            for (int i = 0; i < nOfClips; i++)
            {
                SoundEmitter soundEmitter = _pool.Request();
                if (soundEmitter != null)
                {
                    soundEmitter.PlayAudioClip(clipsToPlay[i], settings, audioCue.looping, position);
                    if (!audioCue.looping)
                    {
                        soundEmitter.OnSoundFinishedPlaying += OnSoundEmitterFinishedPlaying;
                    }
                }
            }
        }

        else if (audioCue.isSolo && !soloPlaying)
        {
            AudioClip[] clipsToPlay = audioCue.GetClips();
            int         nOfClips    = clipsToPlay.Length;
            StartCoroutine(SoloClipDelay(clipsToPlay[0].length));
            for (int i = 0; i < nOfClips; i++)
            {
                SoundEmitter soundEmitter = _pool.Request();
                if (soundEmitter != null)
                {
                    soundEmitter.PlayAudioClip(clipsToPlay[i], settings, audioCue.looping, position);
                    if (!audioCue.looping)
                    {
                        soundEmitter.OnSoundFinishedPlaying += OnSoundEmitterFinishedPlaying;
                    }
                }
            }
        }

        else
        {
            Debug.Log("Could not play solo clip as another one is currently playing");
        }
    }
    /// <summary>
    /// Plays an AudioCue by requesting the appropriate number of SoundEmitters from the pool.
    /// </summary>
    public void PlayAudioCue(AudioCueSO audioCue, AudioConfigurationSO settings, Vector3 position = default)
    {
        AudioClip[] clipsToPlay = audioCue.GetClips();
        int         nOfClips    = clipsToPlay.Length;

        for (int i = 0; i < nOfClips; i++)
        {
            SoundEmitter soundEmitter = _pool.Request();
            if (soundEmitter != null)
            {
                soundEmitter.PlayAudioClip(clipsToPlay[i], settings, audioCue.looping, position);
                if (!audioCue.looping)
                {
                    soundEmitter.OnSoundFinishedPlaying += OnSoundEmitterFinishedPlaying;
                }
            }
        }

        //TODO: Save the SoundEmitters that were activated, to be able to stop them if needed
    }
Example #10
0
    public void PlayAudioCue(AudioCueSO audioCue, AudioConfigurationSO settings, Vector3 position = default)
    {
        AudioClip[] clipsToPlay   = audioCue.GetClips();
        var         amountOfClips = clipsToPlay.Length;

        for (int i = 0; i < amountOfClips; i++)
        {
            SoundEmitter soundEmitter = _pool.Request();

            if (soundEmitter != null)
            {
                soundEmitter.PlayAudioClip(clipsToPlay[i], settings, audioCue.IsLooping, position);

                if (!audioCue.IsLooping)
                {
                    soundEmitter.OnSoundFinishedPlaying += OnSoundEmitterFinishedPlaying;
                }
            }
        }
    }
Example #11
0
    /// <summary>
    /// Plays an AudioCue by requesting the appropriate number of SoundEmitters from the pool.
    /// </summary>
    public AudioCueKey PlayAudioCue(AudioCueSO audioCue, AudioConfigurationSO settings, Vector3 position = default)
    {
        AudioClip[]    clipsToPlay       = audioCue.GetClips();
        SoundEmitter[] soundEmitterArray = new SoundEmitter[clipsToPlay.Length];

        int nOfClips = clipsToPlay.Length;

        for (int i = 0; i < nOfClips; i++)
        {
            soundEmitterArray[i] = _pool.Request();
            if (soundEmitterArray[i] != null)
            {
                soundEmitterArray[i].PlayAudioClip(clipsToPlay[i], settings, audioCue.looping, position);
                if (!audioCue.looping)
                {
                    soundEmitterArray[i].OnSoundFinishedPlaying += OnSoundEmitterFinishedPlaying;
                }
            }
        }

        return(_soundEmitterVault.Add(audioCue, soundEmitterArray));
    }
Example #12
0
    private AudioCueKey PlayMusicTrack(AudioCueSO audioCue, AudioConfigurationSO audioConfiguration, Vector3 positionInSpace)
    {
        float fadeDuration = 2f;
        float startTime    = 0f;

        if (_musicSoundEmitter != null && _musicSoundEmitter.IsPlaying())
        {
            AudioClip songToPlay = audioCue.GetClips()[0];
            if (_musicSoundEmitter.GetClip() == songToPlay)
            {
                return(AudioCueKey.Invalid);
            }

            //Music is already playing, need to fade it out
            startTime = _musicSoundEmitter.FadeMusicOut(fadeDuration);
        }

        _musicSoundEmitter = _pool.Request();
        _musicSoundEmitter.FadeMusicIn(audioCue.GetClips()[0], audioConfiguration, 1f, startTime);
        _musicSoundEmitter.OnSoundFinishedPlaying += StopMusicEmitter;

        return(AudioCueKey.Invalid);        //No need to return a valid key for music
    }
Example #13
0
 public AudioCueKey GetKey(AudioCueSO cue)
 {
     return(new AudioCueKey(_nextUniqueKey++, cue));
 }
 public PlayAudioCueAction(AudioCueSO audioCue, AudioCueEventChannelSO audioCueEventChannel, AudioConfigurationSO audioConfiguration)
 {
     _audioCue             = audioCue;
     _audioCueEventChannel = audioCueEventChannel;
     _audioConfiguration   = audioConfiguration;
 }
Example #15
0
 public void Raise(AudioCueSO audioCue, AudioConfigurationSO audioConfiguration, Vector3 positionInSpace)
 {
     eventRaised.Invoke(audioCue, audioConfiguration, positionInSpace);
 }
 internal AudioCueKey(int value, AudioCueSO audioCue)
 {
     Value    = value;
     AudioCue = audioCue;
 }