コード例 #1
0
ファイル: WUIInteractor.cs プロジェクト: ech0array/chunx
    private void Click(RaycastResult raycastResult, Selectable selectable, PointerEventData pointerEventData)
    {
        _data.queuedClick     = false;
        _data.deltaSelectable = selectable;

        if (selectable is Button)
        {
            Button button = (Button)selectable;
            if (button.interactable)
            {
                button.onClick.Invoke();
            }
        }
        else if (selectable is TMP_InputField)
        {
            selectable.GetComponentInParent <WUI>().Edit((TMP_InputField)selectable);
        }
        else if (selectable is WUIChartable)
        {
            ((WUIChartable)selectable).Chart((raycastResult.distance * base.transform.forward) + base.transform.position);
        }
        else
        {
            selectable.OnSelect(pointerEventData);
        }
    }
コード例 #2
0
    /// <summary>
    /// 获取目标控件是否能够点击(没有呗其他控件遮挡)
    /// </summary>
    /// <param name="selectable"></param>
    /// <param name="eventSystem"></param>
    /// <returns></returns>
    static bool IsSelectableValid(Selectable selectable, EventSystem eventSystem)
    {
        var raycaster = selectable.GetComponentInParent <GraphicRaycaster>();

        if (!raycaster || !eventSystem)
        {
            return(false);
        }

        var rect             = GetSelectableRect(selectable.GetComponent <RectTransform>(), Camera.main);
        var pointerEventData = new PointerEventData(eventSystem);

        pointerEventData.position = rect.center;

        var results = new List <RaycastResult>();

        raycaster.Raycast(pointerEventData, results);

        foreach (var result in results)
        {
            if (result.gameObject == selectable.gameObject)
            {
                return(true);
            }
        }
        return(false);
    }
コード例 #3
0
        bool isOnScreen(Selectable selectable)
        {
            Canvas canvas = selectable.GetComponentInParent <Canvas>();

            if (canvas == null)
            {
                return(false);
            }

            return(canvas.renderMode != RenderMode.WorldSpace);
        }
コード例 #4
0
        Selectable FindNextSelectable(Selectable selectable, TabDirection direction)
        {
            int           columnIndex = -1, rowIndex = -1;
            CellContainer cellContainer = selectable.GetComponentInParent <CellContainer>();

            for (int i = 0; i < tableColumns.Count; i++)
            {
                int row = tableColumns[i].IndexOf(cellContainer);
                if (row >= 0)
                {
                    columnIndex = i;
                    rowIndex    = row;
                    break;
                }
            }
            if (columnIndex < 0 || rowIndex < 0)
            {
                return(null);
            }
            if (direction == TabDirection.Forward)
            {
                for (int i = rowIndex; i < ElementCount; i++)
                {
                    int startIndex = (i == rowIndex) ? columnIndex + 1 : 0;
                    for (int j = startIndex; j < tableColumns.Count; j++)
                    {
                        Selectable s = GetSelectableFromCellAt(j, i);
                        if (s != null)
                        {
                            return(s);
                        }
                    }
                }
            }
            else
            {
                for (int i = rowIndex; i >= 0; i--)
                {
                    int startIndex = (i == rowIndex) ? columnIndex - 1 : tableColumns.Count - 1;
                    for (int j = startIndex; j >= 0; j--)
                    {
                        Selectable s = GetSelectableFromCellAt(j, i);
                        if (s != null)
                        {
                            return(s);
                        }
                    }
                }
            }
            return(null);
        }
コード例 #5
0
    public static void EventTrigger(this Selectable selectable, EventTriggerType eventType, UnityAction <BaseEventData> action)
    {
        EventTrigger trigger = selectable.GetComponentInParent <EventTrigger>();

        if (trigger == null)
        {
            trigger = selectable.gameObject.AddComponent <EventTrigger>();
        }
        EventTrigger.Entry entry = new EventTrigger.Entry();
        entry.eventID = eventType;
        entry.callback.AddListener((eventData) => {
            if (selectable.interactable)
            {
                action(eventData);
            }
        });
        trigger.triggers.Add(entry);
    }
