Files
ichni_Official/Assets/Scripts/Game/GameElements/Notes/NoteObjects/Stay.cs

174 lines
5.8 KiB
C#
Raw Normal View History

2025-06-03 02:42:28 -04:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Dreamteck.Splines;
using Ichni.RhythmGame.Beatmap;
using Lean.Pool;
2025-07-21 05:42:20 -04:00
using UniRx;
2025-06-03 02:42:28 -04:00
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Serialization;
namespace Ichni.RhythmGame
{
public partial class Stay : NoteBase
{
public NoteJudgeType preJudgeType;
public static Stay GenerateElement(string elementName, Guid id, List<string> tags, bool isFirstGenerated,
GameElement parentElement, float exactJudgeTime)
{
Stay stay = Instantiate(GameManager.instance.basePrefabs.stayNote, parentElement.transform).GetComponent<Stay>();
stay.Initialize(elementName, id, tags, isFirstGenerated, parentElement);
stay.exactJudgeTime = exactJudgeTime;
stay.preJudgeType = NoteJudgeType.NotJudged;
stay.judgeIntervals = new NoteJudgeIntervals(
new TimeInterval(-0.15f, -0.15f), new TimeInterval(-0.15f, -0.15f),
2025-07-21 05:42:20 -04:00
new TimeInterval(-0.15f, -0.15f), new TimeInterval(-0.15f, 0.15f),
new TimeInterval(0.15f, 0.15f), new TimeInterval(0.15f, 0.15f), 0.15f);
2025-06-03 02:42:28 -04:00
if (parentElement.TryGetComponent(out Track track))
{
if (track.trackTimeSubmodule != null)
{
stay.track = track;
stay.trackPositioner = stay.AddComponent<SplinePositioner>();
stay.trackPositioner.spline = track.trackPathSubmodule.path;
stay.isOnTrack = true;
stay.UpdateNoteInTrack();
}
else
{
throw new Exception("如果Note要生成在Track上Track必须有TrackTimeSubmodule组件。");
}
}
else
{
stay.track = null;
stay.isOnTrack = false;
}
return stay;
}
protected override void Update()
{
float songTime = GameManager.instance.songTime;
2025-07-21 05:42:20 -04:00
if (!isFirstJudged && !isDuringJudging &&
2025-06-03 02:42:28 -04:00
songTime >= exactJudgeTime + judgeIntervals.beforeMiss.intervalStart &&
2025-08-11 14:04:06 -04:00
!GameManager.instance.noteJudgeManager.checkingStayList.Contains(this))
2025-06-03 02:42:28 -04:00
{
2025-07-21 05:42:20 -04:00
isDuringJudging = true;
2025-08-11 14:04:06 -04:00
GameManager.instance.noteJudgeManager.checkingStayList.Add(this);
2025-06-03 02:42:28 -04:00
}
base.Update();
2025-07-21 05:42:20 -04:00
ExecuteFinalJudge(songTime);
}
protected override void RemoveFromCheckingList()
{
2025-08-11 14:04:06 -04:00
if (GameManager.instance.noteJudgeManager.checkingStayList.Contains(this))
{
GameManager.instance.noteJudgeManager.checkingStayList.Remove(this);
}
2025-06-03 02:42:28 -04:00
}
public override void ExecuteStartJudge()
{
float triggerTime = GameManager.instance.songTime;
float timeDifference = triggerTime - exactJudgeTime;
NoteJudgeType startJudgeType = GetStartJudgeType(timeDifference);
2025-07-26 04:20:25 -04:00
if (startJudgeType != NoteJudgeType.Perfect)
{
return;
}
2025-08-11 14:04:06 -04:00
RemoveFromCheckingList();
2025-06-03 02:42:28 -04:00
preJudgeType = startJudgeType;
isFirstJudged = true;
}
2025-07-10 08:42:30 -04:00
public void ExecuteFinalJudge(float triggerTime)
2025-06-03 02:42:28 -04:00
{
2025-07-08 14:28:40 -04:00
if (isFirstJudged && !isFinalJudged && preJudgeType != NoteJudgeType.NotJudged &&
2025-06-03 02:42:28 -04:00
GameManager.instance.songTime >= exactJudgeTime)
{
if (preJudgeType == NoteJudgeType.Perfect)
{
Perfect(triggerTime);
2025-08-11 14:04:06 -04:00
GameManager.instance.playingRecorder.resultData.Add(0);
2025-06-03 02:42:28 -04:00
}
else if (preJudgeType == NoteJudgeType.Good)
{
Good(triggerTime);
}
else if (preJudgeType == NoteJudgeType.Bad)
{
Bad(triggerTime);
}
else if (preJudgeType == NoteJudgeType.Miss)
{
Miss(triggerTime);
}
2025-07-10 08:42:30 -04:00
if (preJudgeType != NoteJudgeType.Miss)
{
noteAudioSubmodule.PlayGeneralJudgeAudios();
}
2025-07-08 14:28:40 -04:00
isFinalJudged = true;
2025-06-03 02:42:28 -04:00
}
}
}
public partial class Stay
{
public override void SetDefaultSubmodules()
{
base.SetDefaultSubmodules();
noteAudioSubmodule = new NoteAudioSubmodule(this, "DefaultStay");
}
public override void SaveBM()
{
matchedBM = new Stay_BM(elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM, exactJudgeTime);
}
}
public partial class Stay
{
2025-07-21 05:42:20 -04:00
public bool CheckJudgeAvailability(InputUnitTouch inputUnitTouch)
2025-06-03 02:42:28 -04:00
{
2025-07-21 05:42:20 -04:00
return noteJudgeSubmodule.judgeUnitList.All(judgeUnit => judgeUnit.CheckJudgeAvailability(inputUnitTouch));
2025-06-03 02:42:28 -04:00
}
}
namespace Beatmap
{
public class Stay_BM : NoteBase_BM
{
public Stay_BM()
{
}
public Stay_BM(string elementName, Guid elementGuid, List<string> tags, GameElement_BM attachedElement, float exactJudgeTime)
: base(elementName, elementGuid, tags, attachedElement, exactJudgeTime)
{
}
public override void ExecuteBM()
{
matchedElement = Stay.GenerateElement(elementName, elementGuid, tags, false,
GetElement(attachedElementGuid), exactJudgeTime);
}
}
}
}