예제 #1
0
            void OnDestroy()
            {
                TaskExitFlag = 1;
#if (UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN)
                timeEndPeriod(1);
#endif
                MemorySound.StopSound();
            }
예제 #2
0
        public static void Loop(Queue <NoteInLine>[] noteInLines, JudgmentAnimCTL judgmentAnim, FlareAnimCTL[] flarePlayList, FlareAnimCTL[] LongflarePlayList)
        {
            for (int i = 0; i < PlayManager.NumLines; i++)
            {
                if (noteInLines[i].Count > 0 && noteInLines[i].Peek() != null)
                {
                    var noteInLine = noteInLines[i].Peek();
                    if (noteInLine.IsLongPressed)
                    {
                        // 长音连击
                        int longNoteCombo = Mathf.Min(noteInLine.LongNoteCount, (int)(
                                                          (System.Math.Min(PlayManager.Position, noteInLine.Position + noteInLine.NoteLength) - noteInLine.Position) /
                                                          (LongNoteComboStep * JudgmentDelta.MeasureScale)) + 1);
                        if (longNoteCombo > noteInLine.LongNoteCombo)
                        {
                            var delta = longNoteCombo - noteInLine.LongNoteCombo;
                            for (int j = 0; j < delta; j++)
                            {
                                PlayManager.AddCombo();
                                PlayManager.AddScore(noteInLine.LongNoteJudgment);
                                judgmentAnim.Play(noteInLine.LongNoteJudgment);
                                flarePlayList[i].Play(noteInLine.LongNoteJudgment);
                            }
                            noteInLine.LongNoteCombo = longNoteCombo;
                        }
                        // 自动结尾
                        if (noteInLine.Position + noteInLine.NoteLength <= PlayManager.Position)
                        {
                            LongflarePlayList[i].IsStop = true;
                            noteInLine.IsDestroy        = true;
                            noteInLines[i].Dequeue();
                        }
                    }

                    // FAIL
                    else if (noteInLine.NoteLength > 6)
                    {
                        // 长音
                        if (noteInLine.Position - PlayManager.Position < -JudgmentDelta.GetJudgmentDelta(JudgmentType.Miss, 1))
                        {
                            PlayManager.ComboBreak();
                            PlayManager.AddScore(JudgmentType.Fail);
                            judgmentAnim.Play(JudgmentType.Fail);
                            noteInLines[i].Dequeue();
                        }
                    }
                    else
                    {
                        // 短音
                        if (noteInLine.Position - PlayManager.Position < -JudgmentDelta.GetJudgmentDelta(JudgmentType.Miss, 0.5f))
                        {
                            PlayManager.ComboBreak();
                            PlayManager.AddScore(JudgmentType.Fail);
                            judgmentAnim.Play(JudgmentType.Fail);
                            noteInLines[i].Dequeue();
                        }
                    }
                }

                // Auto play
                if (PlayManager.IsAutoPlay)
                {
                    if (noteInLines[i].Count > 0 && noteInLines[i].Peek() != null)
                    {
                        var noteInLine = noteInLines[i].Peek();
                        if (noteInLine.NoteLength > 6)
                        {
                            // 长音
                            if (!noteInLine.IsLongPressed && noteInLine.Position <= PlayManager.Position)
                            {
                                var note = PlayManager.TimeLine.Lines[i].Notes[noteInLine.Index];
                                noteInLine.IsLongPressed    = true;
                                noteInLine.LongNoteJudgment = JudgmentType.Kool;
                                LongflarePlayList[i].Play();
                                MemorySound.PlaySound(note.id, note.vol, note.pan, MemorySound.Main);
                            }
                        }
                        else
                        {
                            // 短音
                            if (noteInLine.Position <= PlayManager.Position)
                            {
                                PlayManager.AddCombo();
                                PlayManager.AddScore(JudgmentType.Kool);
                                judgmentAnim.Play(JudgmentType.Kool);
                                var note = PlayManager.TimeLine.Lines[i].Notes[noteInLine.Index];
                                noteInLine.IsDestroy = true;
                                flarePlayList[i].Play();
                                MemorySound.PlaySound(note.id, note.vol, note.pan, MemorySound.Main);
                                noteInLines[i].Dequeue();
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        public static void InputEvent(bool state, int keyId, Queue <NoteInLine>[] noteInLines, JudgmentAnimCTL judgmentAnim, FlareAnimCTL[] flarePlayList, FlareAnimCTL[] LongflarePlayList)
        {
            // 按下
            if (state)
            {
                Pattern.Note note;
                NoteInLine   noteInLine;

                if (noteInLines[keyId].Count > 0 && noteInLines[keyId].Peek() != null)
                {
                    noteInLine = noteInLines[keyId].Peek();
                    note       = PlayManager.TimeLine.Lines[keyId].Notes[noteInLine.Index];

                    double judgmentDelta = noteInLine.Position - PlayManager.Position;
                    bool   isFast        = judgmentDelta > 0;
                    judgmentDelta = System.Math.Abs(judgmentDelta);

                    // 长音
                    if (note.length > 6)
                    {
                        if (JudgmentDelta.CompareJudgmentDelta(judgmentDelta, JudgmentType.Kool, 1))
                        {
                            LongflarePlayList[keyId].Play();
                            noteInLine.IsLongPressed    = true;
                            noteInLine.LongNoteJudgment = JudgmentType.Kool;
                        }
                        else if (JudgmentDelta.CompareJudgmentDelta(judgmentDelta, JudgmentType.Cool, 1))
                        {
                            judgmentAnim.ShowFastSlow(isFast);
                            LongflarePlayList[keyId].Play();
                            noteInLine.IsLongPressed    = true;
                            noteInLine.LongNoteJudgment = JudgmentType.Cool;
                        }
                        else if (JudgmentDelta.CompareJudgmentDelta(judgmentDelta, JudgmentType.Good, 1))
                        {
                            judgmentAnim.ShowFastSlow(isFast);
                            LongflarePlayList[keyId].Play(JudgmentType.Good);
                            noteInLine.IsLongPressed    = true;
                            noteInLine.LongNoteJudgment = JudgmentType.Good;
                        }
                        else if (JudgmentDelta.CompareJudgmentDelta(judgmentDelta, JudgmentType.Miss, 1))
                        {
                            PlayManager.ComboBreak();
                            PlayManager.AddScore(JudgmentType.Miss);
                            judgmentAnim.Play(JudgmentType.Miss);
                            judgmentAnim.ShowFastSlow(isFast);
                            noteInLines[keyId].Dequeue();
                        }
                    }
                    // 短音
                    else
                    {
                        if (JudgmentDelta.CompareJudgmentDelta(judgmentDelta, JudgmentType.Kool, 0.5f))
                        {
                            PlayManager.AddCombo();
                            PlayManager.AddScore(JudgmentType.Kool);
                            judgmentAnim.Play(JudgmentType.Kool);
                            flarePlayList[keyId].Play();
                            noteInLine.IsDestroy = true;
                            noteInLines[keyId].Dequeue();
                        }
                        else if (JudgmentDelta.CompareJudgmentDelta(judgmentDelta, JudgmentType.Cool, 0.5f))
                        {
                            PlayManager.AddCombo();
                            PlayManager.AddScore(JudgmentType.Cool);
                            judgmentAnim.Play(JudgmentType.Cool);
                            judgmentAnim.ShowFastSlow(isFast);
                            flarePlayList[keyId].Play();
                            noteInLine.IsDestroy = true;
                            noteInLines[keyId].Dequeue();
                        }
                        else if (JudgmentDelta.CompareJudgmentDelta(judgmentDelta, JudgmentType.Good, 0.5f))
                        {
                            PlayManager.AddCombo();
                            PlayManager.AddScore(JudgmentType.Good);
                            judgmentAnim.Play(JudgmentType.Good);
                            judgmentAnim.ShowFastSlow(isFast);
                            flarePlayList[keyId].Play(JudgmentType.Good);
                            noteInLine.IsDestroy = true;
                            noteInLines[keyId].Dequeue();
                        }
                        else if (JudgmentDelta.CompareJudgmentDelta(judgmentDelta, JudgmentType.Miss, 0.5f))
                        {
                            PlayManager.ComboBreak();
                            PlayManager.AddScore(JudgmentType.Miss);
                            judgmentAnim.Play(JudgmentType.Miss);
                            judgmentAnim.ShowFastSlow(isFast);
                            noteInLines[keyId].Dequeue();
                        }
                    }
                }
                else
                {
                    noteInLine = null;
                    if (PlayManager.TimeLine.Lines[keyId].Notes.Count > 0)
                    {
                        note = PlayManager.TimeLine.Lines[keyId].Notes[Mathf.Min(PlayManager.TimeLine.LinesIndex[keyId], PlayManager.TimeLine.Lines[keyId].Notes.Count - 1)];
                    }
                    else
                    {
                        note = null;
                    }
                }

                FMOD.Channel?channel = null;
                if (note != null)
                {
                    channel = MemorySound.PlaySound(note.id, note.vol, note.pan, MemorySound.Main);
                }
                if (noteInLine != null && note.length > 6)
                {
                    noteInLine.NoteSound = channel;
                }
            }
            // 松开
            else if (noteInLines[keyId].Count > 0 && noteInLines[keyId].Peek() != null)
            {
                var noteInLine = noteInLines[keyId].Peek();
                if (noteInLine.IsLongPressed)
                {
                    noteInLine.IsLongPressed        = false;
                    LongflarePlayList[keyId].IsStop = true;

                    bool   needStopSound = false;
                    double judgmentDelta = noteInLine.Position + noteInLine.NoteLength - PlayManager.Position;
                    bool   isFast        = judgmentDelta > 0;
                    judgmentDelta = System.Math.Abs(judgmentDelta);
                    if (judgmentDelta <= JudgmentDelta.GetJudgmentDelta(JudgmentType.Cool, 1))
                    {
                        var delta = noteInLine.LongNoteCount - noteInLine.LongNoteCombo;
                        for (int j = 0; j < delta; j++)
                        {
                            PlayManager.AddCombo();
                            PlayManager.AddScore(noteInLine.LongNoteJudgment);
                            judgmentAnim.Play(noteInLine.LongNoteJudgment);
                            flarePlayList[keyId].Play(noteInLine.LongNoteJudgment);
                        }
                        if (!JudgmentDelta.CompareJudgmentDelta(judgmentDelta, JudgmentType.Kool, 1))
                        {
                            judgmentAnim.ShowFastSlow(isFast);
                        }
                        noteInLine.IsDestroy = true;
                    }
                    else if (JudgmentDelta.CompareJudgmentDelta(judgmentDelta, JudgmentType.Good, 1))
                    {
                        var delta = noteInLine.LongNoteCount - noteInLine.LongNoteCombo;
                        for (int j = 0; j < delta; j++)
                        {
                            PlayManager.AddCombo();
                            PlayManager.AddScore(JudgmentType.Good);
                            judgmentAnim.Play(JudgmentType.Good);
                            flarePlayList[keyId].Play(JudgmentType.Good);
                        }
                        judgmentAnim.ShowFastSlow(isFast);
                        needStopSound = true;
                    }
                    else if (judgmentDelta > JudgmentDelta.GetJudgmentDelta(JudgmentType.Good, 1))
                    {
                        PlayManager.ComboBreak();
                        PlayManager.AddScore(JudgmentType.Miss);
                        judgmentAnim.Play(JudgmentType.Miss);
                        judgmentAnim.ShowFastSlow(isFast);
                        needStopSound = true;
                    }

                    if (needStopSound && noteInLine.NoteSound != null)
                    {
                        ((FMOD.Channel)noteInLine.NoteSound).stop();
                    }
                    noteInLines[keyId].Dequeue();
                }
            }
        }
예제 #4
0
        public static void MainLoop()
        {
            // bpm
            while (TimeLine.BPMIndex < TimeLine.BPMList.Count && TimeLine.BPMList[TimeLine.BPMIndex].position <= UnscaledPosition)
            {
                TimeLine.BPM = TimeLine.BPMList[TimeLine.BPMIndex].bpm;
                TimeLine.BPMIndex++;
            }
            // Beat
            while (TimeLine.BeatIndex < TimeLine.BeatList.Count && TimeLine.BeatList[TimeLine.BeatIndex].position <= UnscaledPosition)
            {
                TimeLine.Beat = TimeLine.BeatList[TimeLine.BeatIndex].beat;
                TimeLine.BeatIndex++;
            }

            // 播放音符
            for (int i = 0; i < TimeLine.MaxLines; i++)
            {
                var line = TimeLine.Lines[i];

                while (TimeLine.LinesIndex[i] < line.Notes.Count && line.Notes[TimeLine.LinesIndex[i]].position <= UnscaledPosition)
                {
                    // 跳过可玩轨道
                    if (i > 7)
                    {
                        var note = line.Notes[TimeLine.LinesIndex[i]];

                        if (PlayManager.GameType == GameType.DJMAX &&
                            PlayManager.GameMode < EZR.GameMode.Mode.FourKey &&
                            note.id == 0)
                        {
                            IsPlayBGA = true;
                        }

                        MemorySound.PlaySound(note.id, note.vol, note.pan, MemorySound.BGM);

                        // debug事件
                        if (DebugEvent != null)
                        {
                            DebugEvent(string.Format(
                                           "[{3}] Sound: {0}\n[vol: {1}] [pan:{2}]",
                                           TimeLine.SoundList[note.id].filename,
                                           (int)(note.vol * 100),
                                           (int)(note.pan * 100),
                                           (int)Position
                                           ), note.id);
                        }
                    }

                    TimeLine.LinesIndex[i]++;
                }
            }

            long now = Stopwatch.ElapsedTicks;

            DeltaTime = (now - lastTime) / 10000000d;
            lastTime  = now;

            TickPerSecond     = TimeLine.BPM * 0.25d * PatternUtils.Pattern.TickPerMeasure / 60d;
            PositionDelta     = DeltaTime * TickPerSecond;
            UnscaledPosition += PositionDelta;

            // 检测结束
            if (UnscaledPosition >= TimeLine.EndTick)
            {
                Stop();
                if (LoopStop != null)
                {
                    LoopStop();
                }
                return;
            }

            beat += DeltaTime * (TimeLine.BPM / 60d);

            // 节奏事件
            if (beat >= 1)
            {
                beat -= 1;
                if (Groove != null)
                {
                    Groove();
                }
            }
        }