コード例 #6
0
        private void HandleTabKey(bool isNavigateBackward)
        {
            GameObject selectedObject = EventSystem.current.currentSelectedGameObject;

            if (selectedObject != null && selectedObject.activeInHierarchy)
            {
                Selectable currentSelection = selectedObject.GetComponent <Selectable>();
                if (currentSelection != null)
                {
                    if (currentSelection.GetComponentInParent <Table>() != this)
                    {
                        return;
                    }
                    Selectable nextSelection = FindNextSelectable(currentSelection, isNavigateBackward ? TabDirection.Backward: TabDirection.Forward);
                    if (nextSelection != null)
                    {
                        nextSelection.Select();
                    }
                }
            }
        }
コード例 #7
0
    // Update is called once per frame
    public override void OnServiceUpdate()
    {
        bool menuBarObjectUnderMouse = false;

        if (Globals.applicationMode != Globals.ApplicationMode.Loading && inUIBar)
        {
            // Get a list of all the objects currently under the mouse to get past the blocker
            GameObject[] currentHoveringObjects = GetObjectsUnderMouse();

            // Check if mouse is hovering over an associated object
            foreach (GameObject objectUnderPointer in currentHoveringObjects)
            {
                for (int i = 0; i < uiElements.Length; ++i)
                {
                    if ((uiElements[i] == objectUnderPointer) || objectUnderPointer.transform.parent.gameObject == uiElements[i])
                    {
                        currentElement          = i;
                        menuBarObjectUnderMouse = true;
                        break;
                    }
                }

                if (menuBarObjectUnderMouse)
                {
                    break;
                }
            }

            // Exit if not in a dropdown associated with the collected gameobjects or not hovering over an associated object
            if (!menuBarObjectUnderMouse)
            {
                currentElement = -1;
            }
            else if (prevElement != currentElement)
            {
                Dropdown            dropdown        = null;
                CustomUnityDropdown instantDropdown = null;

                // Auto-switch dropdown on hover
                if (lastShownDropdown && lastShownDropdown.gameObject != uiElements[currentElement].gameObject)
                {
                    Dropdown            lastDropdown        = lastShownDropdown.GetComponentInParent <Dropdown>();
                    CustomUnityDropdown lastInstantDropdown = lastShownDropdown.GetComponentInParent <CustomUnityDropdown>();

                    if (lastDropdown)
                    {
                        lastDropdown.Hide();
                    }

                    if (lastInstantDropdown)
                    {
                        lastInstantDropdown.Hide();
                    }
                }

                EventSystem.current.SetSelectedGameObject(uiElements[currentElement].gameObject);

                dropdown        = uiElements[currentElement].GetComponentInParent <Dropdown>();
                instantDropdown = uiElements[currentElement].GetComponentInParent <CustomUnityDropdown>();

                if (dropdown)
                {
                    dropdown.Show();
                    lastShownDropdown = dropdown;
                }

                if (instantDropdown)
                {
                    instantDropdown.Show();
                    lastShownDropdown = instantDropdown;
                }
            }
        }

        if (Input.GetMouseButtonDown(0) && !inUIBar)
        {
            GameObject[] currentHoveringObjects = GetObjectsUnderMouse();

            GameObject foundObject = null;
            // Check if mouse is hovering over an associated object
            foreach (GameObject objectUnderPointer in currentHoveringObjects)
            {
                for (int i = 0; i < uiElements.Length; ++i)
                {
                    if ((uiElements[i] == objectUnderPointer) || objectUnderPointer.transform.parent.gameObject == uiElements[i])
                    {
                        currentElement = i;
                        foundObject    = uiElements[i];
                        break;
                    }
                }

                if (foundObject)
                {
                    break;
                }
            }

            if (foundObject)
            {
                inUIBar = true;

                // Set the last shown dropdown
                Dropdown dropdown = foundObject.GetComponentInParent <Dropdown>();
                if (dropdown)
                {
                    lastShownDropdown = dropdown;
                }

                CustomUnityDropdown instantDropdown = foundObject.GetComponentInParent <CustomUnityDropdown>();
                if (instantDropdown)
                {
                    lastShownDropdown = instantDropdown;
                }
            }

            mouseUpBlock = true;
        }
        // Properly deselect dropdown
        else if (Input.GetMouseButtonUp(0) /* && (EventSystem.current.currentSelectedGameObject || !menuBarObjectUnderMouse)*/)
        {
            if (mouseUpBlock)
            {
                mouseUpBlock = false;
            }
            else
            {
                EventSystem.current.SetSelectedGameObject(null);
                inUIBar        = false;
                currentElement = -1;
            }
        }

        //Debug.Log(inUIBar);

        prevElement = currentElement;
    }