Esempio n. 1
0
 public void PointerEnter(Vector3 pointerPosition)
 {
     if (pointerEnter != null)
     {
         pointerEnter.OnPointerEnter(new PointerEventData(EventSystem.current)
         {
             position = Camera.main.WorldToScreenPoint(pointerPosition)
         });
     }
 }
Esempio n. 2
0
    private void OnPointerIn(object sender, PointerEventArgs e)
    {
        IPointerEnterHandler pointerEnterHandler = e.target.GetComponent <IPointerEnterHandler>();

        if (pointerEnterHandler == null)
        {
            return;
        }

        pointerEnterHandler.OnPointerEnter(new PointerEventData(EventSystem.current));
    }
Esempio n. 3
0
        private void OnPointerIn(object sender, PointerEventArgs e)
        {
            IPointerEnterHandler pointerEnterHandler = e.target.GetComponent <IPointerEnterHandler>();

            if (pointerEnterHandler == null)
            {
                return;
            }
            PointerEventData myData = new PointerEventData(EventSystem.current)
            {
                worldPosition = e.position,
            };

            pointerEnterHandler.OnPointerEnter(myData);
        }
Esempio n. 4
0
    void OnPointerEnter(object sender, PointerEventArgs e)
    {
        IPointerEnterHandler enter = e.target.GetComponent <IPointerEnterHandler>();

        if (enter == null)
        {
            return;
        }

        enter.OnPointerEnter(new PointerEventData(EventSystem.current));

        /*
         * ExecuteEvents.Execute(e.target.gameObject
         *                  , new PointerEventData(EventSystem.current)
         *                  , ExecuteEvents.pointerEnterHandler);
         */
    }
