2025-06-03 02:42:28 -04:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
2025-07-21 05:42:20 -04:00
|
|
|
|
using System.Linq;
|
2025-06-03 02:42:28 -04:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ichni.RhythmGame
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class Flick : NoteBase
|
|
|
|
|
|
{
|
2025-07-26 04:20:25 -04:00
|
|
|
|
public NoteJudgeType preJudgeType;
|
|
|
|
|
|
|
2025-06-03 02:42:28 -04:00
|
|
|
|
public List<Vector2> availableFlickDirections;
|
2025-07-21 05:42:20 -04:00
|
|
|
|
public float flickBuffer = 0.5f;
|
2025-06-03 02:42:28 -04:00
|
|
|
|
|
|
|
|
|
|
public static Flick GenerateElement(string elementName, Guid id, List<string> tags, bool isFirstGenerated,
|
|
|
|
|
|
GameElement parentElement, float exactJudgeTime, List<Vector2> directions)
|
|
|
|
|
|
{
|
|
|
|
|
|
Flick flick = Instantiate(GameManager.instance.basePrefabs.flickNote, parentElement.transform).GetComponent<Flick>();
|
|
|
|
|
|
|
|
|
|
|
|
flick.Initialize(elementName, id, tags, isFirstGenerated, parentElement);
|
|
|
|
|
|
flick.exactJudgeTime = exactJudgeTime;
|
2025-07-21 05:42:20 -04:00
|
|
|
|
flick.availableFlickDirections = new List<Vector2>() { Vector2.left, Vector2.right };
|
|
|
|
|
|
flick.judgeIntervals = new NoteJudgeIntervals(
|
|
|
|
|
|
new TimeInterval(-0.15f, -0.15f), new TimeInterval(-0.15f, -0.15f),
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
flick.track = track;
|
|
|
|
|
|
flick.trackPositioner = flick.AddComponent<SplinePositioner>();
|
|
|
|
|
|
flick.trackPositioner.spline = track.trackPathSubmodule.path;
|
|
|
|
|
|
flick.isOnTrack = true;
|
|
|
|
|
|
flick.UpdateNoteInTrack();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new System.Exception("如果Note要生成在Track上,Track必须有TrackTimeSubmodule组件。");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
flick.track = null;
|
|
|
|
|
|
flick.isOnTrack = false;
|
|
|
|
|
|
}
|
2025-07-21 05:42:20 -04:00
|
|
|
|
|
2025-06-03 02:42:28 -04:00
|
|
|
|
return flick;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-21 05:42:20 -04:00
|
|
|
|
protected override void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
float songTime = GameManager.instance.songTime;
|
|
|
|
|
|
|
|
|
|
|
|
if (!isFirstJudged && !isDuringJudging &&
|
|
|
|
|
|
songTime >= exactJudgeTime + judgeIntervals.beforeMiss.intervalStart &&
|
2025-08-11 14:04:06 -04:00
|
|
|
|
!GameManager.instance.noteJudgeManager.checkingFlickList.Contains(this))
|
2025-07-21 05:42:20 -04:00
|
|
|
|
{
|
|
|
|
|
|
isDuringJudging = true;
|
2025-08-11 14:04:06 -04:00
|
|
|
|
GameManager.instance.noteJudgeManager.checkingFlickList.Add(this);
|
2025-07-21 05:42:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
base.Update();
|
2025-07-26 04:20:25 -04:00
|
|
|
|
ExecuteFinalJudge(songTime);
|
2025-07-21 05:42:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void RemoveFromCheckingList()
|
|
|
|
|
|
{
|
2025-08-11 14:04:06 -04:00
|
|
|
|
if (GameManager.instance.noteJudgeManager.checkingFlickList.Contains(this))
|
2025-07-26 04:20:25 -04:00
|
|
|
|
{
|
2025-08-11 14:04:06 -04:00
|
|
|
|
GameManager.instance.noteJudgeManager.checkingFlickList.Remove(this);
|
2025-07-26 04:20:25 -04:00
|
|
|
|
}
|
2025-07-21 05:42:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void ExecuteStartJudge()
|
|
|
|
|
|
{
|
2025-07-26 04:20:25 -04:00
|
|
|
|
float triggerTime = GameManager.instance.songTime;
|
|
|
|
|
|
float timeDifference = triggerTime - exactJudgeTime;
|
|
|
|
|
|
|
|
|
|
|
|
NoteJudgeType startJudgeType = GetStartJudgeType(timeDifference);
|
2025-07-21 05:42:20 -04:00
|
|
|
|
|
2025-07-26 04:20:25 -04:00
|
|
|
|
if (startJudgeType != NoteJudgeType.Perfect)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-08-11 14:04:06 -04:00
|
|
|
|
RemoveFromCheckingList();
|
2025-07-21 05:42:20 -04:00
|
|
|
|
|
2025-07-26 04:20:25 -04:00
|
|
|
|
preJudgeType = startJudgeType;
|
|
|
|
|
|
isFirstJudged = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ExecuteFinalJudge(float triggerTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isFirstJudged && !isFinalJudged && preJudgeType != NoteJudgeType.NotJudged &&
|
|
|
|
|
|
GameManager.instance.songTime >= exactJudgeTime)
|
2025-07-21 05:42:20 -04:00
|
|
|
|
{
|
2025-07-26 04:20:25 -04:00
|
|
|
|
if (preJudgeType == NoteJudgeType.Perfect)
|
|
|
|
|
|
{
|
|
|
|
|
|
Perfect(triggerTime);
|
2025-08-11 14:04:06 -04:00
|
|
|
|
GameManager.instance.playingRecorder.resultData.Add(0);
|
2025-07-26 04:20:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
else if (preJudgeType == NoteJudgeType.Good)
|
|
|
|
|
|
{
|
|
|
|
|
|
Good(triggerTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (preJudgeType == NoteJudgeType.Bad)
|
|
|
|
|
|
{
|
|
|
|
|
|
Bad(triggerTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (preJudgeType == NoteJudgeType.Miss)
|
|
|
|
|
|
{
|
|
|
|
|
|
Miss(triggerTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (preJudgeType != NoteJudgeType.Miss)
|
|
|
|
|
|
{
|
|
|
|
|
|
noteAudioSubmodule.PlayGeneralJudgeAudios();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isFinalJudged = true;
|
2025-07-21 05:42:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public partial class Flick
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool CheckJudgeAvailability(InputUnitSwipe inputUnitSwipe)
|
2025-06-03 02:42:28 -04:00
|
|
|
|
{
|
2025-07-21 05:42:20 -04:00
|
|
|
|
return noteJudgeSubmodule.judgeUnitList.All(judgeUnit => judgeUnit.CheckJudgeAvailability(inputUnitSwipe));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-26 04:20:25 -04:00
|
|
|
|
public bool CheckSwipeDirection(InputUnitSwipe inputUnitSwipe)
|
2025-07-21 05:42:20 -04:00
|
|
|
|
{
|
2025-07-26 04:20:25 -04:00
|
|
|
|
if (inputUnitSwipe.isGeneric)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log($"输入方向 {inputUnitSwipe.swipeDirection} 是通用的,直接匹配成功。");
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-21 05:42:20 -04:00
|
|
|
|
Camera gameCamera = GameManager.instance.cameraManager.gameCamera.gameCamera;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (Vector2 localDir in availableFlickDirections)
|
|
|
|
|
|
{
|
|
|
|
|
|
Vector3 worldDirection = noteVisual.transform.TransformDirection(localDir.normalized);
|
|
|
|
|
|
Vector3 noteOriginWorld = noteVisual.transform.position;
|
|
|
|
|
|
Vector3 noteTargetWorld = noteOriginWorld + worldDirection;
|
|
|
|
|
|
|
|
|
|
|
|
Vector3 screenOrigin = gameCamera.WorldToScreenPoint(noteOriginWorld);
|
|
|
|
|
|
Vector3 screenTarget = gameCamera.WorldToScreenPoint(noteTargetWorld);
|
|
|
|
|
|
|
|
|
|
|
|
Vector2 noteScreenDirection = new Vector2(screenTarget.x - screenOrigin.x, screenTarget.y - screenOrigin.y).normalized;
|
|
|
|
|
|
|
|
|
|
|
|
if (noteScreenDirection.sqrMagnitude < 0.01f)
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-26 04:20:25 -04:00
|
|
|
|
float dotProduct = Vector2.Dot(inputUnitSwipe.swipeDirection, noteScreenDirection);
|
2025-07-21 05:42:20 -04:00
|
|
|
|
|
|
|
|
|
|
// 4. 检查点积是否满足阈值
|
|
|
|
|
|
if (dotProduct >= flickBuffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 匹配成功!无需再检查其他方向。
|
2025-07-26 04:20:25 -04:00
|
|
|
|
Debug.Log($"匹配成功! 输入方向 {inputUnitSwipe.swipeDirection} 匹配了本地方向 {localDir} (屏幕投影: {noteScreenDirection}), 点积: {dotProduct}");
|
2025-07-21 05:42:20 -04:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-03 02:42:28 -04:00
|
|
|
|
|
2025-07-26 04:20:25 -04:00
|
|
|
|
Debug.Log($"匹配失败. 输入方向 {inputUnitSwipe.swipeDirection} 未匹配任何允许的方向。");
|
2025-07-21 05:42:20 -04:00
|
|
|
|
return false;
|
2025-06-03 02:42:28 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public partial class Flick
|
|
|
|
|
|
{
|
|
|
|
|
|
public override void SetDefaultSubmodules()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.SetDefaultSubmodules();
|
|
|
|
|
|
noteAudioSubmodule = new NoteAudioSubmodule(this, "DefaultStay");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void SaveBM()
|
|
|
|
|
|
{
|
|
|
|
|
|
matchedBM = new Flick_BM(elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM,
|
|
|
|
|
|
exactJudgeTime, availableFlickDirections);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace Beatmap
|
|
|
|
|
|
{
|
|
|
|
|
|
public class Flick_BM : NoteBase_BM
|
|
|
|
|
|
{
|
|
|
|
|
|
public List<Vector2> availableFlickDirections;
|
|
|
|
|
|
|
|
|
|
|
|
public Flick_BM()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Flick_BM(string elementName, Guid elementGuid, List<string> tags, GameElement_BM attachedElement,
|
|
|
|
|
|
float exactJudgeTime,
|
|
|
|
|
|
List<Vector2> directions) : base(elementName, elementGuid, tags, attachedElement, exactJudgeTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
availableFlickDirections = directions;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void ExecuteBM()
|
|
|
|
|
|
{
|
|
|
|
|
|
matchedElement = Flick.GenerateElement(elementName, elementGuid, tags, false,
|
|
|
|
|
|
GetElement(attachedElementGuid), exactJudgeTime, availableFlickDirections);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|