コード例 #1
0
    // Event handler when an input is inputted from playerinputcontroller
    void PlayerInput(int trackNumber)
    {
        if (queueForTracks[trackNumber].Count != 0)
        {
            MusicNoteController frontNote = queueForTracks[trackNumber].Peek();

            float noteHitPos = frontNote.gameObject.transform.position.y - endPosY;

            if (noteHitPos < perfectRankYBegin && noteHitPos > perfectRankYEnd)
            {
                frontNote.Perfect();

                if (onHitEvent != null)
                {
                    onHitEvent(trackNumber, Rank.PERFECT);
                }

                queueForTracks[trackNumber].Dequeue();
            }
            else if (noteHitPos < goodRankYBegin && noteHitPos > goodRankYEnd)
            {
                frontNote.Good();

                if (onHitEvent != null)
                {
                    onHitEvent(trackNumber, Rank.GOOD);
                }

                queueForTracks[trackNumber].Dequeue();
            }
            else if (noteHitPos < okayRankYBegin && noteHitPos > okayRankYEnd)
            {
                frontNote.Okay();

                if (onHitEvent != null)
                {
                    onHitEvent(trackNumber, Rank.OKAY);
                }

                queueForTracks[trackNumber].Dequeue();
            }
        }
    }
コード例 #2
0
    public MusicNoteController CreateAndGetNote(float startPosX, float startPosY, float endPosY, float removePosY, float startPosZ, float noteBeat)
    {
        // check if there is an inactive instance
        foreach (MusicNoteController note in noteList)
        {
            if (!note.gameObject.activeInHierarchy)
            {
                note.Initialize(startPosX, startPosY, endPosY, removePosY, startPosZ, noteBeat);
                note.gameObject.SetActive(true);

                return(note);
            }
        }

        // no inactive instance, so insantiate a new GetComponent
        MusicNoteController musicNote = ((GameObject)Instantiate(notePrefab)).GetComponent <MusicNoteController>();

        musicNote.Initialize(startPosX, startPosY, endPosY, removePosY, startPosZ, noteBeat);
        noteList.Add(musicNote);

        return(musicNote);
    }
コード例 #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();
            }
        }
    }