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);
    }
Ejemplo n.º 2
0
    private static Selectable FindSelectable(Selectable s, Vector3 dir, IList <Selectable> whiteList)
    {
        if (whiteList == null || whiteList.Count == 0)
        {
            return(s.FindSelectable(dir));
        }
        else
        {
            dir = dir.normalized;
            Vector3    vector  = Quaternion.Inverse(s.transform.rotation) * dir;
            Vector3    vector2 = s.transform.TransformPoint(UFEScreenExtensions.GetPointOnRectEdge(s.transform as RectTransform, vector));
            float      num     = float.NegativeInfinity;
            Selectable result  = null;

            for (int i = 0; i < Selectable.allSelectables.Count; i++)
            {
                Selectable selectable = Selectable.allSelectables[i];
                if (selectable != s && selectable != null && whiteList.Contains(selectable))
                {
                    if (selectable.IsInteractable() && selectable.navigation.mode != Navigation.Mode.None)
                    {
                        RectTransform rectTransform = selectable.transform as RectTransform;
                        Vector3       vector3       = (!(rectTransform != null)) ? Vector3.zero : new Vector3(rectTransform.rect.center.x, rectTransform.rect.center.y, 0f);
                        Vector3       vector4       = selectable.transform.TransformPoint(vector3) - vector2;
                        float         num2          = Vector3.Dot(dir, vector4);
                        if (num2 > 0)
                        {
                            float num3 = num2 / vector4.sqrMagnitude;
                            if (num3 > num)
                            {
                                num    = num3;
                                result = selectable;
                            }
                        }
                    }
                }
            }
            return(result);
        }
    }
