Exemple #1
0
    public void OnUpdate()
    {
        if (paused)
        {
            return;
        }

        songPosition = (float)(AudioSettings.dspTime - dspTimeSong) * m_AudioService.GetAudioSource().pitch;
        float beatToShow = songPosition / crotchet + BeatsShownOnScreen;

        for (int i = 0; i < len; i++)
        {
            int            nextIndex = trackNextIndices[i];
            SongInfo.Track currTrack = tracks[i];

            if (nextIndex < currTrack.Notes.Length && currTrack.Notes[nextIndex].note < beatToShow)
            {
                SongInfo.Note currNote  = currTrack.Notes[nextIndex];
                Vector3       parentPos = i == 0 ? LeftParent.position : RightParent.position;
                MusicNode     musicNode = Instantiate(NodePrefab, new Vector3(parentPos.x, Screen.height + 200, 0), this.transform.rotation, i == 0 ? LeftParent : RightParent);
                musicNode.Initialize(parentPos.x, Screen.height + 200, finishLineY, 0, currNote.note);

                trackNextIndices[i]++;
                queueForTracks[i].Enqueue(musicNode);
            }
        }

        if (songPosition > songLength)
        {
            if (m_OnFinish != null)
            {
                m_OnFinish.Invoke();
                paused = true;

                m_OnFinish = null;
                m_OnInput  = null;
            }
        }
    }
