Exemplo n.º 1
0
    private void UpdateGamePadKey(GameCommand cmd, GamepadKey key)
    {
        inputManager.SetGamepadCommand(cmd, key);
        // First, remove the actual saved gamepad key for command.
        GamepadKey toRemove = null;

        foreach (KeyValuePair <GamepadKey, GameCommand> entry in assignedPadCommands)
        {
            if (cmd == entry.Value)
            {
                toRemove = entry.Key;
            }
        }
        if (toRemove != null)
        {
            RemoveFormerPadKey(toRemove);
        }
        // Remove pad key if it was used elsewhere.
        toRemove = null;
        foreach (var cmdKey in assignedPadCommands.Keys)
        {
            if (cmdKey.ToString() == key.ToString())
            {
                toRemove = cmdKey;
                break;
            }
        }
        if (toRemove != null)
        {
            RemoveFormerPadKey(toRemove);
        }
        assignedPadCommands.Add(key, cmd);
    }
        //NOTE: 親指のスティック操作に対して何が出来るか考えないといけないんですよね…

        public void ButtonDown(GamepadKey key)
        {
            int fingerNumber = KeyToFingerNumber(key);

            _fingerPressButtonCounts[fingerNumber]++;
            fingerController.Hold(fingerNumber, GetBendingAngle(fingerNumber, true));
        }
        private static int KeyToFingerNumber(GamepadKey key)
        {
            switch (key)
            {
            case GamepadKey.A:
            case GamepadKey.B:
            case GamepadKey.X:
            case GamepadKey.Y:
                return(FingerConsts.RightThumb);

            case GamepadKey.UP:
            case GamepadKey.RIGHT:
            case GamepadKey.LEFT:
            case GamepadKey.DOWN:
                return(FingerConsts.LeftThumb);

            case GamepadKey.RShoulder:
                return(FingerConsts.RightIndex);

            case GamepadKey.RTrigger:
                return(FingerConsts.RightMiddle);

            case GamepadKey.LShoulder:
                return(FingerConsts.LeftIndex);

            case GamepadKey.LTrigger:
                return(FingerConsts.LeftMiddle);

            default:
                return(FingerConsts.RightThumb);
            }
        }
Exemplo n.º 4
0
        public void ButtonDown(GamepadKey key)
        {
            if (GamepadProvider.IsSideKey(key))
            {
                return;
            }

            _buttonDownCount++;
        }
        public void ButtonUp(GamepadKey key)
        {
            int fingerNumber = KeyToFingerNumber(key);

            _fingerPressButtonCounts[fingerNumber]--;
            fingerController.Hold(
                fingerNumber,
                GetBendingAngle(fingerNumber, _fingerPressButtonCounts[fingerNumber] > 0)
                );
        }
        public void ButtonDown(GamepadKey key)
        {
            _inputJitter.AddButtonInput();
            if (GamepadProvider.IsSideKey(key))
            {
                return;
            }

            _buttonDownCount++;
        }
Exemplo n.º 7
0
    private void RemoveFormerPadKey(GamepadKey gpkey)
    {
        var command = assignedPadCommands[gpkey];
        var text    = gamepadKeyToName[command];

        text.text = menuSlash;
        // TODO: Shouldn't be necessary, seek when does this state happen.
        if (assignedPadCommands.ContainsKey(gpkey))
        {
            assignedPadCommands.Remove(gpkey);
        }
    }
Exemplo n.º 8
0
        public void ButtonUp(GamepadKey key)
        {
            if (GamepadProvider.IsSideKey(key))
            {
                return;
            }
            _buttonDownCount--;

            //通常起きないハズだが一応
            if (_buttonDownCount < 0)
            {
                _buttonDownCount = 0;
            }
        }
Exemplo n.º 9
0
    // Checks if a gamepad axis is being pressed for the specified action.
    private bool IsGamePadPress(GamepadKey action)
    {
        var pressed = false;

        if (action.key != KeyCode.None)
        {
            pressed |= Input.GetKey(action.key);
        }
        else
        {
            pressed |= action.positive
                ? Input.GetAxisRaw(action.axis) > gamePadTreshold
                : Input.GetAxisRaw(action.axis) < -gamePadTreshold;
        }

        return(pressed);
    }
