Пример #1
0
    private void Start()
    {
        //TODO : make that WAYYY more generic and robust
        Canvas canvas = GetComponent <Canvas>();

        canvas.worldCamera = Camera.main;

        if (KeyboardMapping == null)
        {
            Debug.LogError("You need to setup at least a keyboard mapping before opening the InputMapper");
            return;
        }

        _mapperEntries = new InputMapperEntry[KeyboardMapping.buttons.Length];

        for (int i = 0; i < KeyboardMapping.buttons.Length; ++i)
        {
            _mapperEntries[i] = Instantiate(entryPrefab, listParent);
            _mapperEntries[i].padEntry.SetActive(PadMapping != null);

            _mapperEntries[i].nameText.text    = KeyboardMapping.buttons[i].name;
            _mapperEntries[i].keyboardKey.text = KeyboardMapping.GetKeyCode(KeyboardMapping.buttons[i].name).ToString();
            if (PadMapping != null)
            {
                _mapperEntries[i].padKey.text = PadMapping.GetKeyCode(PadMapping.buttons[i].name).ToString().Replace("Joystick", "");
            }
        }

        _currentActive = 0;
    }
Пример #2
0
    public void HandleInput()
    {
        Vector2 velocity = _po.velocity;
        Vector2 move     = Vector2.zero;

        //_pushing = false;

        if (_controlled)
        {
            KeyCode jumpKeyboardKeycode = inputKeyboardMapping.GetKeyCode(JUMP_BUTTON_HASH);
            KeyCode jumpPadKeycode      = inputPadMapping.GetKeyCode(JUMP_BUTTON_HASH);

            KeyCode attackKeyboardKeycode = inputKeyboardMapping.GetKeyCode(ATTACK_BUTTON_HASH);
            KeyCode attackPadKeycode      = inputPadMapping.GetKeyCode(ATTACK_BUTTON_HASH);

            move.x = Input.GetAxis("Horizontal");
            move.y = Input.GetAxis("Vertical");

            if (_po.grounded)
            {
                if (Input.GetKeyDown(jumpKeyboardKeycode) || Input.GetKeyDown(jumpPadKeycode))
                {
                    bool jump = true;

                    if (jump)
                    {
                        velocity.y   = jumpTakeoffSpeed;
                        _po.velocity = velocity;
                    }
                }
                else if (Input.GetKeyDown(attackKeyboardKeycode) || Input.GetKeyDown(attackPadKeycode))
                {
                    _animator.SetTrigger("attacking");
                }
            }
            else if ((Input.GetKeyUp(jumpKeyboardKeycode) || Input.GetKeyUp(jumpPadKeycode)))
            {
                if (_po.velocity.y > 0)
                {
                    _po.velocity = _po.velocity * 0.5f;
                }
            }



            move.y = 0;

            bool needChange = _renderer.flipX ? (move.x > 0.01f) : (move.x < -0.01f);
            if (needChange)
            {
                _renderer.flipX = !_renderer.flipX;
            }

            _po.moveInput = move;
        }

        _animator.SetBool("grounded", _po.grounded);

        float velocityParam = Mathf.Abs(move.x);

        _animator.SetFloat("velocityX", velocityParam);
        _animator.SetFloat("velocityY", move.y);
        _animator.SetFloat("verticalSpeed", _po.velocity.y);

        //check for mapper input
        if (Input.GetKeyDown(KeyCode.Escape) && Time.timeScale > 0)
        {
            Time.timeScale = 0.0f;
            InputMapper.SetMappingData(inputKeyboardMapping, inputPadMapping);
            SceneManager.LoadSceneAsync("inputMapper", LoadSceneMode.Additive);
        }
    }