Beispiel #1
0
    /*
     * public void Play(Color colour, float velocity = 10, float length = 1, float speed = 1)
     * {
     *      if (PianoKeyController.ShowMIDIChannelColours)
     *      {
     *              _colour = colour;
     *      }
     *
     *      this.Play(velocity, length, speed);
     * }
     */
    #endregion

    //WE NEED TO CHECK THIS IENUMERATOR BECAUSE ROTATION AFFECTS VOLUME AND WE DON'T NEED ROTATION..
    //UPDATE :: Apparently this was only for KayMode.Physical
    #region [------------	THE VOLUME DEPENDS OF THE ROTATION OF THE KEY BUT WE DONT HAVE A PIANO KEY..------------]

    /*
     * [Obsolete("We need to check this Ienumerator")]
     * IEnumerator PlayPressedAudio()
     * {
     * if (!PianoKeyController.NoMultiAudioSource && CurrentAudioSource.isPlaying)
     * {
     * bool foundReplacement = false;
     * int index = AudioSources.IndexOf(CurrentAudioSource);
     *
     * for (int i = 0; i < AudioSources.Count; i++)
     * {
     *      if (i != index && (!AudioSources[i].isPlaying || AudioSources[i].volume <= 0))
     *      {
     *              foundReplacement = true;
     *              CurrentAudioSource = AudioSources[i];
     *              _toFade.Remove(AudioSources[i]);
     *              break;
     *      }
     * }
     *
     * if (!foundReplacement)
     * {
     *      AudioSource newAudioSource = CloneAudioSource();
     *      AudioSources.Add(newAudioSource);
     *      CurrentAudioSource = newAudioSource;
     * }
     *
     * _toFade.Add(AudioSources[index]);
     * }
     *
     * _startAngle = transform.eulerAngles.x;
     *
     * yield return new WaitForFixedUpdate();
     * yield return new WaitForFixedUpdate(); // two yields in a row? mmm wtf okay..
     *
     *
     * if (Mathf.Abs(_startAngle - transform.eulerAngles.x) > 0)
     * {
     * CurrentAudioSource.volume = Mathf.Lerp(0, 1, Mathf.Clamp((Mathf.Abs(_startAngle - transform.eulerAngles.x) / 2f), 0, 1));
     * }
     *
     * CurrentAudioSource.Play();
     * }
     */

    #endregion

    void PlayVirtualAudio()
    {
        if (!PianoKeyController.NoMultiAudioSource && CurrentAudioSource.isPlaying)
        {
            bool foundReplacement = false;
            int  index            = AudioSources.IndexOf(CurrentAudioSource);

            for (int i = 0; i < AudioSources.Count; i++)
            {
                if (i != index && (!AudioSources[i].isPlaying || AudioSources[i].volume <= 0))
                {
                    foundReplacement   = true;
                    CurrentAudioSource = AudioSources[i];
                    _toFade.Remove(AudioSources[i]);
                    break;
                }
            }

            if (!foundReplacement)
            {
                AudioSource newAudioSource = CloneAudioSource();
                AudioSources.Add(newAudioSource);
                CurrentAudioSource = newAudioSource;
            }

            _toFade.Add(AudioSources[index]);
        }

        CurrentAudioSource.volume = _velocity / 127f;

        CurrentAudioSource.Play();
    }
Beispiel #2
0
    IEnumerator PlayPressedAudio()
    {
        if (!PianoKeyController.NoMultiAudioSource && CurrentAudioSource.isPlaying)
        {
            bool foundReplacement = false;
            int  index            = AudioSources.IndexOf(CurrentAudioSource);

            for (int i = 0; i < AudioSources.Count; i++)
            {
                if (i != index && (!AudioSources[i].isPlaying || AudioSources[i].volume <= 0))
                {
                    foundReplacement   = true;
                    CurrentAudioSource = AudioSources[i];
                    _toFade.Remove(AudioSources[i]);
                    break;
                }
            }

            if (!foundReplacement)
            {
                AudioSource newAudioSource = CloneAudioSource();
                AudioSources.Add(newAudioSource);
                CurrentAudioSource = newAudioSource;
            }

            _toFade.Add(AudioSources[index]);
        }

        _startAngle = transform.eulerAngles.x;

        yield return(new WaitForFixedUpdate());

        yield return(new WaitForFixedUpdate());

        if (Mathf.Abs(_startAngle - transform.eulerAngles.x) > 0)
        {
            CurrentAudioSource.volume = Mathf.Lerp(0, 1, Mathf.Clamp((Mathf.Abs(_startAngle - transform.eulerAngles.x) / 2f), 0, 1));
        }

        CurrentAudioSource.Play();
    }