///-------------------------------------------------------------------- /// InputManager methods ///-------------------------------------------------------------------- public void Init(bool lite = false) { // TODO: Allow KeyMap to accept an existing KeyMap config on init _km = new KeyMap(); _keyDownArr = new bool[KeyMap.KeysInUse.Length]; // Force lite mode when there's no player instance, or if we're not ingame (in a menu) if (HubrisPlayer.Instance == null || !HubrisCore.Instance.Ingame) { SetLite(true); return; } SetLite(lite); }
private void ProcessKeys() { // No keys pressed this tick if (!Input.anyKey) { // Check for any keys previously pressed for (int i = 0; i < KeyMap.KeysInUse.Length; i++) { if (_keyDownArr[i]) { KeyCode kc = KeyMap.KeysInUse[i]; Command cmd = KeyMap.CheckKeyCmd(kc); GetKeyState(cmd, false, _keyDownArr[i], out InputState state); if (state == InputState.INVALID) { continue; } if (_lite) { // Only accept the following specific commands in Lite mode if (cmd == Command.Console || cmd == Command.Escape || cmd == Command.Submit || cmd == Command.PrevCmd || cmd == Command.NextCmd) { LocalConsole.Instance.AddToQueue(cmd, state); } } else { LocalConsole.Instance.AddToQueue(cmd, state); } } _keyDownArr[i] = false; } return; } // If running in Lite mode if (_lite) { for (int i = 0; i < KeyMap.KeysInUse.Length; i++) { KeyCode kc = KeyMap.KeysInUse[i]; bool keyDown = Input.GetKey(kc); // Key is not pressed and was not pressed; continue if (!keyDown && !_keyDownArr[i]) { continue; } Command cmd = KeyMap.CheckKeyCmd(kc); GetKeyState(cmd, keyDown, _keyDownArr[i], out InputState state); _keyDownArr[i] = keyDown; if (state == InputState.INVALID) { continue; } // Only accept the following specific commands in Lite mode if (cmd == Command.Console || cmd == Command.Escape || cmd == Command.Submit || cmd == Command.PrevCmd || cmd == Command.NextCmd) { LocalConsole.Instance.AddToQueue(cmd, state); } } return; } // Temporary mouse scroll behavior, to be checked in non-Lite mode float mouseScroll = Input.mouseScrollDelta.y; if (mouseScroll != 0.0f) { if (mouseScroll > 0.0f) { LocalConsole.Instance.AddToQueue(Command.NextSlot, InputState.MWHEEL_UP); } else { LocalConsole.Instance.AddToQueue(Command.PrevSlot, InputState.MWHEEL_DOWN); } } // Check which keys were pressed and map to commands for (int i = 0; i < KeyMap.KeysInUse.Length; i++) { KeyCode kc = KeyMap.KeysInUse[i]; bool keyDown = Input.GetKey(kc); // Key is not pressed and was not pressed; continue if (!keyDown && !_keyDownArr[i]) { continue; } Command cmd = KeyMap.CheckKeyCmd(kc); GetKeyState(cmd, keyDown, _keyDownArr[i], out InputState state); _keyDownArr[i] = keyDown; if (state == InputState.INVALID) { continue; } if (CheckValidForType(cmd)) { UpdateMoveKey(cmd); LocalConsole.Instance.AddToQueue(cmd, state); } else { if (HubrisCore.Instance.Debug) { LocalConsole.Instance.LogWarning("InputManager Tick(): CheckValidForType(" + cmd.CmdName + ") returned false", true); } } } }