ui基本完毕,修了一大把的bug

This commit is contained in:
FloatGaming
2026-07-13 02:28:39 +08:00
parent 1e20d73e90
commit fd22501f71
958 changed files with 378289 additions and 41038 deletions
@@ -3,6 +3,10 @@ using TMPro;
using System;
using UnityEngine.UI;
// Runs before default-order scripts so the per-track held-state table (trackHeld) is
// updated from keyboard/touch this frame *before* hold notes read it. This preserves the
// frame-accurate timing the old direct Input.GetKey polling had in HoldNote.
[DefaultExecutionOrder(-100)]
public class InputManager : MonoBehaviour
{
public static InputManager Instance { get; private set; }
@@ -42,6 +46,21 @@ public class InputManager : MonoBehaviour
private KeyCode[] cachedKeys = new KeyCode[5];
private bool pauseBlockedLastFrame = false;
// Per-track held state. Written by both keyboard (Update) and touch (PressTrack/
// ReleaseTrack) so hold-note logic can query one platform-agnostic source instead
// of polling Input.GetKey directly (which cannot be driven by touch on Android).
private bool[] trackHeld = new bool[5];
/// <summary>
/// True while the given track (0-4) is currently held, regardless of whether the
/// source is keyboard or touch. Replaces direct Input.GetKey polling in hold notes.
/// </summary>
public bool IsTrackHeld(int trackIndex)
{
if (trackIndex < 0 || trackIndex >= trackHeld.Length) return false;
return trackHeld[trackIndex];
}
private void Awake()
{
if (Instance == null)
@@ -111,45 +130,61 @@ public class InputManager : MonoBehaviour
KeyCode key = cachedKeys[i];
if (key == KeyCode.None) continue;
int index = i; // TrackColors array index matches track index logic here
if (Input.GetKeyDown(key))
{
OnKeyPressed?.Invoke(key);
// Documentation text normalized.
// Update lane sprite alpha
if (laneSprites != null && index >= 0 && index < laneSprites.Length)
{
SetSpriteAlpha(laneSprites[index], pressedAlpha);
}
// Documentation text normalized.
if (trackKeyTexts != null && index >= 0 && index < trackKeyTexts.Length)
{
var txt = trackKeyTexts[index];
if (txt != null)
txt.color = keyActiveColor;
}
}
PressTrack(i);
if (Input.GetKeyUp(key))
{
OnKeyReleased?.Invoke(key);
ReleaseTrack(i);
}
}
// Update lane sprite alpha
if (laneSprites != null && index >= 0 && index < laneSprites.Length)
{
SetSpriteAlpha(laneSprites[index], 0f);
}
/// <summary>
/// Begin holding a track (0-4). Called by keyboard Update on key-down and by touch
/// regions on pointer-down. Sets the held-state table, raises OnKeyPressed with the
/// track's bound key so event-driven tap notes keep working, and updates lane visuals.
/// </summary>
public void PressTrack(int index)
{
if (index < 0 || index >= TrackColors.Length) return;
if (trackHeld[index]) return; // already held; avoid duplicate press events
// Documentation text normalized.
if (trackKeyTexts != null && index >= 0 && index < trackKeyTexts.Length)
{
var txt = trackKeyTexts[index];
if (txt != null)
txt.color = keyInactiveColor;
}
}
trackHeld[index] = true;
KeyCode key = cachedKeys[index];
if (key != KeyCode.None)
OnKeyPressed?.Invoke(key);
if (laneSprites != null && index < laneSprites.Length)
SetSpriteAlpha(laneSprites[index], pressedAlpha);
if (trackKeyTexts != null && index < trackKeyTexts.Length)
{
var txt = trackKeyTexts[index];
if (txt != null) txt.color = keyActiveColor;
}
}
/// <summary>
/// Release a track (0-4). Called by keyboard Update on key-up and by touch regions
/// on pointer-up. Clears the held-state table, raises OnKeyReleased, and resets visuals.
/// </summary>
public void ReleaseTrack(int index)
{
if (index < 0 || index >= TrackColors.Length) return;
if (!trackHeld[index]) return; // not held; nothing to release
trackHeld[index] = false;
KeyCode key = cachedKeys[index];
if (key != KeyCode.None)
OnKeyReleased?.Invoke(key);
if (laneSprites != null && index < laneSprites.Length)
SetSpriteAlpha(laneSprites[index], 0f);
if (trackKeyTexts != null && index < trackKeyTexts.Length)
{
var txt = trackKeyTexts[index];
if (txt != null) txt.color = keyInactiveColor;
}
}
@@ -169,6 +204,7 @@ public class InputManager : MonoBehaviour
for (int i = 0; i < TrackColors.Length; i++)
{
string color = TrackColors[i];
trackHeld[i] = false; // clear held state so hold notes don't see a stale press after pause/clear
KeyCode key = KeyBindingManager.GetKeyForColor(color);
if (key == KeyCode.None) continue;
try { OnKeyReleased?.Invoke(key); } catch { }