Esempio n. 5
0
        //레이저 포인터가 들어갔을 경우
        void OnPointerEnter(object sender, PointerEventArgs e)
        {
            IPointerEnterHandler enterHandler = e.target.GetComponent <IPointerEnterHandler>();

            if (enterHandler == null)
            {
                return;
            }

            enterHandler.OnPointerEnter(new PointerEventData(EventSystem.current));

            // UI 인터렉션 사운드
            if (GameObject.FindWithTag("UI"))
            {
                audioSource.PlayOneShot(EffectSound);
            }
        }
    public static int OnPointerEnter(IntPtr l)
    {
        int result;

        try
        {
            IPointerEnterHandler pointerEnterHandler = (IPointerEnterHandler)LuaObject.checkSelf(l);
            PointerEventData     eventData;
            LuaObject.checkType <PointerEventData>(l, 2, out eventData);
            pointerEnterHandler.OnPointerEnter(eventData);
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Esempio n. 7
0
 private static void Execute(IPointerEnterHandler handler, BaseEventData eventData)
 {
     handler.OnPointerEnter(ValidateEventData <PointerEventData>(eventData));
 }
Esempio n. 8
0
        /// <summary>
        /// 渲染当前添加的所有元素,在OnGUI进行调用,默认自动进行调用
        /// </summary>
        public void OnGUI()
        {
            Event evt = Event.current;


            if (evt.type == EventType.KeyDown && evt.control && evt.keyCode == KeyCode.R)
            {
                AssetDatabase.Refresh();
                evt.Use();
            }

            //先进行渲染
            if (evt.type == EventType.Repaint)
            {
                foreach (var VARIABLE in _rootElements)
                {
                    VARIABLE.Draw();
                }
            }

            //实现局部事件
            {
                Vector2 mousePos = evt.mousePosition;

                //Drag
                if (_pointerDragIndex != -1 && mousePos != _lastDragMousePosition)
                {
                    IPointerDragHandler drag = _uiElements[_pointerDragIndex] as IPointerDragHandler;
                    if (drag != null)
                    {
                        drag.OnDrag(mousePos - _lastDragMousePosition, mousePos);
                        _lastDragMousePosition = mousePos;
                        _refreshWindow         = true;
                    }
                }


                //PointerExit
                if (_pointerEnterIndex != -1)
                {
                    if (_uiElements.Count <= _pointerEnterIndex)
                    {
                        _pointerEnterIndex = -1;
                    }
                    else
                    {
                        IOverlapPoint ip = _uiElements[_pointerEnterIndex] as IOverlapPoint;
                        if (ip != null && !ip.OverlapPoint(mousePos, evt))
                        {
                            IPointerExitHandler ie = ip as IPointerExitHandler;
                            ie?.OnPointerExit();
                            _pointerEnterIndex = -1;
                        }
                    }
                }

                //PointerClickExit
                if (_pointerClickEnterIndex != -1)
                {
                    if (_uiElements.Count <= _pointerClickEnterIndex)
                    {
                        _pointerClickEnterIndex = -1;
                    }
                    else
                    {
                        IOverlapPoint ip = _uiElements[_pointerClickEnterIndex] as IOverlapPoint;
                        if (ip != null && !ip.OverlapPoint(mousePos, evt))
                        {
                            _pointerClickEnterIndex = -1;
                        }
                    }
                }

                //PointerEnter
                for (int i = _uiElements.Count - 1; i >= 0; i--)
                {
                    IPointerEnterHandler id = _uiElements[i] as IPointerEnterHandler;
                    if (id != null && id.OverlapPoint(mousePos, evt))
                    {
                        if (_pointerEnterIndex == -1 || _pointerEnterIndex < i)
                        {
                            if (_pointerEnterIndex != -1)
                            {
                                IPointerExitHandler ie = _uiElements[_pointerEnterIndex] as IPointerExitHandler;
                                ie?.OnPointerExit();
                            }

                            _pointerEnterIndex = i;
                            id.OnPointerEnter();
                            break;
                        }
                    }
                }

                //PointerClickEnter
                for (int i = _uiElements.Count - 1; i >= 0; i--)
                {
                    IPointerClickHandler id = _uiElements[i] as IPointerClickHandler;
                    if (id != null && id.OverlapPoint(mousePos, evt))
                    {
                        if (_pointerClickEnterIndex == -1 || _pointerClickEnterIndex < i)
                        {
                            _pointerClickEnterIndex = i;
                            break;
                        }
                    }
                }
            }

            //处理鼠标按下
            if (evt.type == EventType.MouseDown)
            {
                Vector2 mousePos = evt.mousePosition;

                bool hasFocus = false;
                //PointerDown
                for (int i = _uiElements.Count - 1; i >= 0; i--)
                {
                    UIElement     ui = _uiElements[i];
                    IOverlapPoint ip = ui as IOverlapPoint;

                    if (ip.OverlapPoint(mousePos, evt))
                    {
                        hasFocus = true;
                        IFocus focus = ui as IFocus;

                        IPointerDownHandler down = ui as IPointerDownHandler;

                        IPointerDragHandler drag = ui as IPointerDragHandler;

                        //Focus
                        if (focus != null)
                        {
                            //向上查找所有父亲
                            UIElement parent = ui;
                            while (parent != null)
                            {
                                focus = parent as IFocus;
                                if (focus != null)
                                {
                                    _focusElementsCur.Add(focus);
                                }

                                parent = parent.Parent;
                            }

                            //取消之前的
                            for (int i2 = _focusElements.Count - 1; i2 >= 0; i2--)
                            {
                                if (!_focusElementsCur.Contains(_focusElements[i2]))
                                {
                                    _focusElements[i2].Focus = false;
                                }
                            }


                            //聚焦现在的,从父亲到孩子
                            for (int i2 = _focusElementsCur.Count - 1; i2 >= 0; i2--)
                            {
                                _focusElementsCur[i2].Focus = true;
                            }

                            //交换之前与现在的列表,并清除现在
                            List <IFocus> temp = _focusElements;
                            _focusElements    = _focusElementsCur;
                            _focusElementsCur = temp;
                            _focusElementsCur.Clear();

                            if (down == null && drag == null)
                            {
                                break;
                            }
                        }

                        if (drag != null && _pointerDragIndex == -1 && evt.button == 0)
                        {
                            _pointerDragIndex = i;
                            drag.OnStartDrag(mousePos);

                            _lastDragMousePosition = mousePos;

                            if (down == null)
                            {
                                break;
                            }
                        }

                        if (down != null)
                        {
                            //PointerDown
                            down.OnPointerDown(mousePos, evt.shift, evt.control, evt.alt);
                            break;
                        }
                    }
                }


                //PointerClickDown
                for (int i = _uiElements.Count - 1; i >= 0; i--)
                {
                    IPointerClickHandler id = _uiElements[i] as IPointerClickHandler;
                    if (id != null && id.OverlapPoint(mousePos, evt) && _pointerClickPressIndex == -1)
                    {
                        _pointerClickPressButton = evt.button;
                        _pointerClickPressIndex  = i;
                        break;
                    }
                }

                //处理空白区域点击取消Focus
                if (!hasFocus)
                {
                    //取消焦点
                    for (int i2 = _focusElements.Count - 1; i2 >= 0; i2--)
                    {
                        _focusElements[i2].Focus = false;
                    }

                    _focusElements.Clear();
                }

                _refreshWindow = true;
            }

            //处理鼠标抬起
            if (evt.type == EventType.MouseUp || evt.type == EventType.MouseLeaveWindow)
            {
                Vector2 mousePos = evt.mousePosition;

                if (evt.button == 0)
                {
                    if (_pointerDragIndex != -1)
                    {
                        if (_uiElements[_pointerDragIndex] is IPointerDragHandler drag)
                        {
                            drag.OnDragEnd(mousePos);
                        }

                        _pointerDragIndex = -1;
                    }
                }

                //PointerUp
                for (int i = _uiElements.Count - 1; i >= 0; i--)
                {
                    IPointerUpHandler id = _uiElements[i] as IPointerUpHandler;
                    if (id != null && id.OverlapPoint(mousePos, evt))
                    {
                        id.OnPointerUp(mousePos);
                        break;
                    }
                }

                //PointerClickUp
                if (_pointerClickPressIndex != -1)
                {
                    if (_pointerClickEnterIndex != -1)
                    {
                        IPointerClickHandler ic = _uiElements[_pointerClickPressIndex] as IPointerClickHandler;
                        if (_pointerClickPressButton == evt.button)
                        {
                            if (_pointerClickPressIndex == _pointerClickEnterIndex)
                            {
                                ic?.OnClick(mousePos);
                            }
                            else
                            {
                                ic?.OnCancelClick(mousePos);
                            }
                        }
                        else
                        {
                            ic?.OnCancelClick(mousePos);
                        }

                        _pointerClickEnterIndex = -1;
                        _pointerClickPressIndex = -1;
                    }
                    else
                    {
                        IPointerClickHandler ic = _uiElements[_pointerClickPressIndex] as IPointerClickHandler;
                        ic?.OnCancelClick(mousePos);
                        _pointerClickEnterIndex = -1;
                        _pointerClickPressIndex = -1;
                    }
                }

                _refreshWindow = true;
            }

            //处理鼠标滚轮滑动
            if (evt.type == EventType.ScrollWheel)
            {
                for (int i = _uiElements.Count - 1; i >= 0; i--)
                {
                    IScrollHandler ic = _uiElements[i] as IScrollHandler;
                    ic?.OnScroll(evt.delta.y);
                }
            }

            //处理键盘按下
            if (evt.type == EventType.KeyDown)
            {
                if (evt.character != 0)
                {
                    for (int i = _uiElements.Count - 1; i >= 0; i--)
                    {
                        ICharacterInputHandler ic = _uiElements[i] as ICharacterInputHandler;
                        ic?.OnCharacterInput(evt.character);
                    }
                }

                for (int i = _uiElements.Count - 1; i >= 0; i--)
                {
                    IKeyDownHandler ui = _uiElements[i] as IKeyDownHandler;
                    ui?.OnKeyDown(evt.keyCode, evt.shift, evt.control, evt.alt);
                }

                evt.Use();

                _refreshWindow = true;
            }

            if (evt.type == EventType.KeyUp)
            {
                for (int i = _uiElements.Count - 1; i >= 0; i--)
                {
                    IKeyUpHandler ui = _uiElements[i] as IKeyUpHandler;
                    ui?.OnKeyUp(evt.keyCode);
                }

                evt.Use();

                _refreshWindow = true;
            }


            //RefreshAllElement
            if (_hasChangedElement)
            {
                RefreshAllElementInline();
                _hasChangedElement = false;
                _refreshWindow     = true;
            }

            //鼠标移动重绘
            if (_lastMoveMousePosition != evt.mousePosition)
            {
                _refreshWindow         = true;
                _lastDragMousePosition = evt.mousePosition;
            }

            //自动重绘界面
            if (_refreshWindow)
            {
                _refreshWindow = false;
                CurEditorWindow.Repaint();
            }
        }
Esempio n. 9
0
    void OnPointerEnter(object sender, PointerEventArgs e)
    {
        IPointerEnterHandler enterHandler = e.target.GetComponent <IPointerEnterHandler>();

        enterHandler.OnPointerEnter(new PointerEventData(EventSystem.current));
    }