示例#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();
    }
示例#2
0
        public double Init(AudioClip startPatch, float timeToStart = 3)
        {
            Debug.Assert(State != ControllerState.START);

            State = ControllerState.START;

            double initTime = AudioSettings.dspTime;

            CurrentClip             = startPatch;
            CurrentAudioSource.clip = CurrentClip;
            firstClipStartTime      = initTime + timeToStart;

            CurrentAudioSource.PlayScheduled(firstClipStartTime);
            return(firstClipStartTime);
        }
示例#3
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();
    }
示例#4
0
    private void InitAudioSource(SongsEnum songId, float volume = -1)
    {
        if (volume == -1)
        {
            volume = _standardVolume;
        }

        CurrentSong = songId;

        var clip = _songs.Find(s => s.Id == songId).Song;

        CurrentAudioSource.volume = 0;
        CurrentAudioSource.clip   = clip;
        CurrentAudioSource.loop   = true;
        CurrentAudioSource.Play();

        DOTween
        .To(() => CurrentAudioSource.volume, value => CurrentAudioSource.volume = value, volume, 1f)
        .SetEase(Ease.InOutSine)
        .SetId("MusicTween");
    }
示例#5
0
        //播放音效
        public void PlaySound(string clipname)
        {
            if (!Setting.SoundEffectSwitch)
            {
                return;
            }
            AudioClipInfo clipInfo = GetSoundClip(clipname);

            if (clipInfo == null)
            {
                Debug.Log(string.Format("<color=red>PlaySound err cant load sound={0}</color>", clipname));
                return;
            }
            AudioClip clip = clipInfo.Clip;

            if (clip == null)
            {
                Debug.LogError("PlaySound err sound: " + clipname);
                return;
            }
            //Debug.Log(string.Format("<color=green>PlaySound t load sound={0} </color>", clipname));
            CurrentAudioSource.PlayOneShot(clip, Setting.Volume);
        }