Exemple #1
0
        public override void HandleButton(InputButton button, InputButtonState state, Player0 player)
        {
            if (state == InputButtonState.Released)
            {
                if (button == Settings.Instance.InputMappings.Crouch)
                {
                    player.ChangeMovement(new Falling(this), false);
                }
                else if (button == InputButton.Left || button == InputButton.Right)
                {
                    if (Freeze)
                    {
                        // player should continue moving in the one that is still pressed
                        Direction = new Vector2f(button == InputButton.Right ? -1 : 1, Direction.Y);
                        Freeze    = false;

                        player.AddMovement(new Walking(this));
                    }
                    else
                    {
                        Direction = new Vector2f(0, Direction.Y);
                        player.AddMovement(new Idle());
                    }
                }
            }
        }
Exemple #2
0
 public override void HandleButton(InputButton button, InputButtonState state, Player0 player)
 {
     if (state == InputButtonState.Pressed)
     {
         // opposite direction was pressed while moving, freeze
         if (button == InputButton.Left || button == InputButton.Right)
         {
             Freeze = true;
         }
     }
     else if (state == InputButtonState.Released)
     {
         if (button == InputButton.Right || button == InputButton.Left)
         {
             if (Freeze)
             {
                 Direction = new Vector2f(button == InputButton.Right ? -1 : 1, Direction.Y);
                 Freeze    = false;
             }
             else
             {
                 player.ChangeMovement(new Crouching());
             }
         }
         else if (button == Settings.Instance.InputMappings.Crouch)
         {
             player.ChangeMovement(new Walking(this));
         }
     }
 }
    /// <summary>
    /// 重置数据
    /// </summary>
    void ResetState()
    {
        m_schemeJoystickIdx = -1;
        m_value             = InputManager.AXIS_ZERO;
        m_rawAxisName       = null;
        m_analogButtonState = InputButtonState.Release;
        m_joystickNegative  = KeyCode.None;
        m_joystickPositive  = KeyCode.None;

        UnRegisterModifibleListener();

        m_isDirty = true;
    }
Exemple #4
0
        private bool CheckValue(KeyCode inputKey, InputButtonState state)
        {
            switch (state)
            {
            case InputButtonState.Press: return(UnityEngine.Input.GetKeyDown(inputKey));

            case InputButtonState.Hold: return(UnityEngine.Input.GetKey(inputKey));

            case InputButtonState.Release: return(UnityEngine.Input.GetKeyUp(inputKey));

            default: return(false);
            }
        }
Exemple #5
0
        private bool CheckButton(ButtonInputObject input, InputButtonState state)
        {
            switch (state)
            {
            case InputButtonState.Press: return(UnityEngine.Input.GetKeyDown(input.Button));

            case InputButtonState.Hold: return(UnityEngine.Input.GetKey(input.Button));

            case InputButtonState.Release: return(UnityEngine.Input.GetKeyUp(input.Button));

            default: return(false);
            }
        }
Exemple #6
0
        public override void HandleButton(InputButton button, InputButtonState state, Player0 player)
        {
            // dashing is uncontrollable
            if (state == InputButtonState.Released)
            {
                if ((button == InputButton.Right && Direction.X > 0) || (button == InputButton.Left && Direction.X < 0))
                {
                    player.AddMovement(new Idle());
                }

                else if (button == Settings.Instance.InputMappings.Run)
                {
                    player.AddMovement(new Walking(Direction.Normalize()));
                }
            }
        }
Exemple #7
0
        public override void HandleButton(InputButton button, InputButtonState state, Player0 player)
        {
            if (state == InputButtonState.Pressed)
            {
                // if direction was changed in air
                if (button == InputButton.Left || button == InputButton.Right)
                {
                    // if opposite direction is pressed
                    if ((button == InputButton.Left && Direction.X > 0) ||
                        (button == InputButton.Right && Direction.X < 0))
                    {
                        Freeze = true;
                        player.AddMovement(new Walking(this));
                    }
                    else
                    {
                        // set new direction
                        Direction = new Vector2f(button == InputButton.Right ? 1 : -1, Direction.Y);
                        player.AddMovement(new Walking(this));
                    }
                }
                else if (button == Settings.Instance.InputMappings.Crouch)
                {
                    player.ChangeMovement(new Diving(this), false);
                }
            }
            else if (state == InputButtonState.Released)
            {
                if (button == InputButton.Left || button == InputButton.Right)
                {
                    if (Freeze)
                    {
                        // player should continue moving in the one that is still pressed
                        Direction = new Vector2f(button == InputButton.Right ? -1 : 1, Direction.Y);
                        Freeze    = false;

                        player.AddMovement(new Walking(this));
                    }
                    else
                    {
                        Direction = new Vector2f(0, Direction.Y);
                        player.AddMovement(new Idle());
                    }
                }
            }
        }
