Пример #1
0
    /// <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");
        }
    }
Пример #2
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
    }
Пример #3
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;
                }
            }
        }
    }
Пример #4
0
    /// <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
    }
Пример #5
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(_soundEmitterList.Add(audioCue, soundEmitterArray));
    }