长音符再修复 加入了关卡连接 优化了一些默认加载
This commit is contained in:
@@ -10,8 +10,25 @@ public class Note : BaseNote
|
||||
|
||||
private NoteData noteData;
|
||||
|
||||
[Header("判定区间配置")]
|
||||
public NoteJudgeConfig judgeConfig; // 判定区间配置,需在预制体或生成时赋值
|
||||
[Header("���������")]
|
||||
public NoteJudgeConfig judgeConfig; // �ж��������ã�����Ԥ���������ʱ��ֵ
|
||||
|
||||
// Cache allies per track to avoid GameObject.Find on every judge.
|
||||
private static AllyCombatant[] allyCache;
|
||||
|
||||
private static AllyCombatant GetAllyForTrackCached(int trackIndex)
|
||||
{
|
||||
if (trackIndex < 0) return null;
|
||||
if (allyCache == null || allyCache.Length < 10) allyCache = new AllyCombatant[10];
|
||||
if (allyCache[trackIndex] != null) return allyCache[trackIndex];
|
||||
|
||||
var allyGo = GameObject.Find($"ally_0{trackIndex + 1}");
|
||||
if (allyGo != null)
|
||||
{
|
||||
allyCache[trackIndex] = allyGo.GetComponent<AllyCombatant>();
|
||||
}
|
||||
return allyCache[trackIndex];
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -37,11 +54,15 @@ public class Note : BaseNote
|
||||
|
||||
InputManager.OnKeyPressed += HandlePress;
|
||||
|
||||
// 判定区间配置检查
|
||||
// �ж��������ü��
|
||||
if (judgeConfig == null)
|
||||
Debug.LogError($"NoteJudgeConfig is null! 判定区间配置未传入!track={trackIndex}");
|
||||
{
|
||||
if (GameConfig.verboseLogs) Debug.LogError($"NoteJudgeConfig is null! �ж���������δ���룡track={trackIndex}");
|
||||
}
|
||||
else
|
||||
Debug.Log($"NoteJudgeConfig: perfect={judgeConfig.perfectRange}, great={judgeConfig.greatRange}, good={judgeConfig.goodRange}, miss={judgeConfig.missRange}");
|
||||
{
|
||||
if (GameConfig.verboseLogs) Debug.Log($"NoteJudgeConfig: perfect={judgeConfig.perfectRange}, great={judgeConfig.greatRange}, good={judgeConfig.goodRange}, miss={judgeConfig.missRange}");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -51,12 +72,12 @@ public class Note : BaseNote
|
||||
|
||||
private void HandlePress(KeyCode key)
|
||||
{
|
||||
// 只判定正确轨道且在判定区
|
||||
// ֻ�ж���ȷ��������ж���
|
||||
if (isJudged || key != keyToPress || (controller != null && !controller.IsInJudgeZone()))
|
||||
return;
|
||||
|
||||
float timeDifference = Mathf.Abs(Time.time - hitTime);
|
||||
// 计算正负偏差:正值提前,负值落后
|
||||
// ��������ƫ���ֵ��ǰ����ֵ���
|
||||
float rawOffsetMs = (hitTime - Time.time) * 1000f;
|
||||
string judgeResult = null;
|
||||
|
||||
@@ -64,37 +85,29 @@ public class Note : BaseNote
|
||||
{
|
||||
if (timeDifference <= judgeConfig.perfectRange)
|
||||
{
|
||||
Debug.Log($"{keyToPress}: Perfect");
|
||||
if (GameConfig.verboseLogs) Debug.Log($"{keyToPress}: Perfect");
|
||||
judgeResult = "Perfect";
|
||||
ScoreManager.Instance.countPerfect += 1;
|
||||
if (noteData != null) noteData.judgeOffsetMs = rawOffsetMs;
|
||||
}
|
||||
else if (timeDifference <= judgeConfig.greatRange)
|
||||
{
|
||||
Debug.Log($"{keyToPress}: Great");
|
||||
if (GameConfig.verboseLogs) Debug.Log($"{keyToPress}: Great");
|
||||
judgeResult = "Great";
|
||||
ScoreManager.Instance.countGreat += 1;
|
||||
if (noteData != null) noteData.judgeOffsetMs = rawOffsetMs;
|
||||
}
|
||||
else if (timeDifference <= judgeConfig.goodRange)
|
||||
{
|
||||
Debug.Log($"{keyToPress}: Good");
|
||||
if (GameConfig.verboseLogs) Debug.Log($"{keyToPress}: Good");
|
||||
judgeResult = "Good";
|
||||
ScoreManager.Instance.countGood += 1;
|
||||
if (noteData != null) noteData.judgeOffsetMs = rawOffsetMs;
|
||||
}
|
||||
else if (timeDifference <= judgeConfig.missRange)
|
||||
{
|
||||
Debug.Log($"{keyToPress}: Miss");
|
||||
judgeResult = "Miss";
|
||||
/*ScoreManager.Instance.countMiss += 1;
|
||||
if (noteData != null) noteData.judgeOffsetMs = rawOffsetMs;*/
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"{keyToPress}: Miss");
|
||||
if (GameConfig.verboseLogs) Debug.Log($"{keyToPress}: Miss");
|
||||
judgeResult = "Miss";
|
||||
// Do not return here - let shared post-judge logic run so NotifyNoteHit is invoked for Miss as well
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -102,43 +115,36 @@ public class Note : BaseNote
|
||||
// fallback timing
|
||||
if (timeDifference <= 0.08f)
|
||||
{
|
||||
Debug.Log($"{keyToPress}: Perfect");
|
||||
if (GameConfig.verboseLogs) Debug.Log($"{keyToPress}: Perfect");
|
||||
judgeResult = "Perfect";
|
||||
}
|
||||
else if (timeDifference <= 0.15f)
|
||||
{
|
||||
Debug.Log($"{keyToPress}: Great");
|
||||
if (GameConfig.verboseLogs) Debug.Log($"{keyToPress}: Great");
|
||||
judgeResult = "Great";
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"{keyToPress}: Miss");
|
||||
if (GameConfig.verboseLogs) Debug.Log($"{keyToPress}: Miss");
|
||||
judgeResult = "Miss";
|
||||
// Do not return here - let shared post-judge logic run so NotifyNoteHit is invoked for Miss as well
|
||||
}
|
||||
}
|
||||
|
||||
// 显示判定信息
|
||||
if (!string.IsNullOrEmpty(judgeResult))
|
||||
{
|
||||
InputManager.Instance?.ShowJudgeResult(TrackIndex, judgeResult);
|
||||
JudgeSoundManager.Instance?.PlayJudgeSound(judgeResult);
|
||||
teamUIController.Instance?.OnJudgeResult(judgeResult); // 更新combo计数
|
||||
teamUIController.Instance?.OnJudgeResult(judgeResult);
|
||||
Animation_GenerateJudgementSituationPrefab.Instance?.SpawnJudgePrefab(noteColor, judgeResult);
|
||||
|
||||
// Calculate score addition via AllyCombatant and add to per-track pm sums
|
||||
try
|
||||
{
|
||||
var allyGo = GameObject.Find($"ally_0{TrackIndex + 1}");
|
||||
if (allyGo != null)
|
||||
var ally = GetAllyForTrackCached(TrackIndex);
|
||||
if (ally != null)
|
||||
{
|
||||
var ally = allyGo.GetComponent<AllyCombatant>();
|
||||
if (ally != null)
|
||||
{
|
||||
int added = ally.AddScoreForJudge(judgeResult);
|
||||
float efficiency = ally.scoreEfficiency;
|
||||
ScoreManager.Instance?.AddPmScoreForTrack(TrackIndex, added, efficiency);
|
||||
}
|
||||
int added = ally.AddScoreForJudge(judgeResult);
|
||||
float efficiency = ally.scoreEfficiency;
|
||||
ScoreManager.Instance?.AddPmScoreForTrack(TrackIndex, added, efficiency);
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
@@ -146,9 +152,9 @@ public class Note : BaseNote
|
||||
Debug.LogWarning($"[Note] Failed to add per-track score: {ex}");
|
||||
}
|
||||
|
||||
// Notify SkillBuilder about this note hit so OnNoteHit skills may trigger (tap notes)
|
||||
try { SkillBuilder.Instance?.NotifyNoteHit(TrackIndex, judgeResult, SkillDefinition.NoteTypeTrigger.Tap); } catch { }
|
||||
}
|
||||
|
||||
Judge();
|
||||
}
|
||||
|
||||
@@ -178,29 +184,26 @@ public class Note : BaseNote
|
||||
|
||||
public void JudgeMiss()
|
||||
{
|
||||
// idempotent: this can be called from multiple paths
|
||||
if (isJudged) return;
|
||||
|
||||
isJudged = true;
|
||||
ScoreManager.Instance.countMiss += 1;
|
||||
Debug.Log($"{keyToPress} Miss");
|
||||
// Ensure UI shows Miss and combo is updated when a note auto-misses
|
||||
if (GameConfig.verboseLogs) Debug.Log($"{keyToPress} Miss");
|
||||
|
||||
InputManager.Instance?.ShowJudgeResult(TrackIndex, "Miss");
|
||||
JudgeSoundManager.Instance?.PlayJudgeSound("Miss");
|
||||
teamUIController.Instance?.OnJudgeResult("Miss");
|
||||
Animation_GenerateJudgementSituationPrefab.Instance?.SpawnJudgePrefab(noteColor, "Miss");
|
||||
|
||||
// Add score for Miss as well (some systems may give 0)
|
||||
try
|
||||
{
|
||||
var allyGo = GameObject.Find($"ally_0{TrackIndex + 1}");
|
||||
if (allyGo != null)
|
||||
var ally = GetAllyForTrackCached(TrackIndex);
|
||||
if (ally != null)
|
||||
{
|
||||
var ally = allyGo.GetComponent<AllyCombatant>();
|
||||
if (ally != null)
|
||||
{
|
||||
int added = ally.AddScoreForJudge("Miss");
|
||||
float efficiency = ally.scoreEfficiency;
|
||||
ScoreManager.Instance?.AddPmScoreForTrack(TrackIndex, added, efficiency);
|
||||
}
|
||||
int added = ally.AddScoreForJudge("Miss");
|
||||
float efficiency = ally.scoreEfficiency;
|
||||
ScoreManager.Instance?.AddPmScoreForTrack(TrackIndex, added, efficiency);
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
@@ -208,9 +211,8 @@ public class Note : BaseNote
|
||||
Debug.LogWarning($"[Note] Failed to add per-track score for Miss: {ex}");
|
||||
}
|
||||
|
||||
// Notify SkillBuilder about Miss so OnNoteHit skills configured for Miss can trigger
|
||||
try { SkillBuilder.Instance?.NotifyNoteHit(TrackIndex, "Miss", SkillDefinition.NoteTypeTrigger.Tap); } catch { }
|
||||
// InputManager.Instance?.ShowJudgeResult(TrackIndex, "Miss"); // 已在HandlePress中调用 for manual presses
|
||||
|
||||
ReturnToPool();
|
||||
}
|
||||
|
||||
@@ -236,17 +238,14 @@ public class Note : BaseNote
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 由 Controller 通知 Note 是否进入判定区
|
||||
/// �� Controller ֪ͨ Note �Ƿ�����ж���
|
||||
/// </summary>
|
||||
public void SetJudgeZone(bool inZone)
|
||||
{
|
||||
// 离开判定区且未判定则判 Miss
|
||||
if (!inZone && !isJudged)
|
||||
// leaving judge zone without being judged -> Miss
|
||||
if (!inZone)
|
||||
{
|
||||
// Show Miss and update combo
|
||||
InputManager.Instance?.ShowJudgeResult(TrackIndex, "Miss");
|
||||
JudgeSoundManager.Instance?.PlayJudgeSound("Miss");
|
||||
teamUIController.Instance?.OnJudgeResult("Miss");
|
||||
// JudgeMiss already handles UI/sound and prevents double execution.
|
||||
JudgeMiss();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user