Ejemplo n.º 1
0
    public static bool SpecialNavigationSystem(
        this UFEScreen screen,
        int player,
        MoveCursorCallback moveCursorCallback = null,
        ActionCallback confirmCallback        = null,
        ActionCallback cancelCallback         = null
        )
    {
        //-------------------------------------------------------------------------------------------------------------
        // Retrieve the controller assigned to specified player
        //-------------------------------------------------------------------------------------------------------------
        AbstractInputController inputController = UFE.GetController(player);

        if (inputController != null && UFE.eventSystem != null && UFE.eventSystem.isActiveAndEnabled)
        {
            return(UFEScreenExtensions.SpecialNavigationSystem(
                       inputController,
                       inputController.GetAxisRaw(inputController.horizontalAxis),
                       inputController.GetAxisRaw(inputController.verticalAxis),
                       inputController.GetButtonDown(inputController.horizontalAxis),
                       inputController.GetButtonDown(inputController.verticalAxis),
                       inputController.GetButtonDown(UFE.config.inputOptions.confirmButton),
                       inputController.GetButtonDown(UFE.config.inputOptions.cancelButton),
                       moveCursorCallback,
                       confirmCallback,
                       cancelCallback
                       ));
        }

        return(false);
    }
    public override void DoFixedUpdate()
    {
        base.DoFixedUpdate();

        AbstractInputController p1InputController = UFE.GetPlayer1Controller();
        AbstractInputController p2InputController = UFE.GetPlayer2Controller();

        // Retrieve the values of the horizontal and vertical axis
        float p1VerticalAxis = p1InputController.GetAxisRaw(p1InputController.horizontalAxis);
        bool  p1AxisDown     = p1InputController.GetButtonDown(p1InputController.horizontalAxis);

        float p2VerticalAxis = p2InputController.GetAxisRaw(p2InputController.horizontalAxis);
        bool  p2AxisDown     = p2InputController.GetButtonDown(p2InputController.horizontalAxis);


        if (p1AxisDown)
        {
            if (p1VerticalAxis > 0f)
            {
                this.PreviousStage();
            }
            else if (p1VerticalAxis < 0f)
            {
                this.NextStage();
            }
        }

        if (p1InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
        {
            this.TrySelectStage();
        }
        else if (p1InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
        {
            this.TryDeselectStage();
        }

        if (p2AxisDown)
        {
            if (p2VerticalAxis > 0f)
            {
                this.PreviousStage();
            }
            else if (p2VerticalAxis < 0f)
            {
                this.NextStage();
            }
        }

        if (p2InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
        {
            this.TrySelectStage();
        }
        else if (p2InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
        {
            this.TryDeselectStage();
        }
    }
Ejemplo n.º 3
0
    public static void DefaultNavigationSystem(
        this UFEScreen screen,
        AudioClip selectSound     = null,
        AudioClip moveCursorSound = null,
        Action cancelAction       = null,
        AudioClip cancelSound     = null
        )
    {
        // Retrieve the controller assigned to each player
        AbstractInputController p1InputController = UFE.GetPlayer1Controller();
        AbstractInputController p2InputController = UFE.GetPlayer2Controller();

        // Retrieve the values of the horizontal and vertical axis
        float p1HorizontalAxis = p1InputController.GetAxisRaw(p1InputController.horizontalAxis);
        float p1VerticalAxis   = p1InputController.GetAxisRaw(p1InputController.verticalAxis);
        bool  p1AxisDown       =
            p1InputController.GetButtonDown(p1InputController.horizontalAxis) ||
            p1InputController.GetButtonDown(p1InputController.verticalAxis);

        float p2HorizontalAxis = p2InputController.GetAxisRaw(p2InputController.horizontalAxis);
        float p2VerticalAxis   = p2InputController.GetAxisRaw(p2InputController.verticalAxis);
        bool  p2AxisDown       =
            p2InputController.GetButtonDown(p2InputController.horizontalAxis) ||
            p2InputController.GetButtonDown(p2InputController.verticalAxis);

        // Check if we should change the selected option
        if (p1AxisDown)
        {
            screen.MoveCursor(new Vector3(p1HorizontalAxis, p1VerticalAxis), moveCursorSound);
        }

        if (p1InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
        {
            screen.SelectOption(selectSound);
        }
        else if (p1InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
        {
            if (cancelSound != null)
            {
                UFE.PlaySound(cancelSound);
            }
            if (cancelAction != null)
            {
                cancelAction();
            }
        }
        else
        {
            if (p2AxisDown)
            {
                screen.MoveCursor(new Vector3(p2HorizontalAxis, p2VerticalAxis), moveCursorSound);
            }

            if (p2InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
            {
                screen.SelectOption(selectSound);
            }
            else if (p2InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
            {
                if (cancelSound != null)
                {
                    UFE.PlaySound(cancelSound);
                }
                if (cancelAction != null)
                {
                    cancelAction();
                }
            }
        }
    }
Ejemplo n.º 4
0
    public override void DoFixedUpdate()
    {
        base.DoFixedUpdate();

        if (this.isRunning)
        {
            AbstractInputController p1InputController = UFE.GetPlayer1Controller();
            AbstractInputController p2InputController = UFE.GetPlayer2Controller();
            float deltaTime = Time.fixedDeltaTime;

            // Animate the alert messages if they exist
            if (this.player1GUI != null && this.player1GUI.alert != null && this.player1GUI.alert.text != null)
            {
                this.player1GUI.alert.text.rectTransform.anchoredPosition = Vector3.Lerp(
                    this.player1GUI.alert.text.rectTransform.anchoredPosition,
                    this.player1GUI.alert.finalPosition,
                    this.player1GUI.alert.movementSpeed * deltaTime
                    );

                if (this.player1AlertTimer > 0f)
                {
                    this.player1AlertTimer -= deltaTime;
                }
                else if (!string.IsNullOrEmpty(this.player1GUI.alert.text.text))
                {
                    this.player1GUI.alert.text.text = string.Empty;
                }
            }

            if (this.player2GUI != null && this.player2GUI.alert != null && this.player2GUI.alert.text != null)
            {
                this.player2GUI.alert.text.rectTransform.anchoredPosition = Vector3.Lerp(
                    this.player2GUI.alert.text.rectTransform.anchoredPosition,
                    this.player2GUI.alert.finalPosition,
                    this.player2GUI.alert.movementSpeed * deltaTime
                    );

                if (this.player2AlertTimer > 0f)
                {
                    this.player2AlertTimer -= deltaTime;
                }
                else if (!string.IsNullOrEmpty(this.player2GUI.alert.text.text))
                {
                    this.player2GUI.alert.text.text = string.Empty;
                }
            }

            if (this.mainAlert != null && this.mainAlert.text != null)
            {
                if (this.mainAlertTimer > 0f)
                {
                    this.mainAlertTimer -= deltaTime;
                }
                else if (!string.IsNullOrEmpty(this.mainAlert.text.text))
                {
                    this.mainAlert.text.text = string.Empty;
                }
            }


            // Animate life points when it goes down (P1)
            if (this.player1.targetLife > UFE.config.player1Character.currentLifePoints)
            {
                this.player1.targetLife -= this.lifeDownSpeed * deltaTime;
                if (this.player1.targetLife < UFE.config.player1Character.currentLifePoints)
                {
                    this.player1.targetLife = UFE.config.player1Character.currentLifePoints;
                }
            }
            if (this.player1.targetLife < UFE.config.player1Character.currentLifePoints)
            {
                this.player1.targetLife += this.lifeUpSpeed * deltaTime;
                if (this.player1.targetLife > UFE.config.player1Character.currentLifePoints)
                {
                    this.player1.targetLife = UFE.config.player1Character.currentLifePoints;
                }
            }

            // Animate life points when it goes down (P2)
            if (this.player2.targetLife > UFE.config.player2Character.currentLifePoints)
            {
                this.player2.targetLife -= this.lifeDownSpeed * deltaTime;
                if (this.player2.targetLife < UFE.config.player2Character.currentLifePoints)
                {
                    this.player2.targetLife = UFE.config.player2Character.currentLifePoints;
                }
            }
            if (this.player2.targetLife < UFE.config.player2Character.currentLifePoints)
            {
                this.player2.targetLife += this.lifeUpSpeed * deltaTime;
                if (this.player2.targetLife > UFE.config.player2Character.currentLifePoints)
                {
                    this.player2.targetLife = UFE.config.player2Character.currentLifePoints;
                }
            }


            if (
                // Check if both players have their life points above zero...
                UFE.config.player1Character.currentLifePoints > 0 &&
                UFE.config.player2Character.currentLifePoints > 0 &&
                UFE.gameMode != GameMode.NetworkGame &&
                (
                    // and at least one of the players have pressed the Start button...
                    p1InputController != null && p1InputController.GetButtonDown(ButtonPress.Start) ||
                    p2InputController != null && p2InputController.GetButtonDown(ButtonPress.Start)
                )
                )
            {
                // In that case, we can process pause menu events
                UFE.PauseGame(!UFE.isPaused());
            }


            // Draw the Life Bars and Gauge Meters using the data stored in UFE.config.guiOptions
            if (this.player1GUI != null && this.player1GUI.lifeBar != null)
            {
                this.player1GUI.lifeBar.fillAmount = this.player1.targetLife / this.player1.totalLife;
            }

            if (this.player2GUI != null && this.player2GUI.lifeBar != null)
            {
                this.player2GUI.lifeBar.fillAmount = this.player2.targetLife / this.player2.totalLife;
            }

            if (UFE.config.gameGUI.hasGauge)
            {
                if (this.player1GUI != null && this.player1GUI.gaugeMeter != null)
                {
                    this.player1GUI.gaugeMeter.fillAmount = UFE.config.player1Character.currentGaugePoints / UFE.config.player1Character.maxGaugePoints;
                }

                if (this.player2GUI != null && this.player2GUI.gaugeMeter != null)
                {
                    this.player2GUI.gaugeMeter.fillAmount = UFE.config.player2Character.currentGaugePoints / UFE.config.player2Character.maxGaugePoints;
                }
            }

            if (this.pause != null)
            {
                this.pause.DoFixedUpdate();
            }


            /*
             * if (Debug.isDebugBuild){
             *      player1NameGO.guiText.text = string.Format(
             *              "{0}\t\t({1},\t{2},\t{3})",
             *              this.player1.characterName,
             *              UFE.GetPlayer1ControlsScript().transform.position.x,
             *              UFE.GetPlayer1ControlsScript().transform.position.y,
             *              UFE.GetPlayer1ControlsScript().transform.position.z
             *      );
             *
             *      player2NameGO.guiText.text = string.Format(
             *              "{0}\t\t({1},\t{2},\t{3})",
             *              this.player2.characterName,
             *              UFE.GetPlayer2ControlsScript().transform.position.x,
             *              UFE.GetPlayer2ControlsScript().transform.position.y,
             *              UFE.GetPlayer2ControlsScript().transform.position.z
             *      );
             * }
             */
        }
    }
Ejemplo n.º 5
0
    private void translateInputs(AbstractInputController inputController)
    {
        if (!introPlayed || !opControlsScript.introPlayed) return;
        if (UFE.config.lockInputs && !UFE.config.roundOptions.allowMovement) return;
        if (UFE.config.lockMovements) return;

        foreach (InputReferences inputRef in inputController.inputReferences) {
            if (((inputRef.engineRelatedButton == ButtonPress.Down && inputController.GetAxisRaw(inputRef) >= 0)
                 || (inputRef.engineRelatedButton == ButtonPress.Up && inputController.GetAxisRaw(inputRef) <= 0))
                && myPhysicsScript.IsGrounded()
                && !myHitBoxesScript.isHit
                && currentSubState != SubStates.Stunned){
                currentState = PossibleStates.Stand;
            }

            if (inputRef.inputType != InputType.Button && inputRef.heldDown > 0 && inputController.GetAxisRaw(inputRef) == 0) {
                if ((inputRef.engineRelatedButton == ButtonPress.Back && UFE.config.blockOptions.blockType == BlockType.HoldBack)){
                    potentialBlock = false;
                }

                storedMove = myMoveSetScript.GetMove(new ButtonPress[]{inputRef.engineRelatedButton}, inputRef.heldDown, currentMove, true);
                inputRef.heldDown = 0;
                if (storedMove != null){
                    storedMoveTime = ((float)UFE.config.executionBufferTime / UFE.config.fps);
                    return;
                }
            }

            if (inputRef.heldDown == 0 && inputRef.inputType != InputType.Button) {
                inputRef.activeIcon = inputController.GetAxisRaw(inputRef) > 0? inputRef.inputViewerIcon1 : inputRef.inputViewerIcon2;
            }

            /*if (inputController.GetButtonUp(inputRef)) {
                storedMove = myMoveSetScript.GetMove(new ButtonPress[]{inputRef.engineRelatedButton}, inputRef.heldDown, currentMove, true);
                inputRef.heldDown = 0;
                if (storedMove != null){
                    storedMoveTime = ((float)UFE.config.executionBufferTime / UFE.config.fps);
                    return;
                }
            }*/

            // Axis Press
            if (inputRef.inputType != InputType.Button && inputController.GetAxisRaw(inputRef) != 0) {
                if (inputRef.inputType == InputType.HorizontalAxis) {
                    // Horizontal Movements
                    if (inputController.GetAxisRaw(inputRef) > 0) {
                        inputRef.engineRelatedButton = mirror == 1? ButtonPress.Back : ButtonPress.Foward;
                        inputRef.heldDown += Time.fixedDeltaTime;
                        if (inputRef.heldDown == Time.fixedDeltaTime && testMoveExecution(inputRef.engineRelatedButton, false)) return;

                        if (currentState == PossibleStates.Stand
                            && !isBlocking
                            && !myPhysicsScript.isTakingOff
                            && !myPhysicsScript.isLanding
                            && currentSubState != SubStates.Stunned
                            && !blockStunned
                            && currentMove == null
                            && myMoveSetScript.basicMoves.moveEnabled) {
                            myPhysicsScript.Move(-mirror, inputController.GetAxisRaw(inputRef));
                        }
                    }

                    if (inputController.GetAxisRaw(inputRef) < 0) {
                        inputRef.engineRelatedButton = mirror == 1? ButtonPress.Foward : ButtonPress.Back;
                        inputRef.heldDown += Time.fixedDeltaTime;
                        if (inputRef.heldDown == Time.fixedDeltaTime && testMoveExecution(inputRef.engineRelatedButton, false)) return;

                        if (currentState == PossibleStates.Stand
                            && !isBlocking
                            && !myPhysicsScript.isTakingOff
                            && !myPhysicsScript.isLanding
                            && currentSubState != SubStates.Stunned
                            && !blockStunned
                            && currentMove == null
                            && myMoveSetScript.basicMoves.moveEnabled) {
                            myPhysicsScript.Move(mirror, inputController.GetAxisRaw(inputRef));
                        }
                    }

                    // Check for potential blocking
                    if (inputRef.engineRelatedButton == ButtonPress.Back
                        && UFE.config.blockOptions.blockType == BlockType.HoldBack
                        && !myPhysicsScript.isTakingOff
                        && myMoveSetScript.basicMoves.blockEnabled) {
                        potentialBlock = true;
                    }

                    // Check for potential parry
                    if (((inputRef.engineRelatedButton == ButtonPress.Back && UFE.config.blockOptions.parryType == ParryType.TapBack) ||
                         (inputRef.engineRelatedButton == ButtonPress.Foward && UFE.config.blockOptions.parryType == ParryType.TapForward))
                        && potentialParry == 0
                        && inputRef.heldDown == Time.fixedDeltaTime
                        && currentMove == null
                        && !isBlocking
                        && !myPhysicsScript.isTakingOff
                        && currentSubState != SubStates.Stunned
                        && !blockStunned
                        && myMoveSetScript.basicMoves.parryEnabled) {
                        potentialParry = UFE.config.blockOptions.parryTiming;
                    }

                }else{
                    // Vertical Movements
                    if (inputController.GetAxisRaw(inputRef) > 0) {
                        inputRef.engineRelatedButton = ButtonPress.Up;
                        if (!myPhysicsScript.isTakingOff && !myPhysicsScript.isLanding){
                            if (inputRef.heldDown == 0) {
                                if (!myPhysicsScript.IsGrounded() && myInfo.physics.canJump && myInfo.physics.multiJumps > 1){
                                    myPhysicsScript.Jump();
                                }
                                if (testMoveExecution(inputRef.engineRelatedButton, false)) return;
                            }
                            if (!myPhysicsScript.freeze
                                && !myPhysicsScript.IsJumping()
                                && storedMove == null
                                && currentMove == null
                                && currentState == PossibleStates.Stand
                                && currentSubState != SubStates.Stunned
                                && !isBlocking
                                && myInfo.physics.canJump
                                && !blockStunned
                                && myMoveSetScript.basicMoves.jumpEnabled) {

                                float delayTime = (float)myInfo.physics.jumpDelay/UFE.config.fps;
                                myPhysicsScript.isTakingOff = true;
                                potentialBlock = false;
                                potentialParry = 0;

                                UFE.DelaySynchronizedAction(myPhysicsScript.Jump, delayTime);

                                if (myMoveSetScript.AnimationExists(myMoveSetScript.basicMoves.takeOff.name)){
                                    myMoveSetScript.PlayBasicMove(myMoveSetScript.basicMoves.takeOff);

                                    if (myMoveSetScript.basicMoves.takeOff.autoSpeed) {
                                        myMoveSetScript.SetAnimationSpeed(
                                            myMoveSetScript.basicMoves.takeOff.name,
                                            myMoveSetScript.GetAnimationLengh(myMoveSetScript.basicMoves.takeOff.name) / delayTime);
                                    }

                                }
                            }
                        }
                        inputRef.heldDown += Time.fixedDeltaTime;

                    }else if (inputController.GetAxisRaw(inputRef) < 0) {
                        inputRef.engineRelatedButton = ButtonPress.Down;
                        if (inputRef.heldDown == 0 && testMoveExecution(inputRef.engineRelatedButton, false)) return;
                        inputRef.heldDown += Time.fixedDeltaTime;

                        if (!myPhysicsScript.freeze
                            && myPhysicsScript.IsGrounded()
                            && currentMove == null
                            && currentSubState != SubStates.Stunned
                            && !myPhysicsScript.isTakingOff
                            && !blockStunned
                            && myMoveSetScript.basicMoves.crouchEnabled) {
                            currentState = PossibleStates.Crouch;
                            if (!myMoveSetScript.IsAnimationPlaying(myMoveSetScript.basicMoves.crouching.name)) {
                                if (!isBlocking && !myMoveSetScript.IsAnimationPlaying(myMoveSetScript.basicMoves.crouching.name))
                                    myMoveSetScript.PlayBasicMove(myMoveSetScript.basicMoves.crouching);

                                if (isBlocking && !myMoveSetScript.IsAnimationPlaying(myMoveSetScript.basicMoves.blockingCrouchingPose.name))
                                    myMoveSetScript.PlayBasicMove(myMoveSetScript.basicMoves.blockingCrouchingPose);
                            }
                        }
                    }
                }

                foreach (InputReferences inputRef2 in inputController.inputReferences) {
                    if (inputRef2.inputType == InputType.Button && inputController.GetButtonDown(inputRef2)) {
                        storedMove = myMoveSetScript.GetMove(
                            new ButtonPress[]{inputRef.engineRelatedButton, inputRef2.engineRelatedButton}, 0, currentMove, false, true);

                        if (storedMove != null){
                            storedMoveTime = ((float)UFE.config.executionBufferTime / UFE.config.fps);
                            return;
                        }
                    }
                }
            }

            // Button Press
            if (inputRef.inputType == InputType.Button && !UFE.config.lockInputs){
                if (inputController.GetButton(inputRef)) {
                    if (myMoveSetScript.CompareBlockButtons(inputRef.engineRelatedButton)
                        && currentSubState != SubStates.Stunned
                        && !myPhysicsScript.isTakingOff
                        && !blockStunned
                        && myMoveSetScript.basicMoves.blockEnabled) {
                        potentialBlock = true;
                        CheckBlocking(true);
                    }

                    if (myMoveSetScript.CompareParryButtons(inputRef.engineRelatedButton)
                        && inputRef.heldDown == 0
                        && potentialParry == 0
                        && currentMove == null
                        && !isBlocking
                        && currentSubState != SubStates.Stunned
                        && !myPhysicsScript.isTakingOff
                        && !blockStunned
                        && myMoveSetScript.basicMoves.parryEnabled) {
                        potentialParry = UFE.config.blockOptions.parryTiming;
                    }

                    inputRef.heldDown += Time.fixedDeltaTime;
                    if (inputRef.heldDown <= ((float)UFE.config.plinkingDelay/(float)UFE.config.fps)) {
                        foreach (InputReferences inputRef2 in inputController.inputReferences) {
                            if (inputRef2 != inputRef
                                && inputRef2.inputType == InputType.Button
                                && inputController.GetButtonDown(inputRef2)) {
                                inputRef2.heldDown += Time.fixedDeltaTime;
                                storedMove = myMoveSetScript.GetMove(
                                    new ButtonPress[]{inputRef.engineRelatedButton, inputRef2.engineRelatedButton}, 0, currentMove, false, true);

                                if (storedMove != null && (currentMove == null || currentMove.currentFrame <= UFE.config.plinkingDelay)){
                                    KillCurrentMove();
                                    storedMoveTime = ((float)UFE.config.executionBufferTime / UFE.config.fps);
                                    return;
                                }
                            }
                        }
                    }
                }

                if (inputController.GetButtonDown(inputRef)) {
                    storedMove = myMoveSetScript.GetMove(new ButtonPress[]{inputRef.engineRelatedButton}, 0, currentMove, false);
                    if (storedMove != null){
                        storedMoveTime = ((float)UFE.config.executionBufferTime / UFE.config.fps);
                        return;
                    }
                }

                if (inputController.GetButtonUp(inputRef)) {
                    storedMove = myMoveSetScript.GetMove(new ButtonPress[]{inputRef.engineRelatedButton}, inputRef.heldDown, currentMove, true);
                    inputRef.heldDown = 0;
                    if (storedMove != null) {
                        storedMoveTime = ((float)UFE.config.executionBufferTime / UFE.config.fps);
                        return;
                    }
                    if (myMoveSetScript.CompareBlockButtons(inputRef.engineRelatedButton)
                        && !myPhysicsScript.isTakingOff) {
                        potentialBlock = false;
                        CheckBlocking(false);
                    }
                }
            }
        }
    }
Ejemplo n.º 6
0
    public override void DoFixedUpdate()
    {
        base.DoFixedUpdate();

        AbstractInputController p1InputController = UFE.GetPlayer1Controller();
        AbstractInputController p2InputController = UFE.GetPlayer2Controller();

        // Retrieve the values of the horizontal and vertical axis
        bool p1AxisDown =
            p1InputController.GetButtonDown(p1InputController.horizontalAxis) ||
            p1InputController.GetButtonDown(p1InputController.verticalAxis);

        bool p2AxisDown =
            p2InputController.GetButtonDown(p2InputController.horizontalAxis) ||
            p2InputController.GetButtonDown(p2InputController.verticalAxis);

        // Process the player input...
        if (UFE.gameMode != GameMode.StoryMode && !UFE.GetCPU(2))
        {
            // If we are in "Story Mode" or in "Player vs Player (versus mode)", the controller assigned to
            // the first player will be used always for selecting the character assigned to that player. If
            // that player has already selected a character, he can't move the cursor unless he deselects
            // the character first.
            if (p1AxisDown)
            {
                this.MoveCursor(p1InputController, 1);
            }

            if (p1InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
            {
                this.TrySelectCharacter(this.p1HoverIndex, 1);
            }
            else if (p1InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
            {
                this.TryDeselectCharacter(1);
            }

            // The controller assigned to the second player only can be used for selecting the character assigned to
            // the second player in "Player vs Player (versus mode)". In other game modes, the character assigned to
            // the second player will be chosen randomly (Story Mode) or will be selected by Player 1 (Player vs CPU).
            if (p2AxisDown)
            {
                this.MoveCursor(p2InputController, 2);
            }

            if (p2InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
            {
                this.TrySelectCharacter(this.p2HoverIndex, 2);
            }
            else if (p2InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
            {
                this.TryDeselectCharacter(2);
            }
        }
        else
        {
            // However, the character assigned to the second player will be chosen by the first player in other
            // game modes (for example: Player vs CPU).
            if (p1AxisDown)
            {
                this.MoveCursor(p1InputController);
            }

            if (p1InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
            {
                this.TrySelectCharacter();
            }
            else if (p1InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
            {
                this.TryDeselectCharacter();
            }
        }
    }
Ejemplo n.º 7
0
    public override void DoFixedUpdate()
    {
        base.DoFixedUpdate();

        // Retrieve the controller assigned to each player
        AbstractInputController p1InputController = UFE.GetPlayer1Controller();
        AbstractInputController p2InputController = UFE.GetPlayer2Controller();

        // Retrieve the values of the horizontal and vertical axis
        float p1HorizontalAxis     = p1InputController.GetAxisRaw(p1InputController.horizontalAxis);
        float p1VerticalAxis       = p1InputController.GetAxisRaw(p1InputController.verticalAxis);
        bool  p1HorizontalAxisDown = p1InputController.GetButtonDown(p1InputController.horizontalAxis);
        bool  p1VerticalAxisDown   = p1InputController.GetButtonDown(p1InputController.verticalAxis);

        float p2HorizontalAxis     = p2InputController.GetAxisRaw(p2InputController.horizontalAxis);
        float p2VerticalAxis       = p2InputController.GetAxisRaw(p2InputController.verticalAxis);
        bool  p2HorizontalAxisDown = p2InputController.GetButtonDown(p2InputController.horizontalAxis);
        bool  p2VerticalAxisDown   = p2InputController.GetButtonDown(p2InputController.verticalAxis);

        // Check if we should change the selected option
        if (p1HorizontalAxisDown)
        {
            GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject;
            Slider     slider            = null;

            if (currentGameObject != null)
            {
                slider = currentGameObject.GetComponent <Slider>();
            }

            if (slider != null)
            {
                if (slider.wholeNumbers)
                {
                    slider.value += Mathf.Sign(p1HorizontalAxis);
                }
                else
                {
                    slider.value += Mathf.Sign(p1HorizontalAxis) * this.sliderSpeed;
                }
            }
            else if (p1VerticalAxisDown)
            {
                this.MoveCursor(new Vector3(p1HorizontalAxis, p1VerticalAxis), this.moveCursorSound);
            }
            else
            {
                this.MoveCursor(new Vector3(p1HorizontalAxis, 0f), this.moveCursorSound);
            }
        }
        else if (p1VerticalAxisDown)
        {
            this.MoveCursor(new Vector3(0f, p1VerticalAxis), this.moveCursorSound);
        }

        if (p1InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
        {
            this.SelectOption(this.selectSound);
        }
        else if (p1InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
        {
            if (this.cancelSound != null)
            {
                UFE.PlaySound(cancelSound);
            }
            if (this.cancelButton != null && this.cancelButton.onClick != null)
            {
                this.cancelButton.onClick.Invoke();
            }
        }
        else
        {
            if (p2HorizontalAxisDown)
            {
                GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject;
                Slider     slider            = null;

                if (currentGameObject != null)
                {
                    slider = currentGameObject.GetComponent <Slider>();
                }

                if (slider != null)
                {
                    if (slider.wholeNumbers)
                    {
                        slider.value += Mathf.Sign(p2HorizontalAxis);
                    }
                    else
                    {
                        slider.value += Mathf.Sign(p2HorizontalAxis) * this.sliderSpeed;
                    }
                }
                else if (p2VerticalAxisDown)
                {
                    this.MoveCursor(new Vector3(p2HorizontalAxis, p2VerticalAxis), this.moveCursorSound);
                }
                else
                {
                    this.MoveCursor(new Vector3(p2HorizontalAxis, 0f), this.moveCursorSound);
                }
            }
            else if (p2VerticalAxisDown)
            {
                this.MoveCursor(new Vector3(0f, p2VerticalAxis), this.moveCursorSound);
            }

            if (p2InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
            {
                this.SelectOption(this.selectSound);
            }
            else if (p2InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
            {
                if (this.cancelSound != null)
                {
                    UFE.PlaySound(cancelSound);
                }
                if (this.cancelButton != null && this.cancelButton.onClick != null)
                {
                    this.cancelButton.onClick.Invoke();
                }
            }
        }
    }