- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public enum InputAction
- {
- Interact,
- Attack,
- Defend,
- Run,
- PauseGame,
- Inventory,
- SelectItem,
- SplitItemStack,
- use1,
- use2,
- use3,
- use4,
- use5,
- }
- public static class InputManager
- {
-
- public static Dictionary<InputAction, KeyCode> keyMaps = new Dictionary<InputAction, KeyCode>()
- {
-
-
- {InputAction.Interact, KeyCode.E },
-
- {InputAction.Attack, KeyCode.Mouse0 },
- {InputAction.Defend, KeyCode.Space },
-
- { InputAction.Run, KeyCode.LeftShift},
-
- {InputAction.PauseGame, KeyCode.Escape },
- {InputAction.Inventory, KeyCode.I },
-
- {InputAction.SelectItem, KeyCode.Mouse0 },
- {InputAction.SplitItemStack, KeyCode.Mouse1 },
-
- {InputAction.use1, KeyCode.Alpha1 },
- {InputAction.use2, KeyCode.Alpha2 },
- {InputAction.use3, KeyCode.Alpha3 },
- {InputAction.use4, KeyCode.Alpha4 },
- {InputAction.use5, KeyCode.Alpha5 }
- };
-
- public static void ChangeKey(InputAction action, KeyCode code)
- {
-
- if (keyMaps.ContainsKey(action))
- {
-
- keyMaps[action] = code;
- }
- else
- {
- Debug.LogError($"The action '{action}' doesn't exist in the key map.");
- }
- }
-
- public static KeyCode GetKey(InputAction action)
- {
-
- if (keyMaps.ContainsKey(action))
- {
-
- return keyMaps[action];
- }
- else
- {
- Debug.LogError($"The action '{action}' doesn't exist in the key map.");
- return KeyCode.None;
- }
- }
-
- public static void SaveKeyBinds()
- {
- foreach (KeyValuePair<InputAction, KeyCode> pair in keyMaps)
- {
-
- PlayerPrefs.SetString(pair.Key.ToString(), pair.Value.ToString());
- }
-
- PlayerPrefs.Save();
- }
-
- public static void LoadKeyBinds()
- {
- foreach(InputAction action in Enum.GetValues(typeof(InputAction)))
- {
-
- if (PlayerPrefs.HasKey(action.ToString()))
- {
-
- string savedKey = PlayerPrefs.GetString(action.ToString());
-
- if (Enum.TryParse(savedKey, out KeyCode keyCode))
- {
-
- keyMaps[action] = keyCode;
- }
- }
- }
- }
- }