This commit is contained in:
FloatGaming
2026-07-26 03:44:27 +08:00
parent 86351dbd2a
commit add675e45d
223 changed files with 1960 additions and 10735 deletions
@@ -3,10 +3,12 @@ using System.Collections.Generic;
public class KeyBindingManager : MonoBehaviour
{
private static Dictionary<string, KeyCode> keyBindings = new Dictionary<string, KeyCode>();
private static readonly string[] colors = { "red", "green", "yellow", "purple", "blue" };
private static readonly KeyCode[] defaultKeys = { KeyCode.D, KeyCode.F, KeyCode.Space, KeyCode.J, KeyCode.K };
private static bool initialized = false;
private static Dictionary<string, KeyCode> keyBindings = new Dictionary<string, KeyCode>();
private static readonly string[] colors = { "red", "green", "yellow", "purple", "blue" };
private static readonly KeyCode[] defaultKeys = { KeyCode.D, KeyCode.F, KeyCode.Space, KeyCode.J, KeyCode.K };
private const string SecondaryTrack3PrefsKey = "KeyBinding_yellow_secondary";
private static KeyCode secondaryTrack3Key = KeyCode.V;
private static bool initialized = false;
private void Awake()
{
@@ -14,7 +16,7 @@ public class KeyBindingManager : MonoBehaviour
{
LoadKeyBindings();
}
Debug.Log("KeyBindingManager Awake() 被调用,开始加载按键映射...");
Debug.Log("KeyBindingManager Awake() 被调用,开始加载按键映射...");
}
public static KeyCode GetKeyForColor(string color)
@@ -38,28 +40,58 @@ public class KeyBindingManager : MonoBehaviour
return defaultKeys[i];
}
}
return KeyCode.None;
}
public static void ChangeKeyBinding(string color, KeyCode newKey)
{
if (string.IsNullOrEmpty(color)) return;
var keyLower = color.ToLower();
keyBindings[keyLower] = newKey;
SaveKeyBindings();
}
private static void SaveKeyBindings()
{
for (int i = 0; i < colors.Length; i++)
{
var col = colors[i];
return KeyCode.None;
}
public static KeyCode GetSecondaryKeyForTrack3()
{
if (!initialized)
{
LoadKeyBindings();
}
return secondaryTrack3Key;
}
public static bool IsKeyForColor(string color, KeyCode key)
{
if (!initialized)
{
LoadKeyBindings();
}
if (key == KeyCode.None || string.IsNullOrEmpty(color)) return false;
string keyLower = color.ToLower();
if (GetKeyForColor(keyLower) == key) return true;
return keyLower == "yellow" && secondaryTrack3Key == key;
}
public static void ChangeKeyBinding(string color, KeyCode newKey)
{
if (string.IsNullOrEmpty(color)) return;
var keyLower = color.ToLower();
keyBindings[keyLower] = newKey;
SaveKeyBindings();
}
public static void ChangeSecondaryTrack3KeyBinding(KeyCode newKey)
{
secondaryTrack3Key = newKey;
SaveKeyBindings();
}
private static void SaveKeyBindings()
{
for (int i = 0; i < colors.Length; i++)
{
var col = colors[i];
KeyCode k = defaultKeys[i];
if (keyBindings.TryGetValue(col, out KeyCode stored)) k = stored;
PlayerPrefs.SetInt($"KeyBinding_{col}", (int)k);
}
PlayerPrefs.Save();
}
if (keyBindings.TryGetValue(col, out KeyCode stored)) k = stored;
PlayerPrefs.SetInt($"KeyBinding_{col}", (int)k);
}
PlayerPrefs.SetInt(SecondaryTrack3PrefsKey, (int)secondaryTrack3Key);
PlayerPrefs.Save();
}
private static void LoadKeyBindings()
{
@@ -73,12 +105,22 @@ public class KeyBindingManager : MonoBehaviour
}
else
{
keyBindings[col] = defaultKeys[i];
}
}
initialized = true;
Debug.Log("KeyBindings 初始化成功:" + string.Join(", ", keyBindings));
}
keyBindings[col] = defaultKeys[i];
}
}
if (PlayerPrefs.HasKey(SecondaryTrack3PrefsKey))
{
secondaryTrack3Key = (KeyCode)PlayerPrefs.GetInt(SecondaryTrack3PrefsKey);
}
else
{
secondaryTrack3Key = KeyCode.V;
PlayerPrefs.SetInt(SecondaryTrack3PrefsKey, (int)secondaryTrack3Key);
PlayerPrefs.Save();
}
initialized = true;
Debug.Log("KeyBindings 初始化成功:" + string.Join(", ", keyBindings));
}
// Return a human-friendly display string for a KeyCode (symbols shown as their character)
public static string GetDisplayName(KeyCode key)