Exemplo n.º 10
0
        /// <summary>
        /// 更新按键状态
        /// </summary>
        /// <param name="key">按键</param>
        /// <param name="state">状态</param>
        /// <param name="tick">时间戳</param>
        public void updateKeyState(GamepadKey key, PinValue state, UInt32 tick)
        {
            var value = state == PinValue.Low ? KEY_STATE.PRESSED : KEY_STATE.NONE;

            if (key.state == value)
            {
                if (value == KEY_STATE.NONE)
                {
                    return;
                }
                if (this.keyRepeatPressEvent == 0 || tick - key.lastupdate < this.keyRepeatPressEvent)
                {
                    return;
                }

                key.count++;
                key.duration   = tick - key.timestamp;
                key.lastupdate = tick;
            }
            else
            {
                if (value == KEY_STATE.PRESSED)
                {
                    // 按下瞬间
                    if (tick - key.lastupdate < 50000)
                    {
                        return;
                    }
                }
                else
                {
                    // 抬起瞬间 从按下到抬起 时间太短的话 过滤掉
                    if (tick - key.timestamp < 100000)
                    {
                        return;
                    }
                }
                key.count      = 1;
                key.state      = value;
                key.timestamp  = tick;
                key.duration   = null;
                key.lastupdate = tick;
            }
            // 触发事件
            this.onKeyChange?.Invoke(key);
        }
Exemplo n.º 11
0
    private bool IsGamePadPressOnce(GamepadKey action)
    {
        var pressed = false;

        if (action.key != KeyCode.None)
        {
            pressed |= Input.GetKeyDown(action.key);
        }
        else
        {
            pressed |= Time.realtimeSinceStartup - lastMenuKeyTick > gamepadTickDelay &&
                       (action.positive
                ? Input.GetAxisRaw(action.axis) > gamePadTreshold
                : Input.GetAxisRaw(action.axis) < -gamePadTreshold);
        }

        return(pressed);
    }
Exemplo n.º 12
0
 public void OnInput(GamepadKey key)
 {
     this.Commands[key].Execute();
 }