Ejemplo n.º 3
0
    public static Selectable FindSelectable(
        this GameObject currentGameObject,
        Vector3 direction,
        bool wrapInput,
        IList <Selectable> whiteList = null
        )
    {
        if (currentGameObject == null || !currentGameObject.activeInHierarchy)
        {
            // If no GameObject is selected, search the first Selectable GameObject in the screen
            return(null);
        }
        else
        {
            // If a GameObject is selected, check if it has a Selectable component and if it's interactable...
            Selectable currentSelectableObject = currentGameObject.GetComponent <Selectable>();
            if (currentSelectableObject == null || !currentSelectableObject.IsInteractable())
            {
                // If the selected GameObject isn't Selectable and Interactable,
                // search the first Selectable GameObject in the screen
                return(null);
            }
            else
            {
                // Otherwise, check which Navigation Mode is defined for the current Selectable Object
                // and try to find the next Selectable Object in the specified direction...
                if (currentSelectableObject.navigation.mode == Navigation.Mode.Automatic)
                {
                    //-------------------------------------------------------------------------------------------------
                    // "AUTOMATIC" Navigation Mode
                    //-------------------------------------------------------------------------------------------------
                    Selectable nextSelectableObject = UFEScreenExtensions.FindSelectable(currentSelectableObject, direction, whiteList);
                    if (nextSelectableObject != null)
                    {
                        return(nextSelectableObject);
                    }
                    else if (wrapInput)
                    {
                        // If we couldn't find any selectable GameObject but we want to wrap
                        // the input in the current screen, we search the first selectable
                        // GameObject in the opposite part of the screen.
                        Vector3 oppositeDirection = -direction;
                        nextSelectableObject = currentSelectableObject;
                        Selectable temp = UFEScreenExtensions.FindSelectable(nextSelectableObject, oppositeDirection, whiteList);

                        while (temp != null)
                        {
                            nextSelectableObject = temp;
                            temp = UFEScreenExtensions.FindSelectable(temp, oppositeDirection, whiteList);
                        }

                        return(nextSelectableObject ?? currentSelectableObject);
                    }
                    else
                    {
                        // If we couldn't find any selectable GameObject and we don't want to wrap the input
                        // in the current screen, then we return the current selectable object (if any).
                        return(currentSelectableObject);
                    }
                }
                else if (currentSelectableObject.navigation.mode == Navigation.Mode.Explicit)
                {
                    //-------------------------------------------------------------------------------------------------
                    // "EXPLICIT" Navigation Mode
                    //-------------------------------------------------------------------------------------------------
                    if (direction.x == 0f)
                    {
                        if (direction.y > 0f)
                        {
                            return(currentSelectableObject.navigation.selectOnUp);
                        }
                        else if (direction.y < 0f)
                        {
                            return(currentSelectableObject.navigation.selectOnDown);
                        }
                        else
                        {
                            return(currentSelectableObject);
                        }
                    }
                    else if (direction.x < 0f)
                    {
                        return(currentSelectableObject.navigation.selectOnLeft);
                    }
                    else if (direction.x > 0f)
                    {
                        return(currentSelectableObject.navigation.selectOnRight);
                    }
                    else
                    {
                        return(currentSelectableObject);
                    }
                }
                else if (currentSelectableObject.navigation.mode == Navigation.Mode.Horizontal)
                {
                    //-------------------------------------------------------------------------------------------------
                    // "HORIZONTAL" Navigation Mode
                    //-------------------------------------------------------------------------------------------------
                    Vector3           currentSelectablePosition = currentSelectableObject.transform.position;
                    List <Selectable> selectables = Selectable.allSelectables;
                    Selectable        first       = null;
                    Selectable        last        = null;
                    Selectable        previous    = null;
                    Selectable        next        = null;

                    for (int i = 0; i < selectables.Count; ++i)
                    {
                        Selectable current = selectables[i];

                        if (current != null && (whiteList == null || whiteList.Count == 0 || whiteList.Contains(current)))
                        {
                            Transform currentTransform = current.transform;

                            if (
                                first == null
                                ||
                                currentTransform.position.x < first.transform.position.x
                                ||
                                currentTransform.position.x == first.transform.position.x &&
                                currentTransform.position.y > first.transform.position.y
                                )
                            {
                                first = current;
                            }

                            if (
                                last == null
                                ||
                                currentTransform.position.x > last.transform.position.x
                                ||
                                currentTransform.position.x == last.transform.position.x &&
                                currentTransform.position.y < last.transform.position.y
                                )
                            {
                                last = current;
                            }

                            if (
                                (
                                    previous == null
                                    ||
                                    currentTransform.position.x > previous.transform.position.x
                                    ||
                                    currentTransform.position.x == previous.transform.position.x &&
                                    currentTransform.position.y < previous.transform.position.y
                                )
                                &&
                                (
                                    currentTransform.position.x < currentSelectablePosition.x
                                    ||
                                    currentTransform.position.x == currentSelectablePosition.x &&
                                    currentTransform.position.y > currentSelectablePosition.y
                                )
                                )
                            {
                                previous = current;
                            }

                            if (
                                (
                                    next == null
                                    ||
                                    currentTransform.position.x < next.transform.position.x
                                    ||
                                    currentTransform.position.x == next.transform.position.x &&
                                    currentTransform.position.y > next.transform.position.y
                                )
                                &&
                                (
                                    currentTransform.position.x > currentSelectablePosition.x
                                    ||
                                    currentTransform.position.x == currentSelectablePosition.x &&
                                    currentTransform.position.y < currentSelectablePosition.y
                                )
                                )
                            {
                                next = current;
                            }
                        }
                    }

                    if (direction.x < 0f)
                    {
                        return(previous ?? (wrapInput ? last : currentSelectableObject));
                    }
                    else if (direction.x > 0f)
                    {
                        return(next ?? (wrapInput ? first : currentSelectableObject));
                    }
                    else
                    {
                        return(currentSelectableObject);
                    }
                }
                else if (currentSelectableObject.navigation.mode == Navigation.Mode.Vertical)
                {
                    //-------------------------------------------------------------------------------------------------
                    // "VERTICAL" Navigation Mode
                    //-------------------------------------------------------------------------------------------------
                    Vector3           currentSelectablePosition = currentSelectableObject.transform.position;
                    List <Selectable> selectables = Selectable.allSelectables;
                    Selectable        first       = null;
                    Selectable        last        = null;
                    Selectable        previous    = null;
                    Selectable        next        = null;

                    for (int i = 0; i < selectables.Count; ++i)
                    {
                        Selectable current = selectables[i];

                        if (current != null && (whiteList == null || whiteList.Count == 0 || whiteList.Contains(current)))
                        {
                            Transform currentTransform = current.transform;

                            if (
                                first == null
                                ||
                                currentTransform.position.y > first.transform.position.y
                                ||
                                currentTransform.position.y == first.transform.position.y &&
                                currentTransform.position.x < first.transform.position.x
                                )
                            {
                                first = current;
                            }

                            if (
                                last == null
                                ||
                                currentTransform.position.y < last.transform.position.y
                                ||
                                currentTransform.position.y == last.transform.position.y &&
                                currentTransform.position.x > last.transform.position.x
                                )
                            {
                                last = current;
                            }

                            if (
                                (
                                    previous == null
                                    ||
                                    currentTransform.position.y < previous.transform.position.y
                                    ||
                                    currentTransform.position.y == previous.transform.position.y &&
                                    currentTransform.position.x > previous.transform.position.x
                                )
                                &&
                                (
                                    currentTransform.position.y > currentSelectablePosition.y
                                    ||
                                    currentTransform.position.y == currentSelectablePosition.y &&
                                    currentTransform.position.x < currentSelectablePosition.x
                                )
                                )
                            {
                                previous = current;
                            }

                            if (
                                (
                                    next == null
                                    ||
                                    currentTransform.position.y > next.transform.position.y
                                    ||
                                    currentTransform.position.y == next.transform.position.y &&
                                    currentTransform.position.x < next.transform.position.x
                                )
                                &&
                                (
                                    currentTransform.position.y < currentSelectablePosition.y
                                    ||
                                    currentTransform.position.y == currentSelectablePosition.y &&
                                    currentTransform.position.x > currentSelectablePosition.x
                                )
                                )
                            {
                                next = current;
                            }
                        }
                    }

                    if (direction.y < 0f)
                    {
                        return(next ?? (wrapInput ? first : currentSelectableObject));
                    }
                    else if (direction.y > 0f)
                    {
                        return(previous ?? (wrapInput ? last : currentSelectableObject));
                    }
                    else
                    {
                        return(currentSelectableObject);
                    }
                }
                else
                {
                    //-------------------------------------------------------------------------------------------------
                    // "NONE" Navigation Mode
                    //-------------------------------------------------------------------------------------------------
                    return(currentSelectableObject);
                }
            }
        }
    }