Exemple #8
0
 public override void HandleButton(InputButton button, InputButtonState state, Player0 player)
 {
     if (state == InputButtonState.Released)
     {
         if (button == Settings.Instance.InputMappings.Crouch)
         {
             player.ChangeMovement(new Idle());
         }
     }
     else if (state == InputButtonState.Pressed)
     {
         if (button == InputButton.Left || button == InputButton.Right)
         {
             player.ChangeMovement(new Sneaking(button));
         }
     }
 }
Exemple #9
0
        private bool CheckButton(KeyCode inputKey, InputButtonState state)
        {
            switch (state)
            {
            case InputButtonState.PressAndHold: return(UnityEngine.Input.GetKeyDown(inputKey) || UnityEngine.Input.GetKey(inputKey));

            case InputButtonState.Press: return(UnityEngine.Input.GetKeyDown(inputKey));

            case InputButtonState.Hold: return(UnityEngine.Input.GetKey(inputKey));

            case InputButtonState.Release: return(UnityEngine.Input.GetKeyUp(inputKey));

            default:
                Debug.LogError("Input Updater - CheckButton(): default state should never be reached!");
                break;
            }
            return(false);
        }
    public void UpdateAnalogButton()
    {
        if (m_inputType != JoystickInputType.AnalogButton)
        {
            return;
        }

        if (string.IsNullOrEmpty(m_rawAxisName))
        {
            return;
        }

        float val = Input.GetAxis(m_rawAxisName);

        val = m_invert.value ? -val : val;

        if (val > m_dead)
        {
            if (m_analogButtonState == InputButtonState.JustPressed)
            {
                m_analogButtonState = InputButtonState.Pressed;
            }
            else if (m_analogButtonState == InputButtonState.Release || m_analogButtonState == InputButtonState.JustRelease)
            {
                m_analogButtonState = InputButtonState.JustPressed;
            }
        }
        else
        {
            if (m_analogButtonState == InputButtonState.JustRelease)
            {
                m_analogButtonState = InputButtonState.Release;
            }
            else if (m_analogButtonState == InputButtonState.Pressed || m_analogButtonState == InputButtonState.JustPressed)
            {
                m_analogButtonState = InputButtonState.JustRelease;
            }
        }
    }
Exemple #11
0
    public void LateUpdate()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (IsShow)
            {
                NovelsManager.Instance.IsAcceptConfirm = true;
            }
        }


#if UNITY_EDITOR || UNITY_IPHONE || UNITY_ANDROID
        if (!IsDialogShow && !IsBlackShow && CharacterControl.Instance != null && CharacterControl.Instance.State == CharacterControl.EState.Move)
        {
            PresenterPanel.gameObject.SetActive(true);
            switch (CurrentButtonState)
            {
            case InputButtonState.None:
                CharacterControl.Instance.MoveInput = 0;
                break;

            case InputButtonState.Left:
                CharacterControl.Instance.MoveInput = -1;
                break;

            case InputButtonState.Right:
                CharacterControl.Instance.MoveInput = 1;
                break;
            }
        }
        else
#endif
        {
            PresenterPanel.gameObject.SetActive(false);
            CurrentButtonState = InputButtonState.None;
        }
    }
