コード例 #1
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();
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        void Start()
        {
            // 读取设置
            var option = UserSaveData.GetOption();

            PlayManager.PanelPosition  = option.PanelPosition;
            PlayManager.TargetLineType = option.TargetLineType;
            PlayManager.JudgmentOffset = option.JudgmentOffset;

            // 初始化面板
            var panel = Instantiate(Resources.Load <GameObject>("Skin/Panel/" + PanelResource));

            panel.transform.SetParent(GameObject.Find("Canvas").transform, false);
            // 面板位置
            panel.transform.localPosition = new Vector3(
                (int)PlayManager.PanelPosition,
                panel.transform.localPosition.y,
                0
                );

            // 初始化音符
            var noteType = Resources.Load <NoteType>("Skin/Note/" + NoteResource);

            notes        = noteType.Notes;
            NoteUseScale = noteType.UseScale;
            NoteSize     = noteType.NoteSize[PlayManager.NumLines - 4];
            var target = Instantiate(noteType.Target[PlayManager.NumLines - 4]);

            target.transform.SetParent(panel.transform.Find("Target"), false);
            noteTargetAnim = target.GetComponent <Animation>();

            // 判定线偏移
            target.transform.parent.localPosition = new Vector3(
                target.transform.parent.localPosition.x,
                target.transform.parent.localPosition.y + (int)PlayManager.TargetLineType,
                0);

            // 节奏线
            measureLine = panel.GetComponent <Panel>().MeasureLine;

            // 初始化对象池
            for (int i = 0; i < PlayManager.NumLines; i++)
            {
                switch (notes[PlayManager.NumLines - 4].NotePrefab[i].GetComponent <NoteInLine>().Type)
                {
                case NoteInLine.NoteType.A:
                    if (notePoolA == null)
                    {
                        notePoolA = new ObjectPool();
                        for (int j = 0; j < 20; j++)
                        {
                            var note = Instantiate(notes[PlayManager.NumLines - 4].NotePrefab[i]);
                            note.GetComponent <NoteInLine>().Recycle(notePoolA);
                        }
                    }
                    break;

                case NoteInLine.NoteType.B:
                    if (notePoolB == null)
                    {
                        notePoolB = new ObjectPool();
                        for (int j = 0; j < 15; j++)
                        {
                            var note = Instantiate(notes[PlayManager.NumLines - 4].NotePrefab[i]);
                            note.GetComponent <NoteInLine>().Recycle(notePoolB);
                        }
                    }
                    break;

                case NoteInLine.NoteType.C:
                    if (notePoolC == null)
                    {
                        notePoolC = new ObjectPool();
                        for (int j = 0; j < 10; j++)
                        {
                            var note = Instantiate(notes[PlayManager.NumLines - 4].NotePrefab[i]);
                            note.GetComponent <NoteInLine>().Recycle(notePoolC);
                        }
                    }
                    break;

                default: continue;
                }
            }
            if (measureLinePool == null)
            {
                measureLinePool = new ObjectPool();
                for (int i = 0; i < 2; i++)
                {
                    var line = Instantiate(measureLine);
                    line.GetComponent <MeasureLine>().Recycle(measureLinePool);
                }
            }

            // 找节奏灯
            grooveLightAnim = panel.transform.Find("Groove").GetComponent <Animation>();
            // 找HP
            HP       = (RectTransform)panel.transform.Find("HP");
            HPHeight = HP.sizeDelta.y;

            // 找按键动画
            linesUpdate = new bool[PlayManager.NumLines];
            linesAnim   = new Animation[PlayManager.NumLines];
            for (int i = 0; i < PlayManager.NumLines; i++)
            {
                linesAnim[i] = panel.transform.Find("Lines/" + PlayManager.NumLines + "/Line" + (i + 1)).GetComponent <Animation>();
            }

            // 选择正确的按键ui
            for (int i = 4; i <= PlayManager.MaxLines; i++)
            {
                var lines = panel.transform.Find("Lines/" + i).gameObject;
                if (i == PlayManager.NumLines)
                {
                    lines.SetActive(true);
                }
                else
                {
                    lines.SetActive(false);
                }
            }

            // 找音符节点
            noteArea = (RectTransform)panel.transform.Find("NoteArea");

            // 初始化按键火花特效
            flarePlayList     = new FlareAnimCTL[PlayManager.NumLines];
            longflarePlayList = new FlareAnimCTL[PlayManager.NumLines];
            for (int i = 0; i < PlayManager.NumLines; i++)
            {
                var flare     = Instantiate(noteType.Flare);
                var longFlare = Instantiate(panel.GetComponent <Panel>().LongFlare);
                flarePlayList[i]     = flare.GetComponent <FlareAnimCTL>();
                longflarePlayList[i] = longFlare.GetComponent <FlareAnimCTL>();
                flare.transform.SetParent(panel.transform, false);
                longFlare.transform.SetParent(panel.transform, false);
                var panelTarget = panel.transform.Find("Target");
                flare.transform.position     = new Vector3(linesAnim[i].transform.position.x, panelTarget.GetChild(0).position.y, 0);
                longFlare.transform.position = new Vector3(linesAnim[i].transform.position.x, panelTarget.GetChild(0).position.y, 0);
            }

            // 初始化判定字动画
            judgmentAnim = panel.transform.Find("Judgment").GetComponent <JudgmentAnimCTL>();
            judgmentAnim.transform.Find("FastSlow").gameObject.SetActive(option.ShowFastSlow);

            // 找连击计数器
            comboCounter = panel.transform.Find("Combo/ComboCounter").GetComponent <ComboCounter>();
            scoreText    = panel.GetComponent <Panel>().ScoreText;
            maxComboText = panel.GetComponent <Panel>().MaxComboText;

            // 生成Lines
            currentIndex = new int[PlayManager.NumLines];
            noteInLines  = new Queue <NoteInLine> [PlayManager.NumLines];
            for (int i = 0; i < PlayManager.NumLines; i++)
            {
                noteInLines[i] = new Queue <NoteInLine>();
            }

            viveMediaDecoder = GameObject.Find("Canvas").transform.Find("BGA").GetComponent <HTC.UnityPlugin.Multimedia.ViveMediaDecoder>();
            videoPlayer      = GameObject.Find("Canvas").transform.Find("BGA").GetComponent <VideoPlayer>();

            string bgaUrl;

            if (PlayManager.GameType == GameType.EZ2ON || PlayManager.GameType == GameType.EZ2DJ)
            {
                bgaUrl = Path.Combine(
                    Master.GameResourcesFolder,
                    "EZ2Series", "Ingame",
                    SongList.List[SongList.CurrentIndex].bgaName + ".mp4"
                    );
            }
            else
            {
                bgaUrl = Path.Combine(
                    Master.GameResourcesFolder,
                    PlayManager.GameType.ToString(),
                    "Ingame",
                    SongList.List[SongList.CurrentIndex].bgaName + ".mp4"
                    );
            }
            string genericBgaUrl = Path.Combine(Master.GameResourcesFolder, "GenericBGA.mp4");

            if (File.Exists(bgaUrl))
            {
                // 初始化BGA
                if (Master.IsOldWin)
                {
                    Destroy(videoPlayer);
                    viveMediaDecoder.initDecoder(bgaUrl);
                }
                else
                {
                    videoPlayer.GetComponent <RawImage>().material = null;
                    Destroy(viveMediaDecoder);
                    videoPlayer.url = bgaUrl;
                    videoPlayer.Prepare();
                }
            }
            else if (File.Exists(genericBgaUrl))
            {
                // fallback通用bga
                if (Master.IsOldWin)
                {
                    Destroy(videoPlayer);
                    viveMediaDecoder.initDecoder(genericBgaUrl);
                    viveMediaDecoder.onVideoEnd.AddListener(() =>
                    {
                        viveMediaDecoder.replay();
                    });
                }
                else
                {
                    videoPlayer.GetComponent <RawImage>().material = null;
                    Destroy(viveMediaDecoder);
                    videoPlayer.url = genericBgaUrl;
                    videoPlayer.Prepare();
                    videoPlayer.isLooping = true;
                }
            }
            else
            {
                Destroy(videoPlayer);
                Destroy(viveMediaDecoder);
            }

            // 找毛玻璃
            var frostedGlass = panel.transform.Find("FrostedGlass").gameObject;

            frostedGlass.SetActive(option.FrostedGlassEffect);

            // 找 auto play 对象
            autoObj = panel.transform.Find("Auto").gameObject;
        }
コード例 #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();
                }
            }
        }