Example #1
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();
                }
            }
        }
    }
Example #2
0
    private static void DefaultMoveCursorAction(
        this UFEScreen screen,
        Fix64 horizontalAxis,
        Fix64 verticalAxis,
        bool horizontalAxisDown,
        bool verticalAxisDown,
        bool confirmButtonDown,
        bool cancelButtonDown,
        AudioClip sound
        )
    {
        bool axisDown = horizontalAxisDown || verticalAxisDown;

        //---------------------------------------------------------------------------------------------------------
        // Retrieve the current selected GameObject.
        // If no GameObject is selected and the player press any button, select the first GameObject at the screen.
        //---------------------------------------------------------------------------------------------------------
        GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject;

        if (currentGameObject == null && axisDown || confirmButtonDown || cancelButtonDown)
        {
            currentGameObject = screen.FindFirstSelectableGameObject();
        }

        //---------------------------------------------------------------------------------------------------------
        // Check if the current Selectable Object is a Slider
        //---------------------------------------------------------------------------------------------------------
        Slider slider = currentGameObject != null?currentGameObject.GetComponent <Slider>() : null;

        //-----------------------------------------------------------------------------------------------------
        // If the current Selectable Object is a Slider, check if the user has pressed a button
        // in the same direction (horizontal / vertical) than the slider, change the slider value.
        //
        // If the current Selectable Object is not an Slider or if the user hasn't pressed a button
        // in the same direction (horizontal / vertical) than the slider, move the cursor
        //-----------------------------------------------------------------------------------------------------
        if (slider != null)
        {
            if (horizontalAxisDown && slider.direction == Slider.Direction.LeftToRight)
            {
                if (slider.wholeNumbers)
                {
                    slider.value += FPMath.Sign(horizontalAxis);
                }
                else
                {
                    slider.normalizedValue += FPMath.Sign(horizontalAxis) * UFEScreenExtensions.NormalizedSliderSpeed;
                }
            }
            else if (horizontalAxisDown && slider.direction == Slider.Direction.RightToLeft)
            {
                if (slider.wholeNumbers)
                {
                    slider.value -= FPMath.Sign(horizontalAxis);
                }
                else
                {
                    slider.normalizedValue -= FPMath.Sign(horizontalAxis) * UFEScreenExtensions.NormalizedSliderSpeed;
                }
            }
            else if (verticalAxisDown && slider.direction == Slider.Direction.BottomToTop)
            {
                if (slider.wholeNumbers)
                {
                    slider.value += FPMath.Sign(verticalAxis);
                }
                else
                {
                    slider.normalizedValue += FPMath.Sign(verticalAxis) * UFEScreenExtensions.NormalizedSliderSpeed;
                }
            }
            else if (verticalAxisDown && slider.direction == Slider.Direction.TopToBottom)
            {
                if (slider.wholeNumbers)
                {
                    slider.value -= FPMath.Sign(verticalAxis);
                }
                else
                {
                    slider.normalizedValue -= FPMath.Sign(verticalAxis) * UFEScreenExtensions.NormalizedSliderSpeed;
                }
            }
            else if (axisDown)
            {
                screen.MoveCursor(new Vector3((float)horizontalAxis, (float)verticalAxis), sound);
            }
        }
        else if (axisDown)
        {
            screen.MoveCursor(new Vector3((float)horizontalAxis, (float)verticalAxis), sound);
        }
    }