超大量的更新 修复很多问题,gameplay特效初步
This commit is contained in:
@@ -11,30 +11,36 @@ public class InputManager : MonoBehaviour
|
||||
|
||||
private static readonly string[] TrackColors = { "red", "green", "yellow", "purple", "blue" };
|
||||
|
||||
[Header("����ж���ʾTMP��������Inspector�����ӣ�")]
|
||||
[Header("Inspector")]
|
||||
public TextMeshProUGUI[] trackJudgeTexts = new TextMeshProUGUI[5];
|
||||
|
||||
[Header("����ָʾ�ı����������ж��ı�������ֱ��Ӧ������D,F,Space,J,K��")]
|
||||
[Header("Inspector")]
|
||||
public Text[] trackKeyTexts = new Text[5];
|
||||
|
||||
[Header("�Ƿ���ʾ�ж�����")]
|
||||
[Header("Lane Background Settings")]
|
||||
[Tooltip("The sprites for the 5 lanes (Red, Green, Yellow, Purple, Blue)")]
|
||||
public SpriteRenderer[] laneSprites = new SpriteRenderer[5];
|
||||
[Tooltip("Alpha value when pressed (0-255)")]
|
||||
public float pressedAlpha = 30f;
|
||||
|
||||
[Header("Inspector")]
|
||||
public bool showJudgeText = true;
|
||||
|
||||
// ��������/�Ǽ�����ɫ
|
||||
[Header("����������ɫ����")]
|
||||
[Tooltip("����������ʱ����ɫ")]
|
||||
// Documentation text normalized.
|
||||
[Header("Inspector")]
|
||||
[Tooltip("Documentation text normalized.")]
|
||||
public Color keyActiveColor = Color.yellow;
|
||||
[Tooltip("����δ����ʱ����ɫ��Ĭ�Ϻ�ɫ��")]
|
||||
[Tooltip("Documentation text normalized.")]
|
||||
public Color keyInactiveColor = Color.black;
|
||||
|
||||
// �ж������Ӧ��ɫ
|
||||
[Header("�ж������Ӧ��ɫ")]
|
||||
// Documentation text normalized.
|
||||
public Color perfectColor = Color.yellow;
|
||||
public Color greatColor = Color.green;
|
||||
public Color goodColor = Color.cyan;
|
||||
public Color missColor = Color.red;
|
||||
|
||||
private KeyCode[] cachedKeys = new KeyCode[5];
|
||||
private bool pauseBlockedLastFrame = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -43,10 +49,10 @@ public class InputManager : MonoBehaviour
|
||||
else
|
||||
Destroy(gameObject);
|
||||
|
||||
// 初始化按键缓存
|
||||
// Documentation text normalized.
|
||||
RefreshKeyCache();
|
||||
|
||||
// ��ʼ�������ı�Ϊ�Ǽ�����ɫ
|
||||
// Documentation text normalized.
|
||||
if (trackKeyTexts != null)
|
||||
{
|
||||
foreach (var t in trackKeyTexts)
|
||||
@@ -66,12 +72,40 @@ public class InputManager : MonoBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Ensure UI shows current bindings from KeyBindingManager/PlayerPrefs
|
||||
// Ensure runtime input and UI labels both use current bindings.
|
||||
RefreshKeyCache();
|
||||
RefreshKeyLabels();
|
||||
|
||||
// Initialize lane sprites to 0 alpha
|
||||
if (laneSprites != null)
|
||||
{
|
||||
foreach (var sprite in laneSprites)
|
||||
{
|
||||
if (sprite != null) SetSpriteAlpha(sprite, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetSpriteAlpha(SpriteRenderer sprite, float alpha255)
|
||||
{
|
||||
if (sprite == null) return;
|
||||
Color c = sprite.color;
|
||||
c.a = Mathf.Clamp01(alpha255 / 255f);
|
||||
sprite.color = c;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
bool pauseBlocked = IsBlockedByPause();
|
||||
if (pauseBlocked)
|
||||
{
|
||||
if (!pauseBlockedLastFrame)
|
||||
ForceReleaseAllKeys();
|
||||
pauseBlockedLastFrame = true;
|
||||
return;
|
||||
}
|
||||
pauseBlockedLastFrame = false;
|
||||
|
||||
for (int i = 0; i < TrackColors.Length; i++)
|
||||
{
|
||||
KeyCode key = cachedKeys[i];
|
||||
@@ -82,10 +116,15 @@ public class InputManager : MonoBehaviour
|
||||
if (Input.GetKeyDown(key))
|
||||
{
|
||||
OnKeyPressed?.Invoke(key);
|
||||
// ���� JudgeManager ͳһ�ж����������
|
||||
JudgeManager.Instance.JudgeEarliestNote(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];
|
||||
@@ -97,7 +136,13 @@ public class InputManager : MonoBehaviour
|
||||
{
|
||||
OnKeyReleased?.Invoke(key);
|
||||
|
||||
// �ɿ�ʱ�ָ�Ϊ�Ǽ�����ɫ
|
||||
// Update lane sprite alpha
|
||||
if (laneSprites != null && index >= 0 && index < laneSprites.Length)
|
||||
{
|
||||
SetSpriteAlpha(laneSprites[index], 0f);
|
||||
}
|
||||
|
||||
// Documentation text normalized.
|
||||
if (trackKeyTexts != null && index >= 0 && index < trackKeyTexts.Length)
|
||||
{
|
||||
var txt = trackKeyTexts[index];
|
||||
@@ -108,6 +153,12 @@ public class InputManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsBlockedByPause()
|
||||
{
|
||||
var pm = PauseManager.Instance;
|
||||
return pm != null && pm.IsPaused;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Force a release event for all bound keys and reset UI indicators.
|
||||
/// Useful for external "clear input" operations where the system should treat
|
||||
@@ -123,6 +174,10 @@ public class InputManager : MonoBehaviour
|
||||
try { OnKeyReleased?.Invoke(key); } catch { }
|
||||
|
||||
int index = GetIndexForColor(color);
|
||||
if (laneSprites != null && index >= 0 && index < laneSprites.Length)
|
||||
{
|
||||
SetSpriteAlpha(laneSprites[index], 0f);
|
||||
}
|
||||
if (trackKeyTexts != null && index >= 0 && index < trackKeyTexts.Length)
|
||||
{
|
||||
var txt = trackKeyTexts[index];
|
||||
@@ -134,19 +189,24 @@ public class InputManager : MonoBehaviour
|
||||
// Refresh displayed labels for key bindings (called after rebind)
|
||||
public void RefreshKeyLabels()
|
||||
{
|
||||
if (trackKeyTexts == null) return;
|
||||
for (int i = 0; i < TrackColors.Length && i < trackKeyTexts.Length; i++)
|
||||
if (trackKeyTexts != null)
|
||||
{
|
||||
var txt = trackKeyTexts[i];
|
||||
if (txt == null) continue;
|
||||
KeyCode k = KeyBindingManager.GetKeyForColor(TrackColors[i]);
|
||||
txt.text = KeyBindingManager.GetDisplayName(k);
|
||||
for (int i = 0; i < TrackColors.Length && i < trackKeyTexts.Length; i++)
|
||||
{
|
||||
var txt = trackKeyTexts[i];
|
||||
if (txt == null) continue;
|
||||
KeyCode k = KeyBindingManager.GetKeyForColor(TrackColors[i]);
|
||||
txt.text = KeyBindingManager.GetDisplayName(k);
|
||||
}
|
||||
}
|
||||
|
||||
// Keep runtime input cache in sync with latest bindings even when label UI is missing.
|
||||
RefreshKeyCache();
|
||||
}
|
||||
|
||||
private int GetIndexForColor(string color)
|
||||
{
|
||||
// ������ trackJudgeTexts ��ͬ������ӳ��
|
||||
// Documentation text normalized.
|
||||
switch (color)
|
||||
{
|
||||
case "red": return 0;
|
||||
@@ -159,8 +219,7 @@ public class InputManager : MonoBehaviour
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ����ָ��������ж��ı�����ɫ
|
||||
/// </summary>
|
||||
/// Documentation text normalized.
|
||||
public void ShowJudgeResult(int trackIndex, string result)
|
||||
{
|
||||
if (!showJudgeText) return;
|
||||
|
||||
Reference in New Issue
Block a user