From 58d15866f9f2dae4d172588dbf33ef8cb12e81bd Mon Sep 17 00:00:00 2001 From: Jiangqvweihuan <15987148+jiangqvweihuan@user.noreply.gitee.com> Date: Sun, 20 Jul 2025 03:04:28 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20Assets/s?= =?UTF-8?q?cripts/gamePlay=5Fgameplay/KeyBindingManager.cs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gamePlay_gameplay/KeyBindingManager.cs | 74 ------------------- 1 file changed, 74 deletions(-) delete mode 100644 Assets/scripts/gamePlay_gameplay/KeyBindingManager.cs diff --git a/Assets/scripts/gamePlay_gameplay/KeyBindingManager.cs b/Assets/scripts/gamePlay_gameplay/KeyBindingManager.cs deleted file mode 100644 index 20687143..00000000 --- a/Assets/scripts/gamePlay_gameplay/KeyBindingManager.cs +++ /dev/null @@ -1,74 +0,0 @@ -using UnityEngine; -using System.Collections.Generic; - -public class KeyBindingManager : MonoBehaviour -{ - private static Dictionary keyBindings = new Dictionary(); - - private void Awake() - { - Debug.Log("KeyBindingManager Awake() 被调用,开始加载按键映射..."); - - if (keyBindings.Count == 0) - { - LoadKeyBindings(); - } - } - - /// 获取颜色对应的按键 - public static KeyCode GetKeyForColor(string color) - { - if (keyBindings.TryGetValue(color.ToLower(), out KeyCode key)) - { - return key; - } - Debug.LogError($"未找到颜色 {color} 对应的按键!请检查 KeyBindingManager 是否正确初始化。"); - return KeyCode.None; - } - - /// 修改按键绑定 - public static void ChangeKeyBinding(string color, KeyCode newKey) - { - if (keyBindings.ContainsKey(color.ToLower())) - { - keyBindings[color.ToLower()] = newKey; - } - else - { - keyBindings.Add(color.ToLower(), newKey); - } - - SaveKeyBindings(); - } - - /// 存储按键绑定到 `PlayerPrefs` - private static void SaveKeyBindings() - { - foreach (var kvp in keyBindings) - { - PlayerPrefs.SetInt($"KeyBinding_{kvp.Key}", (int)kvp.Value); - } - PlayerPrefs.Save(); - } - - /// 从 `PlayerPrefs` 加载按键绑定 - private static void LoadKeyBindings() - { - string[] colors = { "red", "green", "yellow", "purple", "blue" }; - KeyCode[] defaultKeys = { KeyCode.D, KeyCode.F, KeyCode.Space, KeyCode.J, KeyCode.K }; - - for (int i = 0; i < colors.Length; i++) - { - if (PlayerPrefs.HasKey($"KeyBinding_{colors[i]}")) - { - keyBindings[colors[i]] = (KeyCode)PlayerPrefs.GetInt($"KeyBinding_{colors[i]}"); - } - else - { - keyBindings[colors[i]] = defaultKeys[i]; - } - } - - Debug.Log("KeyBindings 初始化成功:" + string.Join(", ", keyBindings)); - } -}