示例#1
0
 public IMButton(string playerID, string buttonID, ButtonDownMethodDelegate btnDown, ButtonPressedMethodDelegate btnPressed, ButtonUpMethodDelegate btnUp)
 {
     ButtonID            = playerID + "_" + buttonID;
     ButtonDownMethod    = btnDown;
     ButtonUpMethod      = btnUp;
     ButtonPressedMethod = btnPressed;
     State = new MMStateMachine <MMInput.ButtonStates> (null, false);
     State.ChangeState(MMInput.ButtonStates.Off);
 }
示例#2
0
 public IMButton(string buttonID, ButtonDownMethodDelegate btnDown = null, ButtonPressedMethodDelegate btnPressed = null, ButtonUpMethodDelegate btnUp = null)
 {
     ButtonID            = buttonID;
     ButtonDownMethod    = btnDown;
     ButtonUpMethod      = btnUp;
     ButtonPressedMethod = btnPressed;
     State = new MMStateMachine <MMInput.ButtonStates>(null, false);
     State.ChangeState(MMInput.ButtonStates.Off);
 }
示例#3
0
 /// <summary>
 /// On init we initialize our state machine and start playing if needed
 /// </summary>
 protected virtual void Initialization()
 {
     _songsPlayedSoFar = 0;
     PlaylistState     = new MMStateMachine <MMPlaylist.PlaylistStates>(this.gameObject, true);
     PlaylistState.ChangeState(PlaylistStates.Idle);
     if (Songs.Count == 0)
     {
         return;
     }
     if (PlayOnStart)
     {
         PlayFirstSong();
     }
 }
示例#4
0
 /// <summary>
 /// On init we initialize our state machine and start playing if needed
 /// </summary>
 protected virtual void Initialization()
 {
     if (RandomOrder && RandomizeOrderSeed)
     {
         Random.InitState(System.Environment.TickCount);
     }
     _songsPlayedSoFar = 0;
     PlaylistState     = new MMStateMachine <MMPlaylist.PlaylistStates>(this.gameObject, true);
     PlaylistState.ChangeState(PlaylistStates.Idle);
     if (Songs.Count == 0)
     {
         return;
     }
     if (PlayOnStart)
     {
         PlayFirstSong();
     }
 }
示例#5
0
        /// <summary>
        /// Plays a new song in the playlist, and stops / fades the previous one
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        protected virtual IEnumerator PlaySong(int index)
        {
            // if we don't have a song, we stop
            if (Songs.Count == 0)
            {
                yield break;
            }

            // if we've played all our songs, we stop
            if (!Endless && (_songsPlayedThisCycle > Songs.Count))
            {
                yield break;
            }

            if (_coroutine != null)
            {
                StopCoroutine(_coroutine);
            }

            // we stop our current song
            if ((PlaylistState.CurrentState == PlaylistStates.Playing) && (index >= 0 && index < Songs.Count))
            {
                StartCoroutine(Fade(CurrentlyPlayingIndex,
                                    Random.Range(Songs[index].CrossFadeDuration.x, Songs[index].CrossFadeDuration.y),
                                    Songs[CurrentlyPlayingIndex].Volume.y * VolumeMultiplier,
                                    Songs[CurrentlyPlayingIndex].Volume.x * VolumeMultiplier,
                                    true));
            }

            // we stop all other coroutines
            if ((CurrentlyPlayingIndex >= 0) && (Songs.Count > CurrentlyPlayingIndex))
            {
                foreach (MMPlaylistSong song in Songs)
                {
                    if (song != Songs[CurrentlyPlayingIndex])
                    {
                        song.Fading = false;
                    }
                }
            }

            if (index < 0 || index >= Songs.Count)
            {
                yield break;
            }

            // initial delay
            yield return(MMCoroutine.WaitFor(Random.Range(Songs[index].InitialDelay.x, Songs[index].InitialDelay.y)));

            if (Songs[index].TargetAudioSource == null)
            {
                Debug.LogError(this.name + " : the playlist song you're trying to play is null");
                yield break;
            }

            Songs[index].TargetAudioSource.pitch        = Random.Range(Songs[index].Pitch.x, Songs[index].Pitch.y);
            Songs[index].TargetAudioSource.panStereo    = Songs[index].StereoPan;
            Songs[index].TargetAudioSource.spatialBlend = Songs[index].SpatialBlend;
            Songs[index].TargetAudioSource.loop         = Songs[index].Loop;

            // fades the new song's volume
            StartCoroutine(Fade(index,
                                Random.Range(Songs[index].CrossFadeDuration.x, Songs[index].CrossFadeDuration.y),
                                Songs[index].Volume.x * VolumeMultiplier,
                                Songs[index].Volume.y * VolumeMultiplier,
                                false));

            // starts the new song
            Songs[index].TargetAudioSource.Play();

            // updates our state
            CurrentSongName = Songs[index].TargetAudioSource.clip.name;
            PlaylistState.ChangeState(PlaylistStates.Playing);
            Songs[index].Playing  = true;
            CurrentlyPlayingIndex = index;
            _songsPlayedSoFar++;
            _songsPlayedThisCycle++;

            while (Songs[index].TargetAudioSource.isPlaying)
            {
                yield return(null);
            }

            if (PlaylistState.CurrentState != PlaylistStates.Playing)
            {
                yield break;
            }

            if (_songsPlayedSoFar < Songs.Count)
            {
                _coroutine = StartCoroutine(PlaySong(PickNextIndex()));
            }
            else
            {
                if (Endless)
                {
                    _coroutine = StartCoroutine(PlaySong(PickNextIndex()));
                }
                else
                {
                    PlaylistState.ChangeState(PlaylistStates.Idle);
                }
            }
        }
