예제 #1
0
 void updateLongNote()
 {
     if (PlayManager.IsAutoPlay)
     {
         transform.localPosition = new Vector3(
             initX,
             (int)PlayManager.TargetLineType,
             0
             );
         rect.sizeDelta = new Vector2(
             rect.sizeDelta.x,
             (float)((Position + NoteLength - displayLoop.Position) * PlayManager.GetSpeed() / noteScale) + noteHeight
             );
     }
     else
     {
         transform.localPosition = new Vector3(
             initX,
             (int)PlayManager.TargetLineType,
             0
             );
         rect.sizeDelta = new Vector2(
             rect.sizeDelta.x,
             (float)(((Position + NoteLength - displayLoop.Position) * PlayManager.GetSpeed() - PlayManager.JudgmentOffset) / noteScale) + noteHeight
             );
     }
 }
예제 #2
0
        // 表现层循环
        void Update()
        {
            // 等待帧数稳定后开始游戏
            if (!isStarted)
            {
                readyFrame++;
                if (readyFrame > 10)
                {
                    if (viveMediaDecoder != null)
                    {
                        if (viveMediaDecoder.getDecoderState() ==
                            HTC.UnityPlugin.Multimedia.ViveMediaDecoder.DecoderState.INITIALIZED ||
                            viveMediaDecoder.getDecoderState() ==
                            HTC.UnityPlugin.Multimedia.ViveMediaDecoder.DecoderState.INIT_FAIL)
                        {
                            StartPlay();
                        }
                    }
                    if (videoPlayer != null)
                    {
                        if (videoPlayer.isPrepared)
                        {
                            StartPlay();
                        }
                    }
                    if (viveMediaDecoder == null && videoPlayer == null)
                    {
                        StartPlay();
                    }
                }
            }


            if (grooveDisplay)
            {
                grooveDisplay = false;

                // 消除误差,同步时间轴
                if (System.Math.Abs(position - PlayManager.UnscaledPosition) > 1)
                {
                    position = PlayManager.UnscaledPosition;
                }

                // 节奏灯
                grooveLightAnim["GrooveLight"].time = 0;
                grooveLightAnim.Play("GrooveLight");

                // HP跳动
                if (hpBeatCoroutine != null)
                {
                    StopCoroutine(hpBeatCoroutine);
                }
                hpBeatCoroutine = StartCoroutine(hpBeat());

                // 节奏线跳动
                foreach (var measure in MeasureLine.MeasureLines)
                {
                    measure.PlayAnim();
                }

                // 音符目标跳动
                noteTargetAnim[noteTargetAnim.clip.name].time = 0;
                noteTargetAnim.Play();
            }

            // auto play滚屏效果
            if (PlayManager.IsAutoPlay != autoObj.activeSelf)
            {
                autoObj.SetActive(PlayManager.IsAutoPlay);
            }

            // 按键表现
            for (int i = 0; i < PlayManager.NumLines; i++)
            {
                if (linesUpdate[i])
                {
                    if (Master.KeysState[i])
                    {
                        linesAnim[i].Play("KeyDown");
                    }
                    else
                    {
                        linesAnim[i]["KeyUp"].time = 0;
                        linesAnim[i].Play("KeyUp");
                    }
                    linesUpdate[i] = false;
                }
            }

            // 背景动画trigger
            if (PlayManager.IsPlayBGA)
            {
                PlayManager.IsPlayBGA = false;
                if (viveMediaDecoder != null)
                {
                    viveMediaDecoder.startDecoding();
                }
                if (videoPlayer != null)
                {
                    videoPlayer.Play();
                }
            }

            // Unity smoothDeltaTime计算Position 用于消除音符抖动
            if (isStarted)
            {
                PositionDelta = Time.smoothDeltaTime * PlayManager.TickPerSecond;
                position     += PositionDelta;

                // 记录时间
                time += Time.deltaTime;
                if (!bgaPlayed && !(PlayManager.GameType == GameType.DJMAX &&
                                    PlayManager.GameMode < EZR.GameMode.Mode.FourKey) &&
                    PlayManager.BGADelay > 0 && PlayManager.BGADelay <= time)
                {
                    if (viveMediaDecoder != null)
                    {
                        viveMediaDecoder.startDecoding();
                    }
                    if (videoPlayer != null)
                    {
                        videoPlayer.Play();
                    }
                    bgaPlayed = true;
                }
            }

            // 插值下落速度
            PlayManager.RealFallSpeed = Mathf.Lerp(PlayManager.RealFallSpeed, PlayManager.FallSpeed,
                                                   Mathf.Min(Time.deltaTime * 12, 1)
                                                   );

            var screenHeight = (noteArea.sizeDelta.y +
                                (PlayManager.IsAutoPlay ? 0 : PlayManager.JudgmentOffset)) /
                               PlayManager.GetSpeed() / JudgmentDelta.MeasureScale;

            // 生成实时音符
            for (int i = 0; i < PlayManager.NumLines; i++)
            {
                while (currentIndex[i] < PlayManager.TimeLine.Lines[i].Notes.Count &&
                       PlayManager.TimeLine.Lines[i].Notes[currentIndex[i]].position - position < screenHeight)
                {
                    // 测试长音符
                    // if (PlayManager.TimeLines.Lines[i].Notes[currentIndex[i]].length <= 6)
                    // {
                    //     currentIndex[i]++;
                    //     continue;
                    // }

                    // 选择对象池;
                    ObjectPool pool;
                    switch (notes[PlayManager.NumLines - 4].NotePrefab[i].GetComponent <NoteInLine>().Type)
                    {
                    case NoteInLine.NoteType.A:
                        pool = notePoolA;
                        break;

                    case NoteInLine.NoteType.B:
                        pool = notePoolB;
                        break;

                    case NoteInLine.NoteType.C:
                        pool = notePoolC;
                        break;

                    default:
                        currentIndex[i]++;
                        continue;
                    }
                    GameObject note;
                    if (pool.Count == 0)
                    {
                        note = Instantiate(notes[PlayManager.NumLines - 4].NotePrefab[i]);
                    }
                    else
                    {
                        note = pool.Get();
                    }

                    note.transform.SetParent(noteArea, false);
                    // 新产生的音符永远在最下层
                    note.transform.SetSiblingIndex(0);

                    Pattern.Note patternNote = PlayManager.TimeLine.Lines[i].Notes[currentIndex[i]];

                    var noteInLine = note.GetComponent <NoteInLine>();
                    noteInLine.Init(currentIndex[i], patternNote.position, patternNote.length, linesAnim[i].transform.localPosition.x, this, pool);
                    noteInLines[i].Enqueue(noteInLine);

                    currentIndex[i]++;
                }
            }
            // 生成节奏线
            int currentMeasureCount = (int)((position + screenHeight) / (PatternUtils.Pattern.TickPerMeasure * (PlayManager.TimeLine.Beat * 0.25f)));

            if (currentMeasureCount > measureCount)
            {
                var measureDelta = currentMeasureCount - measureCount;
                for (int j = 0; j < measureDelta; j++)
                {
                    GameObject measureLineInstance;
                    if (measureLinePool.Count == 0)
                    {
                        measureLineInstance = Instantiate(measureLine);
                    }
                    else
                    {
                        measureLineInstance = measureLinePool.Get();
                    }

                    measureLineInstance.transform.SetParent(noteArea, false);
                    measureLineInstance.transform.SetSiblingIndex(0);
                    var measureLineComponent = measureLineInstance.GetComponent <MeasureLine>();
                    measureLineComponent.Init(measureCount + j + 1, this, measureLinePool);
                }
                measureCount = currentMeasureCount;
            }

            // 移除长音符音符
            for (int i = 0; i < PlayManager.NumLines; i++)
            {
                if (noteInLines[i].Count > 0)
                {
                    var noteInLine = noteInLines[i].Peek();
                    if (noteInLine == null ||
                        noteInLine.Position + noteInLine.NoteLength - PlayManager.Position < -(JudgmentDelta.Miss + 1))
                    {
                        noteInLines[i].Dequeue();
                    }
                }
            }

            // 连击动画
            if (combo != PlayManager.Combo)
            {
                if (PlayManager.Combo == 0)
                {
                    comboCounter.Clear();
                }
                else
                {
                    combo = PlayManager.Combo;
                    comboCounter.SetCombo(combo);
                }
            }

            // 分数
            scoreText.text = Mathf.Round(PlayManager.Score.RawScore).ToString();
            // 最大连击
            maxComboText.text = PlayManager.Score.MaxCombo.ToString();

            // 修复BGA重复播放问题
            if (videoPlayer != null &&
                !videoPlayer.isLooping &&
                !videoPlayer.isPaused &&
                videoPlayer.frameCount > 0 &&
                (ulong)videoPlayer.frame == videoPlayer.frameCount)
            {
                videoPlayer.Pause();
            }
        }
예제 #3
0
 void updateMeasure()
 {
     if (PlayManager.IsAutoPlay)
     {
         transform.localPosition = new Vector3(
             0,
             (float)((Index * PatternUtils.Pattern.TickPerMeasure * (PlayManager.TimeLine.Beat * 0.25f) - displayLoop.Position) * PlayManager.GetSpeed()) + (int)PlayManager.TargetLineType,
             0
             );
     }
     else
     {
         transform.localPosition = new Vector3(
             0,
             (float)((Index * PatternUtils.Pattern.TickPerMeasure * (PlayManager.TimeLine.Beat * 0.25f) - displayLoop.Position) * PlayManager.GetSpeed()) + (int)PlayManager.TargetLineType - PlayManager.JudgmentOffset,
             0
             );
     }
 }