Exemplo n.º 13
0
    private void Update()
    {
        // Manage column in which the cursor is present.
        if (!assigningKey && inputManager.IsMenuPressRight() && !switchingScene && !assigningKey)
        {
            audioManager.PlayEffect(Sfx.MENU_BEEP);
            horizontalIndex++;
            if (horizontalIndex == 2)
            {
                horizontalIndex = 0;
            }
            UpdateNunIconPosition();
        }

        if (!assigningKey && inputManager.IsMenuPressLeft() && !switchingScene && !assigningKey)
        {
            audioManager.PlayEffect(Sfx.MENU_BEEP);
            horizontalIndex--;
            if (horizontalIndex == -1)
            {
                horizontalIndex = 1;
            }
            UpdateNunIconPosition();
        }

        // Going up and down in the control you want to update.
        if (!assigningKey && inputManager.IsMenuPressUp() && !switchingScene && !assigningKey)
        {
            audioManager.PlayEffect(Sfx.MENU_BEEP);
            optionIndex--;
            if (optionIndex == -1)
            {
                optionIndex = 7;
            }
            UpdateNunIconPosition();
        }

        if (!assigningKey && inputManager.IsMenuPressDown() && !switchingScene && !assigningKey)
        {
            audioManager.PlayEffect(Sfx.MENU_BEEP);
            optionIndex++;
            if (optionIndex == 8)
            {
                optionIndex = 0;
            }
            UpdateNunIconPosition();
        }

        // Going back to main menu.
        if (optionIndex == 7 && inputManager.IsMenuStart() && !switchingScene)
        {
            audioManager.PlayEffect(Sfx.MENU_ACCEPT);
            switchingScene = true;
            GameConfig gc = SaveManager.LoadGameConfig();
            gc.keyboardConfig = InputManager.keyboardConfig;
            gc.padConfig      = InputManager.gamepadConfig;
            SaveManager.SaveGameConfig(gc);
            gs.LoadScene(Scenes.OPTIONS, 0.5f);
        }

        // Assigning a key.
        if (assigningKey)
        {
            foreach (KeyCode key in Enum.GetValues(typeof(KeyCode)))
            {
                // Keyboard configuration.
                if (Input.GetKeyDown(key))
                {
                    // Escape is a special key to exit the assignment menu.
                    if (key == KeyCode.Escape)
                    {
                        DeactivateAssignment();
                        return;
                    }
                    // If they key is assignable to this action, update the configuration.
                    if (!IgnoreKey(key))
                    {
                        UpdateGameKey(commands[optionIndex], key);
                        UpdateControlText(key.ToString());
                        DeactivateAssignment();
                        return;
                    }
                }
            }
        }

        // Assigning a game pad button or axis.
        if (assigningPad)
        {
            foreach (KeyCode key in Enum.GetValues(typeof(KeyCode)))
            {
                // Keyboard configuration.
                if (Input.GetKeyDown(key))
                {
                    // Escape is a special key to exit the assignment menu.
                    if (key == KeyCode.Escape)
                    {
                        DeactivateAssignment();
                        return;
                    }
                    if (!IgnoreKey(key))
                    {
                        UpdateGamePadKey(commands[optionIndex], new GamepadKey(key));
                        UpdateControlText(key.ToString());
                        DeactivateAssignment();
                        return;
                    }
                }
            }

            // Axis configuration.
            // One menu tick to check if an axis is active before the player presses it so we know to nullify it.
            var    update   = false;
            string axis     = "";
            bool   positive = true;
            var    treshold = inputManager.GetGamepadTreshold();

            if (Input.GetAxis(GamepadAxis.HORIZONTAL) != 0)
            {
                axis     = GamepadAxis.HORIZONTAL;
                positive = Input.GetAxis(GamepadAxis.HORIZONTAL) > treshold;
                update   = true;
            }
            if (Input.GetAxis(GamepadAxis.VERTICAL) != 0)
            {
                axis     = GamepadAxis.VERTICAL;
                positive = Input.GetAxis(GamepadAxis.VERTICAL) > treshold;
                update   = true;
            }
            if (Input.GetAxis(GamepadAxis.HORIZONTAL2) != 0)
            {
                axis     = GamepadAxis.HORIZONTAL2;
                positive = Input.GetAxis(GamepadAxis.HORIZONTAL2) > treshold;
                update   = true;
            }
            if (Input.GetAxis(GamepadAxis.VERTICAL2) != 0)
            {
                axis     = GamepadAxis.VERTICAL2;
                positive = Input.GetAxis(GamepadAxis.VERTICAL2) > treshold;
                update   = true;
            }
            if (Input.GetAxis(GamepadAxis.HORIZONTAL3) != 0)
            {
                axis     = GamepadAxis.HORIZONTAL3;
                positive = Input.GetAxis(GamepadAxis.HORIZONTAL3) > treshold;
                update   = true;
            }
            if (Input.GetAxis(GamepadAxis.VERTICAL3) != 0)
            {
                axis     = GamepadAxis.VERTICAL3;
                positive = Input.GetAxis(GamepadAxis.VERTICAL3) > treshold;
                update   = true;
            }

            // If any axis was active during detection, it is assigned.
            if (update)
            {
                var gpkey = new GamepadKey(axis, positive);
                UpdateGamePadKey(commands[optionIndex], gpkey);
                UpdateControlText(gpkey.ToString());
                DeactivateAssignment();
                return;
            }
        }

        // Activating the "assign key" option.
        if (!assigningKey && inputManager.IsMenuStart() && !switchingScene)
        {
            ActivateAssignment();
        }

        // Fade out.
        if (switchingScene)
        {
            var color = GetComponent <SpriteRenderer>().color;
            color.a += 0.03f;
            GetComponent <SpriteRenderer>().color = color;
        }
    }
Exemplo n.º 14
0
 public void SetGamepadCommand(GameCommand command, string axis, bool positive)
 {
     gamepadConfig[command] = new GamepadKey(axis, positive);
     gamePadConfigured      = true;
 }
Exemplo n.º 15
0
 // Set a gamepad button (can be a button or an axis press).
 public void SetGamepadCommand(GameCommand command, GamepadKey key)
 {
     gamepadConfig[command] = key;
     gamePadConfigured      = true;
 }
Exemplo n.º 16
0
 public ObservableButton(GamepadKey key, int flag, Subject <GamepadKeyData> subject)
 {
     _key     = key;
     _flag    = flag;
     _subject = subject;
 }
Exemplo n.º 17
0
 private async void Padreader_onKeyChange(GamepadKey key)
 {
     System.Console.WriteLine(JsonConvert.SerializeObject(key));
     await this.SendAll(JsonConvert.SerializeObject(key));
 }
Exemplo n.º 18
0
 public GamepadKeyData(GamepadKey key, bool isPressed) : this()
 {
     Key       = key;
     IsPressed = isPressed;
 }