Exemple #12
0
    private void Awake()
    {
        Instance = this;

        Clear();

        InputListenerManager.RegisterInputEvent(Button_LeftMove.gameObject, new InputCallback()
        {
            PressCallBack = () =>
            {
                CurrentButtonState = InputButtonState.Left;
            },
            CancelCallBack = (o) =>
            {
                if (CurrentButtonState == InputButtonState.Left)
                {
                    CurrentButtonState = InputButtonState.None;
                }
            }
        }, InputListenerManager.PriorityType.UITigger);

        InputListenerManager.RegisterInputEvent(Button_RightMove.gameObject, new InputCallback()
        {
            PressCallBack = () =>
            {
                CurrentButtonState = InputButtonState.Right;
            },
            CancelCallBack = (o) =>
            {
                if (CurrentButtonState == InputButtonState.Right)
                {
                    CurrentButtonState = InputButtonState.None;
                }
            }
        }, InputListenerManager.PriorityType.UITigger);


        InputListenerManager.RegisterInputEvent(Button_Confire.gameObject, new InputCallback()
        {
            ClickCallBack = () =>
            {
                if (CharacterControl.Instance != null)
                {
                    CharacterControl.Instance.OnConfire();
                }
            }
        }, InputListenerManager.PriorityType.UITigger);


        var input = new InputCallback()
        {
            ClickCallBack = () =>
            {
                if (IsShow)
                {
                    NovelsManager.Instance.IsAcceptConfirm = true;
                }
            }
        };


        InputListenerManager.RegisterInputEvent(typeof(UIConfirmBlock), input, InputListenerManager.PriorityType.UI);
    }
        /// <summary>
        /// Updates the button state
        /// </summary>
        /// <param name="game">Game manager</param>
        /// <param name="isDown">Is the button being pressed</param>
        public void Update(Game game, bool isDown)
        {
            // If the button is being pressed
            if (isDown)
            {
                // First checks its previous state
                switch (State)
                {
                    // If it was previously 'just pressed'
                    case InputButtonState.Triggered:
                        // Changes it to pressed
                        State = InputButtonState.Pressed;
                        break;
                    // If it was pressed, do nothing
                    case InputButtonState.Pressed:
                        break;
                    // If it was repeated
                    case InputButtonState.Repeated:
                        // Change it to pressed
                        State = InputButtonState.Pressed;
                        break;
                    // If it was 'unpressed'
                    default:
                        // Change it to 'just pressed'
                        State = InputButtonState.Triggered;
                        break;
                }

                // If repeating is enabled
                if (IsRepeatEnabled)
                {
                    // If the repeating timer is 0
                    if (RepeatTimer <= 0)
                        // If the repeating cycle started, set the timer to the interval, otherwise to the delay
                        RepeatTimer = IsRepeating ? RepeatInterval : RepeatDelay;

                    // Decreases the timer
                    RepeatTimer -= game.DeltaMilliseconds;

                    // When it reaches 0
                    if (RepeatTimer <= 0)
                    {
                        // Changes the state to repeated
                        State = InputButtonState.Repeated;
                        // And set that the repeating cycle started
                        IsRepeating = true;
                    }
                }
                // If repeating is disabled
                else
                {
                    // Then sets the repeating cycle flag to false
                    IsRepeating = false;
                    // And resets the timer
                    RepeatTimer = 0;
                }
            }
            // If the button is 'unpressed'
            else
            {
                // Checks it previous state
                switch (State)
                {
                    // If it was previously 'unpressed'
                    case InputButtonState.None:
                        // Do nothing
                        break;
                    // If it was previously 'just released'
                    case InputButtonState.Released:
                        // Sets its state to 'unpressed'
                        State = InputButtonState.None;
                        break;
                    // If it was 'just pressed', pressed, repeated or whatever
                    default:
                        // Changes it to released
                        State = InputButtonState.Released;
                        break;
                }

                // Also sets the repeating cycle flag to false
                IsRepeating = false;
                // And resets the timer
                RepeatTimer = 0;
            }
        }
Exemple #14
0
 public abstract void HandleButton(InputButton button, InputButtonState state);
Exemple #15
0
 public override void HandleButton(InputButton button, InputButtonState state, Player0 player)
 {
 }
Exemple #16
0
        public override void HandleButton(InputButton button, InputButtonState state, Player0 player)
        {
            if (state == InputButtonState.Pressed)
            {
                // if direction was changed in air
                if (button == InputButton.Left || button == InputButton.Right)
                {
                    // if opposite direction is pressed
                    if ((button == InputButton.Left && Direction.X > 0) ||
                        (button == InputButton.Right && Direction.X < 0))
                    {
                        Freeze = true;
                        player.AddMovement(new Walking(this));
                    }
                    else
                    {
                        // set new direction
                        Direction = new Vector2f(button == InputButton.Right ? 1 : -1, Direction.Y);
                        player.AddMovement(new Walking(Direction));
                    }
                }
                else if (button == Settings.Instance.InputMappings.Crouch)
                {
                    player.ChangeMovement(new Diving(this), false);
                }
                else if (button == Settings.Instance.InputMappings.Jump)
                {
                    if (ExtraJump > 0)
                    {
                        ExtraJump--;
                        Jump = new Vector2f(0, JumpImpulse * DoubleJumpMultiplier);
                    }
                }
                else if (button == Settings.Instance.InputMappings.Dash)
                {
                    if (!Freeze && Math.Abs(Direction.X) > 0)
                    {
                        player.ChangeMovement(new Dashing(this), false);
                    }
                }
            }
            else if (state == InputButtonState.Released)
            {
                if (button == InputButton.Right || button == InputButton.Left)
                {
                    if (Freeze)
                    {
                        // player should continue moving in the one that is still pressed
                        Direction = new Vector2f(button == InputButton.Right ? -1 : 1, Direction.Y);
                        Freeze    = false;

                        player.AddMovement(new Walking(Direction));
                    }
                    else
                    {
                        Direction = new Vector2f(0, Direction.Y);
                        player.AddMovement(new Idle());
                    }
                }
                else if (button == Settings.Instance.InputMappings.Jump)
                {
                    if (player.Velocity.Y > 0)
                    {
                        player.Velocity.Y = 0.0;
                    }
                }
                else if (button == Settings.Instance.InputMappings.Run)
                {
                    RunMultiplier = 1.0;
                    player.AddMovement(new Walking(this));
                }
            }
        }
Exemple #17
0
 public override void HandleButton(InputButton button, InputButtonState state)
 {
     Movement.Current?.HandleButton(button, state, this);
 }
Exemple #18
0
 public abstract void HandleButton(InputButton button, InputButtonState state, Player0 player);