Exemple #2
0
    void Update()
    {
        //for count down
        if (!songStarted)
        {
            return;
        }

        //for pausing
        if (paused)
        {
            if (pauseTimeStamp < 0f)             //not managed
            {
                pauseTimeStamp = (float)AudioSettings.dspTime;
                //print("pausetimestamp:" + pauseTimeStamp.ToString());
                audioSource.Pause();
            }

            return;
        }
        else if (pauseTimeStamp > 0f)         //resume not managed
        {
            pausedTime += (float)AudioSettings.dspTime - pauseTimeStamp;
            //print("resumetimestamp:"+AudioSettings.dspTime.ToString());
            //print("offset"+pausedTime.ToString());
            audioSource.Play();

            pauseTimeStamp = -1f;
        }

        //calculate songposition
        songposition = (float)(AudioSettings.dspTime - dsptimesong - pausedTime) * audioSource.pitch - songInfo.songOffset;
        //print (songposition);

        //check if need to instantiate new nodes
        float beatToShow = songposition / crotchet + BeatsShownOnScreen;

        //loop the tracks for new MusicNodes
        for (int i = 0; i < len; i++)
        {
            int            nextIndex = trackNextIndices[i];
            SongInfo.Track currTrack = tracks[i];

            if (nextIndex < currTrack.notes.Length && currTrack.notes[nextIndex].note < beatToShow)
            {
                SongInfo.Note currNote = currTrack.notes[nextIndex];

                //set z position
                float layerZ = nextLayerZ[i];
                nextLayerZ[i] += LayerOffsetZ;

                //get a new node
                MusicNode musicNode = MusicNodePool.instance.GetNode(trackSpawnPosX[i], startLineY, finishLineY, removeLineY, layerZ, currNote.note, currNote.times, trackColors[i]);

                //enqueue
                queueForTracks[i].Enqueue(musicNode);

                //update the next index
                trackNextIndices[i]++;
            }
        }

        //loop the queue to check if any of them reaches the finish line
        for (int i = 0; i < len; i++)
        {
            //empty queue, continue
            if (queueForTracks[i].Count == 0)
            {
                continue;
            }

            MusicNode currNode = queueForTracks[i].Peek();

            //multi-times note
            if (currNode.times > 0 && currNode.transform.position.y <= finishLineY + goodOffsetY)
            {
                //have previous note stuck on the finish line
                if (previousMusicNodes[i] != null)
                {
                    previousMusicNodes[i].MultiTimesFailed();

                    //dispatch miss event
                    if (beatOnHitEvent != null)
                    {
                        beatOnHitEvent(i, Rank.MISS);
                    }
                }

                //pause the note
                currNode.paused = true;

                //align to finish line
                currNode.transform.position = new Vector3(currNode.transform.position.x, finishLineY, currNode.transform.position.z);

                //deque, but keep a reference
                previousMusicNodes[i] = currNode;
                queueForTracks[i].Dequeue();
            }
            else if (currNode.transform.position.y <= finishLineY - goodOffsetY)               //single time note
            {
                //have previous note stuck on the finish line
                if (previousMusicNodes[i] != null)
                {
                    previousMusicNodes[i].MultiTimesFailed();
                    previousMusicNodes[i] = null;

                    //dispatch miss event
                    if (beatOnHitEvent != null)
                    {
                        beatOnHitEvent(i, Rank.MISS);
                    }
                }

                //deque
                queueForTracks[i].Dequeue();

                //dispatch miss event (if a multi-times note is missed, its next single note would also be missed)
                if (beatOnHitEvent != null)
                {
                    beatOnHitEvent(i, Rank.MISS);
                }
            }
        }


        //check to see if the song reaches its end
        if (songposition > songLength)
        {
            songStarted = false;

            if (songCompletedEvent != null)
            {
                songCompletedEvent();
            }
        }
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (!songStarted)
        {
            return;
        }

        if (paused)
        {
            if (pauseTimeStamp < 0f)
            {
                pauseTimeStamp = (float)AudioSettings.dspTime;

                song.Pause();
            }

            return;
        }
        else if (pauseTimeStamp > 0f)
        {
            pausedTime += (float)AudioSettings.dspTime - pauseTimeStamp;

            song.Play();

            pauseTimeStamp = -1f;
        }

        songPosition = (float)(AudioSettings.dspTime - dspTimeSong - pausedTime) * song.pitch - songInfo.songOffset;

        songPosInBeats = songPosition / secPerBeat;

        // check if we need to instantiate new prefabs of notes
        float notesToShow = (songPosition / secPerBeat) + beatsShownOnScreen;

        // for loop to iterate through the tracks to spawn more music notes
        for (int i = 0; i < length; i++)
        {
            int            nextIndex    = trackNextIndices[i];
            SongInfo.Track currentTrack = tracks[i];

            if (nextIndex < currentTrack.notes.Length && currentTrack.notes[nextIndex].note < notesToShow)
            {
                SongInfo.Note currentNote = currentTrack.notes[nextIndex];

                MusicNoteController musicNote = MusicNotePool.instance.CreateAndGetNote(spawnPosX[i], startPosY, endPosY, removePosY, 0, currentNote.note);

                queueForTracks[i].Enqueue(musicNote);

                trackNextIndices[i]++;
            }
        }

        // loop the queue to check if any of the notes reached the finish line
        for (int i = 0; i < length; i++)
        {
            if (queueForTracks[i].Count == 0)
            {
                continue;
            }

            MusicNoteController currentNote = queueForTracks[i].Peek();

            if (currentNote.transform.position.y <= endPosY - goodRankYEnd)
            {
                queueForTracks[i].Dequeue();

                if (onHitEvent != null)
                {
                    onHitEvent(i, Rank.MISS);
                }
            }
        }

        if (songPosition > songLength)
        {
            songStarted = false;

            if (songCompletedEvent != null)
            {
                songCompletedEvent();
            }
        }
    }
    private void Update()
    {
        if (Input.GetKeyDown("p"))/////////////////////////////////////
        {
            FireBall();
        }

        if (!ConductorCustom.Instance.paused)
        {
            //check if need to instantiate new nodes
            float beatToShow = ConductorCustom.songposition / ConductorCustom.crotchet + ConductorCustom.BeatsShownOnScreen;
            for (int i = 0; i < queueForTracks.Length; i++)
            {
                int            nextIndex = trackNextIndices[i];
                SongInfo.Track currTrack = tracksNode[i];

                if (nextIndex < currTrack.notes.Length && currTrack.notes[nextIndex].note < beatToShow)
                {
                    SongInfo.Note currNote = currTrack.notes[nextIndex];

                    //set z position
                    float layerZ = nextLayerZ[i];
                    nextLayerZ[i] += LayerOffsetZ;
                    //get a new node
                    MusicNode musicNode = MusicNodePool.instance.GetNode(tracks[i].offsetX, partitionManager.startLineY, partitionManager.finishLineY, partitionManager.removeLineY, layerZ, currNote.note, currNote.times, TracksColors[i], idplayer);
                    if (nextNoteIsStone)
                    {
                        musicNode.isStone = true;
                        nextNoteIsStone   = false;
                    }
                    //enqueue
                    queueForTracks[i].Enqueue(musicNode);

                    //update the next index
                    trackNextIndices[i]++;
                }
            }

            for (int i = 0; i < queueForTracks.Length; i++)
            {
                //empty queue, continue
                if (queueForTracks[i].Count == 0)
                {
                    continue;
                }

                MusicNode currNode = queueForTracks[i].Peek();

                //multi-times note
                if (currNode.transform.position.y <= partitionManager.finishLineY - partitionManager.badOffsetY)   //single time note
                {
                    //have previous note stuck on the finish line
                    if (previousMusicNodes[i] != null)
                    {
                        previousMusicNodes[i].MultiTimesFailed();
                        previousMusicNodes[i] = null;

                        //dispatch miss event
                        if (beatOnHitEvent != null)
                        {
                            beatOnHitEvent(i, PartitionManager.Rank.MISS);
                        }
                    }

                    //deque
                    queueForTracks[i].Dequeue();

                    //dispatch miss event (if a multi-times note is missed, its next single note would also be missed)
                    if (beatOnHitEvent != null)
                    {
                        beatOnHitEvent(i, PartitionManager.Rank.MISS);
                    }
                }
            }
        }
    }