Exemplo n.º 1
0
        /// <summary>
        /// Plays the next music track in the music queue
        /// </summary>
        public void NextMusicTrack()
        {
            // stop the current track
            StopMusic();
            switch (PlayerState)
            {
            // play track queue in order
            case MusicPlayerState.Ordered:
                if (MusicQueue != null && MusicQueue.Count > 0)
                {
                    SoundEffect nextTrack = MusicQueue.Dequeue();
                    PlayMusic(nextTrack);
                }
                else
                {
                    OnMusicQueueEnded(new SoundEffectEventArgs(null));
                }
                break;

            // play a random track from the queue
            case MusicPlayerState.Shuffle:
                if (MusicQueue != null && MusicQueue.Count > 0)
                {
                    int         i         = RandomHelper.Next(0, MusicQueue.Count);
                    SoundEffect nextTrack = MusicQueue.Get(i);
                    if (nextTrack != null)
                    {
                        PlayMusic(nextTrack);
                    }
                }
                else
                {
                    PlayMusic(currentMusicEffect);
                }
                break;

            // play the music queue over and over
            case MusicPlayerState.RepeatOrder:
                if (currentQueueNode.Next == null)
                {
                    currentQueueNode = MusicQueue.First;
                }
                else
                {
                    currentQueueNode = currentQueueNode.Next;
                }
                PlayMusic(currentQueueNode.Value);
                break;

            // play the same track over and over
            case MusicPlayerState.RepeatOne:
                PlayMusic(currentMusicEffect);
                break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        public void Update()
        {
            // Update the music queue
            if (MusicQueue.Count > 0)
            {
                if (string.IsNullOrEmpty(CurrentMusicEvent))
                {
                    PlayMusic(MusicQueue.Dequeue());
                }
            }

            //Delete any dead emitters
            LinkedListNode <AudioEmitter> currentNode = ActiveEmitters.First;

            while (currentNode != null)
            {
                if (currentNode.Value.Finished)
                {
                    var node = currentNode;
                    currentNode = currentNode.Next;
                    GameObject.Destroy(node.Value.gameObject);
                    ActiveEmitters.Remove(node);
                }
                else
                {
                    currentNode = currentNode.Next;
                }
            }

#if UNITY_EDITOR
            if (LogBankRefCounts)
            {
                foreach (KeyValuePair <string, int> kvp in BankReferenceCounts)
                {
                    Debug.Log(kvp.Key.ToString() + ":" + kvp.Value.ToString());
                }
                LogBankRefCounts = false;
            }
#endif
        }