コード例 #1
0
    public void Update()
    {
        if (InputDevice == null)
        {
            return;
        }

        if (InputDevice.GetButtonDown(MappedButton.OpenMenu))
        {
            InGameMenuUIManager.Instance.ToggleMenu(this);
        }

        if (InGameMenuUIManager.Instance.IsMenuDisplayed())
        {
            return;
        }

        Move(this.InputDevice.GetAxis2DCircleClamp(MappedAxis.Horizontal, MappedAxis.Vertical));

        if (InputDevice.GetButtonDown(MappedButton.Ready))
        {
            ToggleReady();
        }

        if (InputDevice is KeyboardMouseInputDevice)
        {
            Keyboard();
        }
        else
        {
            Gamepad();
        }
    }
コード例 #2
0
    void Update()
    {
        if (isInUse)
        {
            // check for monster Choice change
            if (directionalChoiceInLastFrame)
            {
                if (Mathf.Abs(inputUsed.GetXAxis()) < 0.5f)
                {
                    directionalChoiceInLastFrame = false;
                }
            }
            else
            {
                if (Mathf.Abs(inputUsed.GetXAxis()) > 0.5f)
                {
                    directionalChoiceInLastFrame = true;
                    bool biggerChoiceRequested = inputUsed.GetXAxis() > 0.5f;
                    int  newChoice             = playerSelectScreen.TryToGetDifferentMonsterChoice(monsterChoice, biggerChoiceRequested);
                    monsterChoice = newChoice;
                    ShowMonsterChoice();
                }
            }



            // check for quit
            if (IsInUse() && inputUsed.GetButtonDown(PlayerSelectScreen.leaveKey))
            {
                playerSelectScreen.RemovePlayer(this);
            }
        }
    }
コード例 #3
0
    void Update()
    {
        // Listen for callback from player controller
        //primary button hold down
        if (attachedDevice.GetButtonDown(MappedButton.Cling))
        {
            isLookingToCling = true;
        }

        //primary button released
        if (attachedDevice.GetButtonUp(MappedButton.Cling))
        {
            isLookingToCling = false;
        }
    }
コード例 #4
0
    private void Keyboard()
    {
        float mouseX = InputDevice.GetAxisRaw(MappedAxis.AimX);
        float mouseY = InputDevice.GetAxisRaw(MappedAxis.AimY);

        var mousePos  = Camera.main.ScreenToWorldPoint(new Vector2(mouseX, mouseY));
        var aimVector = Vector2.zero;

        if (AttachedObject == null)
        {
            aimVector = mousePos - transform.position;
        }
        else
        {
            aimVector = mousePos - AttachedObject.transform.position;
        }

        AimReticle(aimVector);

        if (InputDevice.GetButtonDown(MappedButton.ChangeGrav))
        {
            FlipGravity();
        }

        if (InputDevice.GetIsAxisTappedPos(MappedAxis.ChangeGravAxis))
        {
            ChangeGravityTowardsDir(Vector2.up);
        }

        if (InputDevice.GetIsAxisTappedNeg(MappedAxis.ChangeGravAxis))
        {
            ChangeGravityTowardsDir(Vector2.down);
        }


        if (InputDevice.GetButtonDown(MappedButton.ShootGravGun))
        {
            ShootGravityGun(aimVector, ProjectileControllerType.Normal);
        }

        if (InputDevice.GetButtonDown(MappedButton.Special))
        {
            DoSpecial(aimVector);
        }
    }
