コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (HasSongChanged())
        {
            Timing.ClearSongUpdatedFlag();
            // If the song has changed, #1 -- Get the new song and generate the pending roll key list.
            song           = Song.GetCurrentSong();
            events         = SongAnalyzer.generateEventList(song);
            currentEvent   = 0;
            pianoRollEvent = 0;

            // #2 - clear error keys, regardless of expiration. Not sure why, but without this step,
            // keys can be redrawn as error keys after they are destroyed.
            foreach (var key in ErrorKeys)
            {
                keyHighlighter.SetKeyHighlight(false, key.Key);
                ErrorKeys.Remove(key.Key);
            }

            // #3 - Destroy all piano roll keys, and prepare the first bar
            keyHighlighter.DestroyAllPianoRollItems();
            NextBar(0);
            LastBar = 1;
        }
        else
        {
            CurrentBar = Timing.GetCurrentBar();
            if (CurrentBar != LastBar)
            {
                NextBar(CurrentBar - 1);
            }
            LastBar = CurrentBar;
        }


        //figure out what events happened in the last frame and handle it!
        if (song != null)
        {
            /*
             * //key highlighting.
             * while (currentEvent < events.Count)
             * {
             *  SongEvent e = (SongEvent)events[currentEvent];
             *  if (e.measureNumber <=Timing.CurrentMeasure)
             *  {
             *      //process e.
             *      keyHighlighter.SetKeyHighlight(e.isStart, e.keyID);
             *      currentEvent++;
             *  }
             *  else { break; }
             * }*/

            //tolerance updating:

            /*while (toleranceRunner < tolerance.Count)
             * {
             *  SongEvent e = (SongEvent)tolerance[toleranceRunner];
             *  if (e.MeasureNumber <= Timing.CurrentMeasure)
             *  {
             *      //process e.
             *      if (e.IsStart) activeNotes.Add(e.KeyID);
             *      else activeNotes.Remove(e.KeyID);
             *      toleranceRunner++;
             *  }
             *  else { break; }
             * }*/


            //piano roll
            float futureTick = Timing.CurrentMeasure + 2 * Timing.BeatsPerMeasure;
            while (pianoRollEvent < events.Count)
            {
                SongEvent e = (SongEvent)events[pianoRollEvent];
                if (e.EndPoint <= futureTick)
                {
                    //process e.
                    startDroplet(e, futureTick);
                    pianoRollEvent++;
                }
                else
                {
                    break;
                }
            }

            // clear error keys, if they have expired
            foreach (var key in ErrorKeys)
            {
                if (key.Value < Timing.CurrentMeasure)
                {
                    keyHighlighter.SetKeyHighlight(false, key.Key);
                    ErrorKeys.Remove(key.Key);
                }
            }
        }


        Vector3 oldpos = playhead.transform.position;

        playhead.transform.position = new Vector3(GetPositionFromBeat(Timing.GetCurrentBeat(), 0), oldpos.y, oldpos.z);
    }