示例#1
0
    public static void MoveCursor(this UFEScreen screen, Vector3 direction, AudioClip moveCursorSound = null)
    {
        GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject;
        GameObject nextGameObject    = null;

        if (currentGameObject != null && currentGameObject.activeInHierarchy)
        {
            Selectable currentSelectableObject = currentGameObject.GetComponent <Selectable>();

            if (currentSelectableObject != null && currentSelectableObject.IsInteractable())
            {
                Selectable nextSelectableObject = currentSelectableObject.FindSelectable(direction);

                if (nextSelectableObject != null)
                {
                    nextGameObject = nextSelectableObject.gameObject;
                }
            }
        }

        if (nextGameObject == null)
        {
            nextGameObject = screen.FindFirstSelectableGameObject();
        }

        if (currentGameObject != nextGameObject)
        {
            if (moveCursorSound != null)
            {
                UFE.PlaySound(moveCursorSound);
            }
            screen.HighlightOption(nextGameObject);
        }
    }
示例#2
0
    public static void SelectOption(this UFEScreen screen, AudioClip selectSound = null)
    {
        // Retrieve the current selected object...
        GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject;

        if (currentGameObject != null)
        {
            // Check if it's a button...
            Button currentButton = currentGameObject.GetComponent <Button>();
            if (currentButton != null)
            {
                // In that case, raise the "On Click" event
                if (currentButton.onClick != null)
                {
                    if (selectSound != null)
                    {
                        UFE.PlaySound(selectSound);
                    }
                    currentButton.onClick.Invoke();
                }
            }
            else
            {
                // Otherwise, check if it's a toggle...
                Toggle currentToggle = currentGameObject.GetComponent <Toggle>();
                if (currentToggle != null)
                {
                    // In that case, change the state of the toggle...
                    currentToggle.isOn = !currentToggle.isOn;
                }
            }
        }
        else
        {
            currentGameObject = screen.FindFirstSelectableGameObject();
            if (selectSound != null)
            {
                UFE.PlaySound(selectSound);
            }
            screen.HighlightOption(currentGameObject);
        }
    }
示例#3
0
    public static void MoveCursor(this UFEScreen screen, Vector3 direction, AudioClip moveCursorSound = null)
    {
        GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject;
        GameObject nextGameObject    = screen.FindSelectableGameObject(direction);

        if (nextGameObject == null)
        {
            nextGameObject = currentGameObject;
        }

        if (currentGameObject != nextGameObject)
        {
            if (moveCursorSound != null)
            {
                UFE.PlaySound(moveCursorSound);
            }

            screen.HighlightOption(nextGameObject);
        }
    }
示例#4
0
 public static void HighlightOption(this UFEScreen screen, Selectable option, BaseEventData pointer = null)
 {
     screen.HighlightOption(option != null ? option.gameObject : null, pointer);
 }
示例#5
0
    public static bool DefaultNavigationSystem(
        this UFEScreen screen,
        IDictionary <InputReferences, InputEvents> previousInputs,
        IDictionary <InputReferences, InputEvents> currentInputs,
        AudioClip moveCursorSound = null,
        AudioClip confirmSound    = null,
        AudioClip cancelSound     = null,
        Action cancelAction       = null
        )
    {
        if (UFE.eventSystem != null && UFE.eventSystem.isActiveAndEnabled)
        {
            //---------------------------------------------------------------------------------------------------------
            // First, check if the current Selectable Object is an Input Field, because it's a special case...
            //---------------------------------------------------------------------------------------------------------
            GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject;
            InputField inputField        = currentGameObject != null?currentGameObject.GetComponent <InputField>() : null;

            if (inputField != null)
            {
                //-----------------------------------------------------------------------------------------------------
                // If it's an Input Field, check if the user wants to write a text
                // or if he wants to move the caret or exit from the Input Field...
                //-----------------------------------------------------------------------------------------------------
                Vector3 direction =
                    (Input.GetKeyDown(KeyCode.UpArrow) ? Vector3.up : Vector3.zero) +
                    (Input.GetKeyDown(KeyCode.DownArrow) ? Vector3.down : Vector3.zero);

                if (
                    direction != Vector3.zero ||
                    Input.GetKeyDown(KeyCode.Tab) ||
                    Input.GetKeyDown(KeyCode.Return) ||
                    Input.GetKeyDown(KeyCode.KeypadEnter)
                    )
                {
                    Selectable previousSelectable = inputField;
                    Selectable nextSelectable     = null;

                    if (direction != Vector3.zero)
                    {
                        nextSelectable = currentGameObject.FindSelectable(direction, false);
                    }

                    if (nextSelectable == null || previousSelectable == nextSelectable)
                    {
                        nextSelectable = currentGameObject.FindSelectable(Vector3.right, false);

                        if (nextSelectable == null || previousSelectable == nextSelectable)
                        {
                            nextSelectable = currentGameObject.FindSelectable(Vector3.down, false);

                            if (nextSelectable == null || previousSelectable == nextSelectable)
                            {
                                nextSelectable = currentGameObject.FindSelectable(Vector3.left, false);

                                if (nextSelectable == null || previousSelectable == nextSelectable)
                                {
                                    nextSelectable = currentGameObject.FindSelectable(Vector3.up, false);
                                }
                            }
                        }
                    }

                    screen.HighlightOption(nextSelectable);
                }
                else
                {
                    inputField.OnUpdateSelected(new AxisEventData(UFE.eventSystem));
                }
                return(true);
            }
            else
            {
                //-----------------------------------------------------------------------------------------------------
                // Otherwise, invoke the "Special Navigation System" with the default functions
                //-----------------------------------------------------------------------------------------------------
                return(screen.SpecialNavigationSystem(
                           previousInputs,
                           currentInputs,
                           new MoveCursorCallback(screen.DefaultMoveCursorAction, moveCursorSound),
                           new ActionCallback(UFE.eventSystem.currentSelectedGameObject.DefaultConfirmAction, confirmSound),
                           new ActionCallback(cancelAction.DefaultCancelAction, cancelSound)
                           ));
            }
        }
        return(false);
    }