コード例 #5
0
    private void Gamepad()
    {
        float rightSitckX = InputDevice.GetAxisRaw(MappedAxis.AimX);
        float rightSitckY = InputDevice.GetAxisRaw(MappedAxis.AimY);

        Vector2 aimDir = new Vector2(rightSitckX, rightSitckY);

        if (aimDir == Vector2.zero)
        {
            aimDir = _lastAimDir;
        }
        else
        {
            _lastAimDir = aimDir;
        }

        AimReticle(aimDir);

        if (InputDevice.GetIsAxisTappedPos(MappedAxis.ChangeGravAxis, .5f))
        {
            ChangeGravityTowardsDir(Vector2.up);
        }

        if (InputDevice.GetIsAxisTappedNeg(MappedAxis.ChangeGravAxis, -.5f))
        {
            ChangeGravityTowardsDir(Vector2.down);
        }

        if (InputDevice.GetIsAxisTappedPos(MappedAxis.ChangeGrav) && InputDevice.GetAxis(MappedAxis.ChangeGrav) > 0)
        {
            FlipGravity();
        }

        if (InputDevice.GetIsAxisTappedPos(MappedAxis.ShootGravGun) && aimDir.magnitude > 0)
        {
            ShootGravityGun(aimDir, ProjectileControllerType.Normal);
        }

        if (InputDevice.GetButtonDown(MappedButton.Special))
        {
            DoSpecial(aimDir);
        }
    }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        if (attachedDevice.GetButtonDown(MappedButton.Start))
        {
            // Pause? (Handled by LevelManager
        }
        if (isCharging)
        {
            return;
        }
        // update player angle
        //currentAngle = getAngle(transform.forward.z, transform.forward.x);
        //print ("current angle " + currentAngle);

        // Get Button is frame dependent - JUMP
        if (isGrounded && attachedDevice.GetButtonDown(MappedButton.Jump))
        {
            seperateFromPlayerBelow();
            playerRBody.AddForce(new Vector3(0.0f, jumpForce, 0.0f), ForceMode.Impulse);
            isGrounded = false;
            isJumping  = true;
            animator.SetBool("isJumping", isJumping);
            meowSound.Play();
        }

        if (attachedDevice.GetButtonDown(MappedButton.Cling))
        {
            // Primary
            print("cling");
            clingComponent.Cling();
        }
        // Charge!
        if (isGrounded && !isCharging && attachedDevice.GetButtonDown(MappedButton.Button4))
        {
            Debug.Log("charging");
            chargeDir = transform.forward * 5.0f + transform.up;
            chargeDir = Vector3.Normalize(chargeDir);
            seperateFromPlayerBelow();
            playerRBody.AddForce(chargeDir * 3.0f, ForceMode.Impulse);
            isCharging = true;
            pushMeow.Play();
            chargedList.Clear();
        }

        if (attachedDevice.GetButtonDown(MappedButton.LeftBumper))
        {
            // Left Strafe
            if (isGrounded)
            {
                Vector3 leftForce = transform.right * -movementSpeed * 0.1f;
                seperateFromPlayerBelow();
                playerRBody.AddForce(leftForce + new Vector3(0.0f, jumpForce * 0.5f, 0.0f), ForceMode.Impulse);
                isGrounded = false;
                isJumping  = true;
                animator.SetBool("isJumping", isJumping);
                meowSound.Play();
            }
        }

        if (attachedDevice.GetButtonDown(MappedButton.RightBumper))
        {
            // Right Strafe
            if (isGrounded)
            {
                Vector3 rightForce = transform.right * movementSpeed * 0.1f;
                seperateFromPlayerBelow();
                playerRBody.AddForce(rightForce + new Vector3(0.0f, jumpForce * 0.5f, 0.0f), ForceMode.Impulse);
                isGrounded = false;
                isJumping  = true;
                animator.SetBool("isJumping", isJumping);
                meowSound.Play();
            }
        }
    }
コード例 #7
0
    void ComputeMovement()
    {
        List <Action> activeActions = new List <Action>();

        foreach (Action a in actions)
        {
            if (a.IsActive())
            {
                activeActions.Add(a);
            }
        }

        for (int i = 0; i < actions.Length; i++)
        {
            if (input.GetButtonDown(i) && !actions[i].IsBlockedBy(activeActions))
            {
                actions[i].performAction();
                if (!activeActions.Contains(actions[i]))
                {
                    activeActions.Add(actions[i]);
                }
            }
        }

        bool dashInProgress = false;

        bool actionInProgress = false;

        foreach (Action act in actions)
        {
            if (act.IsActive())
            {
                actionInProgress = true;
                if (act is Dash)
                {
                    dashInProgress = true;
                }
            }
        }


        // choose animation if none in progress
        if (!actionInProgress)
        {
            bool idling = input.GetXAxis() == 0 && input.GetYAxis() == 0;

            if (idling)
            {
                if (currentAnimationState == AnimationState.Idle)
                {
                    chosenIdleAnimator.UpdateAnimation();
                }
                else
                {
                    currentAnimationState = AnimationState.Idle;
                    chosenIdleAnimator.StartAnimation();
                }
            }
            else
            {
                if (currentAnimationState == AnimationState.Walking)
                {
                    chosenWalkingAnimator.UpdateAnimation();
                }
                else
                {
                    currentAnimationState = AnimationState.Walking;
                    chosenWalkingAnimator.StartAnimation();
                }
            }
        }
        else
        {
            currentAnimationState = AnimationState.CustomAction;
        }



        if (!MovementChangesBlocked())
        {
            {
                rigidBody.velocity = Vector2.zero;

                Vector2 moveDir = new Vector2(input.GetXAxis(), input.GetYAxis()).normalized;
                moveDir *= movementSpeed;

                rigidBody.velocity += moveDir;
            }
        }
        else if (dashInProgress)
        {
            rigidBody.velocity = Vector2.zero;

            Vector2 moveDir = lastAnimationMovementDirection.normalized;
            moveDir *= movementSpeed * 2;

            rigidBody.velocity += moveDir;
        }
    }