示例#6
0
        /// <summary>
        /// Plays a new track in the playlist, and stops / fades the previous one
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        protected virtual IEnumerator PlayTrack(int index)
        {
            // if we don't have a song, we stop
            if (Songs.Count == 0)
            {
                yield break;
            }

            // if we've played all our songs, we stop
            if (!Endless && (_songsPlayedThisCycle > Songs.Count))
            {
                yield break;
            }

            // we stop our current track
            if (PlaylistState.CurrentState == PlaylistStates.Playing)
            {
                StartCoroutine(Fade(CurrentlyPlayingIndex,
                                    Random.Range(Songs[index].CrossFadeDuration.x, Songs[index].CrossFadeDuration.y),
                                    Songs[CurrentlyPlayingIndex].Volume.y,
                                    Songs[CurrentlyPlayingIndex].Volume.x,
                                    true));
            }

            // we stop all other coroutines
            if (CurrentlyPlayingIndex >= 0)
            {
                foreach (MMPlaylistSong song in Songs)
                {
                    if (song != Songs[CurrentlyPlayingIndex])
                    {
                        song.Fading = false;
                    }
                }
            }

            // initial delay
            yield return(new WaitForSeconds(Random.Range(Songs[index].InitialDelay.x, Songs[index].InitialDelay.y)));

            if (Songs[index].TargetAudioSource == null)
            {
                Debug.LogError(this.name + " : the playlist song you're trying to play is null");
                yield break;
            }

            Songs[index].TargetAudioSource.pitch        = Random.Range(Songs[index].Pitch.x, Songs[index].Pitch.y);
            Songs[index].TargetAudioSource.panStereo    = Songs[index].StereoPan;
            Songs[index].TargetAudioSource.spatialBlend = Songs[index].SpatialBlend;
            Songs[index].TargetAudioSource.loop         = Songs[index].Loop;

            // fades the new track's volume
            StartCoroutine(Fade(index,
                                Random.Range(Songs[index].CrossFadeDuration.x, Songs[index].CrossFadeDuration.y),
                                Songs[index].Volume.x,
                                Songs[index].Volume.y,
                                false));

            // starts the new track
            Songs[index].TargetAudioSource.Play();

            // updates our state
            CurrentTrackName = Songs[index].TargetAudioSource.clip.name;
            PlaylistState.ChangeState(PlaylistStates.Playing);
            Songs[index].Playing  = true;
            CurrentlyPlayingIndex = index;
            _songsPlayedSoFar++;
            _songsPlayedThisCycle++;
        }