385 lines
13 KiB
C#
385 lines
13 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using Dreamteck.Splines;
|
||
using Ichni.RhythmGame.Beatmap;
|
||
using UniRx;
|
||
using Unity.VisualScripting;
|
||
using UnityEngine;
|
||
using UnityEngine.Serialization;
|
||
|
||
namespace Ichni.RhythmGame
|
||
{
|
||
public partial class Hold : NoteBase
|
||
{
|
||
public float holdEndTime;
|
||
public float holdingTime;
|
||
public bool isHolding;
|
||
public float holdingBufferTime;
|
||
public float bufferTimer;
|
||
|
||
public float preTimeDifference;
|
||
public NoteJudgeType preJudgeType;
|
||
public float postTimeDifference;
|
||
public NoteJudgeType postJudgeType;
|
||
|
||
public static Hold GenerateElement(string elementName, Guid id, List<string> tags, bool isFirstGenerated,
|
||
GameElement parentElement, float exactJudgeTime, float holdEndTime)
|
||
{
|
||
Hold hold = Instantiate(GameManager.instance.basePrefabs.holdNote, parentElement.transform).GetComponent<Hold>();
|
||
|
||
hold.Initialize(elementName, id, tags, isFirstGenerated, parentElement);
|
||
hold.exactJudgeTime = exactJudgeTime;
|
||
hold.holdEndTime = holdEndTime;
|
||
hold.holdingTime = 0;
|
||
hold.holdingBufferTime = 0.1f;
|
||
hold.judgeIntervals = new NoteJudgeIntervals(
|
||
new TimeInterval(-0.15f, -0.15f), new TimeInterval(-0.15f, -0.125f),
|
||
new TimeInterval(-0.125f, -0.1f), new TimeInterval(-0.1f, 0.1f),
|
||
new TimeInterval(0.1f, 0.125f), new TimeInterval(0.125f, 0.15f), 0.15f);
|
||
hold.preJudgeType = NoteJudgeType.NotJudged;
|
||
hold.postJudgeType = NoteJudgeType.NotJudged;
|
||
|
||
if (parentElement.TryGetComponent(out Track track))
|
||
{
|
||
if (track.trackTimeSubmodule != null)
|
||
{
|
||
hold.track = track;
|
||
hold.trackPositioner = hold.AddComponent<SplinePositioner>();
|
||
hold.trackPositioner.spline = track.trackPathSubmodule.path;
|
||
hold.trackPositioner.updateMethod = SplineUser.UpdateMethod.LateUpdate;
|
||
hold.isOnTrack = true;
|
||
hold.UpdateNoteInTrack();
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("如果Note要生成在Track上,Track必须有TrackTimeSubmodule组件。");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
hold.track = null;
|
||
hold.isOnTrack = false;
|
||
}
|
||
|
||
return hold;
|
||
}
|
||
|
||
public override void ExecuteStartJudge()
|
||
{
|
||
float triggerTime = GameManager.instance.songTime;
|
||
preTimeDifference = triggerTime - exactJudgeTime;
|
||
|
||
NoteJudgeType startJudgeType = GetStartJudgeType(preTimeDifference);
|
||
preJudgeType = startJudgeType;
|
||
|
||
isFirstJudged = true;
|
||
isHolding = true;
|
||
|
||
noteAudioSubmodule.PlayHoldStartAudio();
|
||
|
||
//Debug.Log($"Hold Note Start Judge: {startJudgeType} at {triggerTime}");
|
||
}
|
||
|
||
public void ExecuteProcessJudge()
|
||
{
|
||
isHolding = true;
|
||
}
|
||
|
||
public void ExecuteFinalJudge()
|
||
{
|
||
foreach (EffectBase effect in noteVisual.effectSubmodule.effectCollection["StartHold"])
|
||
{
|
||
if (effect.nowEffectState == EffectBase.EffectState.Middle)
|
||
{
|
||
effect.Adjust();
|
||
}
|
||
}
|
||
|
||
foreach (EffectBase effect in noteVisual.effectSubmodule.effectCollection["Holding"])
|
||
{
|
||
effect.Adjust();
|
||
}
|
||
|
||
float triggerTime = GameManager.instance.songTime;
|
||
postTimeDifference = holdEndTime - triggerTime;
|
||
|
||
if (postTimeDifference <= 0.1f)
|
||
{
|
||
postJudgeType = NoteJudgeType.Perfect;
|
||
}
|
||
else if (postTimeDifference <= 0.125f)
|
||
{
|
||
postJudgeType = NoteJudgeType.Good;
|
||
}
|
||
else
|
||
{
|
||
postJudgeType = NoteJudgeType.Bad;
|
||
}
|
||
|
||
//Debug.Log($"Hold Note Final Judge: {postJudgeType} at {triggerTime} of difference {postTimeDifference}");
|
||
|
||
NoteJudgeType finalJudge = GetLowerType(preJudgeType, postJudgeType);
|
||
float finalTimeDifference = Mathf.Min(preTimeDifference, postTimeDifference);
|
||
GameManager.instance.playingRecorder.resultData.Add(finalTimeDifference);
|
||
|
||
if (finalJudge == NoteJudgeType.Perfect)
|
||
{
|
||
Perfect(triggerTime);
|
||
}
|
||
else if (finalJudge == NoteJudgeType.Good)
|
||
{
|
||
Good(triggerTime);
|
||
}
|
||
else if (finalJudge == NoteJudgeType.Bad)
|
||
{
|
||
Bad(triggerTime);
|
||
}
|
||
else if (finalJudge == NoteJudgeType.Miss)
|
||
{
|
||
Miss(triggerTime);
|
||
}
|
||
|
||
|
||
if (finalJudge != NoteJudgeType.Miss)
|
||
{
|
||
noteAudioSubmodule.PlayGeneralJudgeAudios();
|
||
}
|
||
}
|
||
}
|
||
|
||
public partial class Hold
|
||
{
|
||
public override void UpdateNoteInMovableTrack()
|
||
{
|
||
if (!isHolding && !isFinalJudged)
|
||
{
|
||
base.UpdateNoteInMovableTrack();
|
||
}
|
||
|
||
if (noteVisual is INoteVisualHold noteVisualHold)
|
||
{
|
||
noteVisualHold.UpdateHoldInMovableTrack();
|
||
}
|
||
}
|
||
|
||
public override void UpdateNoteInStaticTrack()
|
||
{
|
||
base.UpdateNoteInStaticTrack();
|
||
|
||
if (noteVisual is INoteVisualHold noteVisualHold)
|
||
{
|
||
noteVisualHold.UpdateHoldInStaticTrack();
|
||
}
|
||
}
|
||
|
||
protected override void RemoveFromCheckingList()
|
||
{
|
||
if (GameManager.instance.noteJudgeManager.checkingHoldList.Contains(this))
|
||
{
|
||
GameManager.instance.noteJudgeManager.checkingHoldList.Remove(this);
|
||
}
|
||
}
|
||
|
||
public override void SetPerfectPosition()
|
||
{
|
||
if (isOnTrack && track.trackTimeSubmodule is TrackTimeSubmoduleMovable movable)
|
||
{
|
||
holdingTime = holdEndTime - exactJudgeTime;
|
||
(noteVisual as INoteVisualHold)?.UpdateHoldInMovableTrack();
|
||
}
|
||
}
|
||
|
||
protected override void SlowOffsetAfterExactJudgeTime()
|
||
{
|
||
if (isOnTrack && track.trackTimeSubmodule is TrackTimeSubmoduleMovable movable)
|
||
{
|
||
holdingTime = GameManager.instance.songTime - exactJudgeTime;
|
||
(noteVisual as INoteVisualHold)?.UpdateHoldInMovableTrack();
|
||
}
|
||
}
|
||
}
|
||
|
||
public partial class Hold
|
||
{
|
||
public override void SetDefaultSubmodules()
|
||
{
|
||
base.SetDefaultSubmodules();
|
||
noteAudioSubmodule = new NoteAudioSubmodule(this, "DefaultTap");
|
||
}
|
||
|
||
public override void SaveBM()
|
||
{
|
||
matchedBM = new Hold_BM(elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM, exactJudgeTime, holdEndTime);
|
||
}
|
||
}
|
||
|
||
public partial class Hold
|
||
{
|
||
public bool CheckJudgeAvailability(InputUnitTap inputUnitTap)
|
||
{
|
||
return !isFirstJudged && noteJudgeSubmodule.judgeUnitList.All(judgeUnit => judgeUnit.CheckJudgeAvailability(inputUnitTap));
|
||
}
|
||
|
||
public bool CheckJudgeAvailability(InputUnitTouch inputUnitTouch)
|
||
{
|
||
return isFirstJudged && noteJudgeSubmodule.judgeUnitList.All(judgeUnit => judgeUnit.CheckJudgeAvailability(inputUnitTouch));
|
||
}
|
||
|
||
protected override void SetJudgeArea()
|
||
{
|
||
if (!SettingsManager.instance.gameSettings.debugMode)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (noteJudgeSubmodule != null)
|
||
{
|
||
if (isDuringJudging && !isFirstJudged)
|
||
{
|
||
foreach (NoteJudgeUnit unit in noteJudgeSubmodule.judgeUnitList.Where(unit => !unit.isShowingJudge))
|
||
{
|
||
unit.SetShowingJudge(true);
|
||
}
|
||
}
|
||
|
||
foreach (NoteJudgeUnit unit in noteJudgeSubmodule.judgeUnitList.Where(unit => unit.isShowingJudge))
|
||
{
|
||
unit.UpdateJudge();
|
||
}
|
||
|
||
if (!isDuringJudging && GameManager.instance.songTime > holdEndTime - 2 * Time.deltaTime)
|
||
{
|
||
foreach (NoteJudgeUnit unit in noteJudgeSubmodule.judgeUnitList.Where(unit => unit.isShowingJudge))
|
||
{
|
||
unit.SetShowingJudge(false);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
public partial class Hold
|
||
{
|
||
protected override void Update()
|
||
{
|
||
float songTime = GameManager.instance.songTime;
|
||
|
||
if (!isFirstJudged && !isDuringJudging &&
|
||
songTime >= exactJudgeTime + judgeIntervals.beforeMiss.intervalStart &&
|
||
!GameManager.instance.noteJudgeManager.checkingHoldList.Contains(this))
|
||
{
|
||
isDuringJudging = true;
|
||
GameManager.instance.noteJudgeManager.checkingHoldList.Add(this);
|
||
}
|
||
|
||
if (!GameManager.instance.audioManager.isUpdating || isFinalJudged)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (isHolding)
|
||
{
|
||
holdingTime = songTime - exactJudgeTime;
|
||
bufferTimer = holdingBufferTime;
|
||
}
|
||
else if(isFirstJudged)
|
||
{
|
||
bufferTimer -= Time.deltaTime;
|
||
}
|
||
|
||
if (isOnTrack)
|
||
{
|
||
UpdateNoteInTrack();
|
||
}
|
||
|
||
if (isDuringJudging)
|
||
{
|
||
noteScreenPosition = GetScreenPosition();
|
||
}
|
||
|
||
SetJudgeArea();
|
||
|
||
if (!isFirstJudged && exactJudgeTime < GameManager.instance.songTime)
|
||
{
|
||
SlowOffsetAfterExactJudgeTime();
|
||
}
|
||
|
||
foreach (EffectBase e in noteVisual.effectSubmodule.effectCollection["Generate"])
|
||
{
|
||
e.UpdateEffect(exactJudgeTime);
|
||
}
|
||
|
||
foreach (EffectBase e in noteVisual.effectSubmodule.effectCollection["StartHold"])
|
||
{
|
||
e.UpdateEffect(exactJudgeTime);
|
||
}
|
||
|
||
foreach (EffectBase e in noteVisual.effectSubmodule.effectCollection["Holding"])
|
||
{
|
||
e.UpdateEffect(exactJudgeTime);
|
||
}
|
||
|
||
if (isFirstJudged && songTime > holdEndTime)
|
||
{
|
||
isHolding = false;
|
||
isFinalJudged = true;
|
||
ExecuteFinalJudge();
|
||
RemoveFromCheckingList();
|
||
}
|
||
|
||
if (isFirstJudged && bufferTimer < 0f)
|
||
{
|
||
isHolding = false;
|
||
isFinalJudged = true;
|
||
|
||
foreach (EffectBase e in noteVisual.effectSubmodule.effectCollection["StartHold"])
|
||
{
|
||
e.Disrupt();
|
||
}
|
||
|
||
ExecuteFinalJudge();
|
||
RemoveFromCheckingList();
|
||
}
|
||
|
||
if (!isFirstJudged && GameManager.instance.songTime > exactJudgeTime + judgeIntervals.afterMiss)
|
||
{
|
||
Miss(exactJudgeTime + judgeIntervals.afterMiss);
|
||
isFirstJudged = true;
|
||
isFinalJudged = true;
|
||
RemoveFromCheckingList();
|
||
}
|
||
}
|
||
|
||
private void LateUpdate()
|
||
{
|
||
isHolding = false;
|
||
}
|
||
}
|
||
|
||
namespace Beatmap
|
||
{
|
||
public class Hold_BM : NoteBase_BM
|
||
{
|
||
public float holdEndTime;
|
||
|
||
public Hold_BM()
|
||
{
|
||
|
||
}
|
||
|
||
public Hold_BM(string elementName, Guid elementGuid, List<string> tags, GameElement_BM attachedElement, float exactJudgeTime, float holdEndTime)
|
||
: base(elementName, elementGuid, tags, attachedElement, exactJudgeTime)
|
||
{
|
||
this.holdEndTime = holdEndTime;
|
||
}
|
||
|
||
public override void ExecuteBM()
|
||
{
|
||
matchedElement = Hold.GenerateElement(elementName, elementGuid, tags, false,
|
||
GetElement(attachedElementGuid), exactJudgeTime, holdEndTime);
|
||
}
|
||
}
|
||
}
|
||
} |