Exemple #1
0
 /**
  * Send an event upwards. If no target is specified, the event is sent to
  * the object itself.
  *
  * @param cb The event being sent
  * @param customTarget the event receiver, if any
  */
 protected void issueEvent <T>(ExecEv.EventFunction <T> cb,
                               GO customTarget = null) where T : Handler
 {
     if (customTarget != null)
     {
         ExecEv.ExecuteHierarchy <T>(customTarget, null, cb);
     }
     else
     {
         ExecEv.ExecuteHierarchy <T>(this.gameObject, null, cb);
     }
 }
Exemple #2
0
        private void ProcessMousePress(PointerInputModule.MouseButtonEventData data)
        {
            PointerEventData buttonData = data.buttonData;
            GameObject       gameObject = buttonData.pointerCurrentRaycast.gameObject;

            if (data.PressedThisFrame())
            {
                buttonData.eligibleForClick = true;
                buttonData.delta            = Vector2.zero;
                buttonData.dragging         = false;
                buttonData.useDragThreshold = true;
                buttonData.pressPosition    = buttonData.position;
                if (buttonData.IsVRPointer())
                {
                    buttonData.SetSwipeStart(Input.mousePosition);
                }
                buttonData.pointerPressRaycast = buttonData.pointerCurrentRaycast;
                base.DeselectIfSelectionChanged(gameObject, buttonData);
                GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject, buttonData, ExecuteEvents.pointerDownHandler);
                if (gameObject2 == null)
                {
                    gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject);
                }
                float unscaledTime = Time.unscaledTime;
                if (gameObject2 == buttonData.lastPress)
                {
                    float num = unscaledTime - buttonData.clickTime;
                    if (num < 0.3f)
                    {
                        buttonData.clickCount++;
                    }
                    else
                    {
                        buttonData.clickCount = 1;
                    }
                    buttonData.clickTime = unscaledTime;
                }
                else
                {
                    buttonData.clickCount = 1;
                }
                buttonData.pointerPress    = gameObject2;
                buttonData.rawPointerPress = gameObject;
                buttonData.clickTime       = unscaledTime;
                buttonData.pointerDrag     = ExecuteEvents.GetEventHandler <IDragHandler>(gameObject);
                if (buttonData.pointerDrag != null)
                {
                    ExecuteEvents.Execute <IInitializePotentialDragHandler>(buttonData.pointerDrag, buttonData, ExecuteEvents.initializePotentialDrag);
                }
            }
            if (data.ReleasedThisFrame())
            {
                ExecuteEvents.Execute <IPointerUpHandler>(buttonData.pointerPress, buttonData, ExecuteEvents.pointerUpHandler);
                GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject);
                if (buttonData.pointerPress == eventHandler && buttonData.eligibleForClick)
                {
                    ExecuteEvents.Execute <IPointerClickHandler>(buttonData.pointerPress, buttonData, ExecuteEvents.pointerClickHandler);
                }
                else if (buttonData.pointerDrag != null)
                {
                    ExecuteEvents.ExecuteHierarchy <IDropHandler>(gameObject, buttonData, ExecuteEvents.dropHandler);
                }
                buttonData.eligibleForClick = false;
                buttonData.pointerPress     = null;
                buttonData.rawPointerPress  = null;
                if (buttonData.pointerDrag != null && buttonData.dragging)
                {
                    ExecuteEvents.Execute <IEndDragHandler>(buttonData.pointerDrag, buttonData, ExecuteEvents.endDragHandler);
                }
                buttonData.dragging    = false;
                buttonData.pointerDrag = null;
                if (gameObject != buttonData.pointerEnter)
                {
                    base.HandlePointerExitAndEnter(buttonData, null);
                    base.HandlePointerExitAndEnter(buttonData, gameObject);
                }
            }
        }
        /// <summary>
        /// Calculate and process any mouse button state changes.
        /// </summary>
        protected void ProcessMousePress(MouseButtonEventData data)
        {
            var pointerEvent  = data.buttonData;
            var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject;

            // PointerDown notification
            if (data.PressedThisFrame())
            {
                pointerEvent.eligibleForClick    = true;
                pointerEvent.delta               = Vector2.zero;
                pointerEvent.dragging            = false;
                pointerEvent.useDragThreshold    = true;
                pointerEvent.pressPosition       = pointerEvent.position;
                pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;

                DeselectIfSelectionChanged(currentOverGo, pointerEvent);

                // search for the control that will receive the press
                // if we can't find a press handler set the press
                // handler to be what would receive a click.
                var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler);
                var newClick   = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);

                // didnt find a press handler... search for a click handler
                if (newPressed == null)
                {
                    newPressed = newClick;
                }

                // Debug.Log("Pressed: " + newPressed);

                float time = Time.unscaledTime;

                if (newPressed == pointerEvent.lastPress)
                {
                    var diffTime = time - pointerEvent.clickTime;
                    if (diffTime < 0.3f)
                    {
                        ++pointerEvent.clickCount;
                    }
                    else
                    {
                        pointerEvent.clickCount = 1;
                    }

                    pointerEvent.clickTime = time;
                }
                else
                {
                    pointerEvent.clickCount = 1;
                }

                pointerEvent.pointerPress    = newPressed;
                pointerEvent.rawPointerPress = currentOverGo;
                pointerEvent.pointerClick    = newClick;

                pointerEvent.clickTime = time;

                // Save the drag handler as well
                pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentOverGo);

                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
                }

                m_InputPointerEvent = pointerEvent;
            }

            // PointerUp notification
            if (data.ReleasedThisFrame())
            {
                ReleaseMouse(pointerEvent, currentOverGo);
            }
        }
Exemple #4
0
        private void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released)
        {
            GameObject gameObject1 = pointerEvent.pointerCurrentRaycast.gameObject;

            if (pressed)
            {
                pointerEvent.eligibleForClick    = true;
                pointerEvent.delta               = Vector2.zero;
                pointerEvent.dragging            = false;
                pointerEvent.useDragThreshold    = true;
                pointerEvent.pressPosition       = pointerEvent.position;
                pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;
                this.DeselectIfSelectionChanged(gameObject1, (BaseEventData)pointerEvent);
                if ((UnityEngine.Object)pointerEvent.pointerEnter != (UnityEngine.Object)gameObject1)
                {
                    this.HandlePointerExitAndEnter(pointerEvent, gameObject1);
                    pointerEvent.pointerEnter = gameObject1;
                }
                GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject1, (BaseEventData)pointerEvent, ExecuteEvents.pointerDownHandler);
                if ((UnityEngine.Object)gameObject2 == (UnityEngine.Object)null)
                {
                    gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1);
                }
                float unscaledTime = Time.unscaledTime;
                if ((UnityEngine.Object)gameObject2 == (UnityEngine.Object)pointerEvent.lastPress)
                {
                    if ((double)(unscaledTime - pointerEvent.clickTime) < 0.300000011920929)
                    {
                        ++pointerEvent.clickCount;
                    }
                    else
                    {
                        pointerEvent.clickCount = 1;
                    }
                    pointerEvent.clickTime = unscaledTime;
                }
                else
                {
                    pointerEvent.clickCount = 1;
                }
                pointerEvent.pointerPress    = gameObject2;
                pointerEvent.rawPointerPress = gameObject1;
                pointerEvent.clickTime       = unscaledTime;
                pointerEvent.pointerDrag     = ExecuteEvents.GetEventHandler <IDragHandler>(gameObject1);
                if ((UnityEngine.Object)pointerEvent.pointerDrag != (UnityEngine.Object)null)
                {
                    ExecuteEvents.Execute <IInitializePotentialDragHandler>(pointerEvent.pointerDrag, (BaseEventData)pointerEvent, ExecuteEvents.initializePotentialDrag);
                }
            }
            if (!released)
            {
                return;
            }
            ExecuteEvents.Execute <IPointerUpHandler>(pointerEvent.pointerPress, (BaseEventData)pointerEvent, ExecuteEvents.pointerUpHandler);
            GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1);

            if ((UnityEngine.Object)pointerEvent.pointerPress == (UnityEngine.Object)eventHandler && pointerEvent.eligibleForClick)
            {
                ExecuteEvents.Execute <IPointerClickHandler>(pointerEvent.pointerPress, (BaseEventData)pointerEvent, ExecuteEvents.pointerClickHandler);
            }
            else if ((UnityEngine.Object)pointerEvent.pointerDrag != (UnityEngine.Object)null && pointerEvent.dragging)
            {
                ExecuteEvents.ExecuteHierarchy <IDropHandler>(gameObject1, (BaseEventData)pointerEvent, ExecuteEvents.dropHandler);
            }
            pointerEvent.eligibleForClick = false;
            pointerEvent.pointerPress     = (GameObject)null;
            pointerEvent.rawPointerPress  = (GameObject)null;
            if ((UnityEngine.Object)pointerEvent.pointerDrag != (UnityEngine.Object)null && pointerEvent.dragging)
            {
                ExecuteEvents.Execute <IEndDragHandler>(pointerEvent.pointerDrag, (BaseEventData)pointerEvent, ExecuteEvents.endDragHandler);
            }
            pointerEvent.dragging    = false;
            pointerEvent.pointerDrag = (GameObject)null;
            if ((UnityEngine.Object)pointerEvent.pointerDrag != (UnityEngine.Object)null)
            {
                ExecuteEvents.Execute <IEndDragHandler>(pointerEvent.pointerDrag, (BaseEventData)pointerEvent, ExecuteEvents.endDragHandler);
            }
            pointerEvent.pointerDrag = (GameObject)null;
            ExecuteEvents.ExecuteHierarchy <IPointerExitHandler>(pointerEvent.pointerEnter, (BaseEventData)pointerEvent, ExecuteEvents.pointerExitHandler);
            pointerEvent.pointerEnter = (GameObject)null;
        }
Exemple #5
0
        /// <summary>
        /// Calculate and process any mouse button state changes.
        /// </summary>
        protected void ProcessMousePress(MouseButtonEventData data)
        {
            var pointerEvent = data.buttonData;

            float holdTime = Time.unscaledTime;
            // useRaycastObject = holdTime - lastPressedTime >= 0.5f;
            // lastPressedTime = Time.unscaledTime;

            var currentOverGo = useRaycastObject?pointerEvent.pointerCurrentRaycast.gameObject:interactableList.focusedGo;



            // PointerDown notification
            if (data.PressedThisFrame())
            {
                pointerEvent.eligibleForClick    = true;
                pointerEvent.delta               = Vector2.zero;
                pointerEvent.dragging            = false;
                pointerEvent.useDragThreshold    = true;
                pointerEvent.pressPosition       = pointerEvent.position;
                pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;

                if (useRaycastObject)
                {
                    DeselectIfSelectionChanged(currentOverGo, pointerEvent);
                }

                GameObject newPressed;
                if (useRaycastObject)
                {
                    // search for the control that will receive the press
                    // if we can't find a press handler set the press
                    // handler to be what would receive a click.
                    newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler);
                }
                else
                {
                    newPressed = ExecuteEvents.GetEventHandler <IPointerDownHandler>(currentOverGo);
                }
                // didnt find a press handler... search for a click handler
                if (newPressed == null)
                {
                    newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);
                }


                float time = Time.unscaledTime;

                if (newPressed == pointerEvent.lastPress)
                {
                    var diffTime = time - pointerEvent.clickTime;
                    if (diffTime < 0.3f)
                    {
                        ++pointerEvent.clickCount;
                    }
                    else
                    {
                        pointerEvent.clickCount = 1;
                    }

                    pointerEvent.clickTime = time;
                }
                else
                {
                    pointerEvent.clickCount = 1;
                }

                // Caso seja uma interação que o evento evento de "pressionar ocorra"
                // Tem maiores efeitos na responsividade do sistema.
                if (!useRaycastObject && pointerEvent.clickCount >= minClicks)
                {
                    ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler);
                }

                pointerEvent.pointerPress    = newPressed;
                pointerEvent.rawPointerPress = currentOverGo;

                pointerEvent.clickTime = time;

                // Save the drag handler as well
                pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentOverGo);

                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
                }

                m_InputPointerEvent = pointerEvent;
                holding             = true;
                lastPressedTime     = Time.unscaledTime;
            }
            // PointerUp notification
            if (data.ReleasedThisFrame())
            {
                holding = false;
                moving  = false;
                ReleaseMouse(pointerEvent, currentOverGo);
                dragging = false;
            }
        }
Exemple #6
0
        /// <summary>
        /// This method is called by Unity whenever a touch event is processed. Override this method with a custom implementation to process touch events yourself.
        /// </summary>
        /// <param name="pointerEvent">Event data relating to the touch event, such as position and ID to be passed to the touch event destination object.</param>
        /// <param name="pressed">This is true for the first frame of a touch event, and false thereafter. This can therefore be used to determine the instant a touch event occurred.</param>
        /// <param name="released">This is true only for the last frame of a touch event.</param>
        /// <remarks>
        /// This method can be overridden in derived classes to change how touch press events are handled.
        /// </remarks>
        protected void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released)
        {
            float holdTime = Time.unscaledTime;
            // useRaycastObject = holdTime - lastPressedTime >= 0.5f;
            // lastPressedTime = Time.unscaledTime;

            var currentOverGo = useRaycastObject?pointerEvent.pointerCurrentRaycast.gameObject:interactableList.focusedGo;

            // PointerDown notification
            if (pressed)
            {
                holding = true;
                pointerEvent.eligibleForClick    = true;
                pointerEvent.delta               = Vector2.zero;
                pointerEvent.dragging            = false;
                pointerEvent.useDragThreshold    = true;
                pointerEvent.pressPosition       = pointerEvent.position;
                pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;

                if (useRaycastObject)
                {
                    DeselectIfSelectionChanged(currentOverGo, pointerEvent);
                }

                // if (pointerEvent.pointerEnter != currentOverGo)
                // {
                //     // send a pointer enter to the touched element if it isn't the one to select...
                //     HandlePointerExitAndEnter(pointerEvent, currentOverGo);
                //     pointerEvent.pointerEnter = currentOverGo;
                // }

                GameObject newPressed;
                if (useRaycastObject)
                {
                    // search for the control that will receive the press
                    // if we can't find a press handler set the press
                    // handler to be what would receive a click.
                    newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler);
                }

                else
                {
                    newPressed = ExecuteEvents.GetEventHandler <IPointerDownHandler>(currentOverGo);
                }
                // didnt find a press handler... search for a click handler
                if (newPressed == null)
                {
                    newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);
                }


                float time = Time.unscaledTime;

                var currentPointerEvent = m_InputPointerEvent != null?m_InputPointerEvent:pointerEvent;

                if (newPressed == currentPointerEvent.lastPress)
                {
                    var diffTime = time - currentPointerEvent.clickTime;
                    if (diffTime < 0.3f)
                    {
                        pointerEvent.clickCount += currentPointerEvent.clickCount + 1;
                    }
                    else
                    {
                        pointerEvent.clickCount = 1;
                    }

                    pointerEvent.clickTime = time;
                }
                else
                {
                    pointerEvent.clickCount = 1;
                }

                // Caso seja uma interação que o evento evento de "pressionar ocorra"
                // Tem maiores efeitos na responsividade do sistema.
                if (!useRaycastObject && pointerEvent.clickCount >= minClicks)
                {
                    ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler);
                }

                pointerEvent.pointerPress    = newPressed;
                pointerEvent.rawPointerPress = currentOverGo;

                pointerEvent.clickTime = time;

                // Save the drag handler as well
                pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentOverGo);

                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
                }

                m_InputPointerEvent  = pointerEvent;
                this.lastPressedTime = Time.unscaledTime;
            }

            // PointerUp notification
            if (released)
            {
                ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);

                // see if we mouse up on the same element that we clicked on...
                var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);

                // PointerClick and Drop events
                if ((pointerEvent.pointerPress == pointerUpHandler || input.touchCount > 0) && pointerEvent.eligibleForClick)
                {
                    if (useRaycastObject)
                    {
                        ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
                    }
                    else if (input.touchCount == 1)
                    {
                        float diff = m_LastMousePosition.x - m_MousePosition.x;
                        swipe = false;
                        if (diff < -1 && !interactableList.isEmpty)
                        {
                            swipe         = true;
                            currentOverGo = interactableList.Next();
                            eventSystem.SetSelectedGameObject(currentOverGo);
                            ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, pointerDescriptionHandler);
                        }
                        else if (diff > 1 && !interactableList.isEmpty)
                        {
                            swipe         = true;
                            currentOverGo = interactableList.Previous();
                            eventSystem.SetSelectedGameObject(currentOverGo);
                            ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, pointerDescriptionHandler);
                        }
                        if (m_InputPointerEvent.clickCount >= minClicks)
                        {
                            ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
                        }
                        else if (!swipe)
                        {
                            ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, pointerDescriptionHandler);
                        }
                    }
                }
                else if (pointerEvent.pointerDrag != null && pointerEvent.dragging && input.touchCount > 1)
                {
                    ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler);
                }

                pointerEvent.eligibleForClick = false;
                pointerEvent.pointerPress     = null;
                pointerEvent.rawPointerPress  = null;

                if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }

                pointerEvent.dragging    = false;
                pointerEvent.pointerDrag = null;

                // send exit events as we need to simulate this on touch up on touch device
                ExecuteEvents.ExecuteHierarchy(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler);
                pointerEvent.pointerEnter = null;
                holding = false;
                // m_InputPointerEvent = pointerEvent;
            }
        }
Exemple #7
0
        private void ProcessPress(PointerEventData pointerEvent, bool pressed, bool released)
        {
            var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject;

            if (pressed)
            {
                pointerEvent.eligibleForClick    = true;
                pointerEvent.delta               = Vector2.zero;
                pointerEvent.dragging            = false;
                pointerEvent.useDragThreshold    = true;
                pointerEvent.pressPosition       = pointerEvent.position;
                pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;

                DeselectIfSelectionChanged(currentOverGo, pointerEvent);

                if (pointerEvent.pointerEnter != currentOverGo)
                {
                    HandlePointerExitAndEnter(pointerEvent, currentOverGo);
                    pointerEvent.pointerEnter = currentOverGo;
                }

                var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler);

                if (newPressed == null)
                {
                    newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);
                }

                float time = Time.unscaledTime;

                if (newPressed == pointerEvent.lastPress)
                {
                    var diffTime = time - pointerEvent.clickTime;
                    if (diffTime < 0.3f)
                    {
                        ++pointerEvent.clickCount;
                    }
                    else
                    {
                        pointerEvent.clickCount = 1;
                    }

                    pointerEvent.clickTime = time;
                }
                else
                {
                    pointerEvent.clickCount = 1;
                }

                pointerEvent.pointerPress    = newPressed;
                pointerEvent.rawPointerPress = currentOverGo;

                pointerEvent.clickTime = time;

                pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentOverGo);

                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
                }
            }


            if (released)
            {
                ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);
                var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);

                if (pointerEvent.pointerPress == pointerUpHandler && pointerEvent.eligibleForClick)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
                }
                else if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler);
                }

                pointerEvent.eligibleForClick = false;
                pointerEvent.pointerPress     = null;
                pointerEvent.rawPointerPress  = null;

                if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }

                pointerEvent.dragging    = false;
                pointerEvent.pointerDrag = null;

                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }

                pointerEvent.pointerDrag = null;

                ExecuteEvents.ExecuteHierarchy(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler);
                pointerEvent.pointerEnter = null;
            }
        }
        protected void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released)
        {
            var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject;

            // PointerDown notification 当前事件是新创建或 Touch phase 处于 TouchPhase.Began 阶段
            if (pressed)
            {
                //初始化当前 PointerEventData 的相关值
                pointerEvent.eligibleForClick    = true;
                pointerEvent.delta               = Vector2.zero;
                pointerEvent.dragging            = false;
                pointerEvent.useDragThreshold    = true;
                pointerEvent.pressPosition       = pointerEvent.position;
                pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;

                // 检测是否需要删除当前 EventSystem 的 Selected 对象 (比如点击了新的对象,就会删除旧的 Selected 对象,然后由当前的 press 决定新的 Selected 对象)
                DeselectIfSelectionChanged(currentOverGo, pointerEvent);

                if (pointerEvent.pointerEnter != currentOverGo)
                {
                    // send a pointer enter to the touched element if it isn't the one to select...
                    HandlePointerExitAndEnter(pointerEvent, currentOverGo);
                    pointerEvent.pointerEnter = currentOverGo;
                }

                // search for the control that will receive the press
                // if we can't find a press handler set the press
                // handler to be what would receive a click.
                // 处理 pointer down 事件
                var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler);

                // didnt find a press handler... search for a click handler
                // 若未能处理 press,接着寻找能处理 click 事件的对象
                if (newPressed == null)
                {
                    newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);
                }

                // Debug.Log("Pressed: " + newPressed);
                float time = Time.unscaledTime;

                // 得到 newPressed 对象之后,接着对 PointerEventData 相关属性赋值
                if (newPressed == pointerEvent.lastPress)
                {
                    var diffTime = time - pointerEvent.clickTime;
                    if (diffTime < 0.3f)
                    {
                        ++pointerEvent.clickCount;
                    }
                    else
                    {
                        pointerEvent.clickCount = 1;
                    }

                    pointerEvent.clickTime = time;
                }
                else
                {
                    pointerEvent.clickCount = 1;
                }

                pointerEvent.pointerPress    = newPressed;
                pointerEvent.rawPointerPress = currentOverGo;

                pointerEvent.clickTime = time;

                // Save the drag handler as well
                // 处理 ExecuteEvents.initializePotentialDrag 事件
                pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentOverGo);

                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
                }

                m_InputPointerEvent = pointerEvent;
            }

            // PointerUp notification
            if (released)
            {
                // Debug.Log("Executing pressup on: " + pointer.pointerPress);
                ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);

                // Debug.Log("KeyCode: " + pointer.eventData.keyCode);

                // see if we mouse up on the same element that we clicked on...
                var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);

                // PointerClick and Drop events
                if (pointerEvent.pointerPress == pointerUpHandler && pointerEvent.eligibleForClick)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
                }
                else if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler);
                }

                pointerEvent.eligibleForClick = false;
                pointerEvent.pointerPress     = null;
                pointerEvent.rawPointerPress  = null;

                if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }

                pointerEvent.dragging    = false;
                pointerEvent.pointerDrag = null;

                // send exit events as we need to simulate this on touch up on touch device
                ExecuteEvents.ExecuteHierarchy(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler);
                pointerEvent.pointerEnter = null;

                m_InputPointerEvent = pointerEvent;
            }
        }
Exemple #9
0
        private void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released)
        {
            GameObject gameObject = pointerEvent.pointerCurrentRaycast.gameObject;

            if (pressed)
            {
                pointerEvent.eligibleForClick    = true;
                pointerEvent.delta               = Vector2.zero;
                pointerEvent.dragging            = false;
                pointerEvent.useDragThreshold    = true;
                pointerEvent.pressPosition       = pointerEvent.position;
                pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;
                DeselectIfSelectionChanged(gameObject, pointerEvent);
                if (pointerEvent.pointerEnter != gameObject)
                {
                    HandlePointerExitAndEnter(pointerEvent, gameObject);
                    pointerEvent.pointerEnter = gameObject;
                }
                GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy(gameObject, pointerEvent, ExecuteEvents.pointerDownHandler);
                if (gameObject2 == null)
                {
                    gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject);
                }
                float unscaledTime = Time.unscaledTime;
                if (gameObject2 == pointerEvent.lastPress)
                {
                    float num = unscaledTime - pointerEvent.clickTime;
                    if (num < 0.3f)
                    {
                        pointerEvent.clickCount++;
                    }
                    else
                    {
                        pointerEvent.clickCount = 1;
                    }
                    pointerEvent.clickTime = unscaledTime;
                }
                else
                {
                    pointerEvent.clickCount = 1;
                }
                pointerEvent.pointerPress    = gameObject2;
                pointerEvent.rawPointerPress = gameObject;
                pointerEvent.clickTime       = unscaledTime;
                pointerEvent.pointerDrag     = ExecuteEvents.GetEventHandler <IDragHandler>(gameObject);
                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
                }
            }
            if (released)
            {
                ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);
                GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject);
                if (pointerEvent.pointerPress == eventHandler && pointerEvent.eligibleForClick)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
                }
                else if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.ExecuteHierarchy(gameObject, pointerEvent, ExecuteEvents.dropHandler);
                }
                pointerEvent.eligibleForClick = false;
                pointerEvent.pointerPress     = null;
                pointerEvent.rawPointerPress  = null;
                if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }
                pointerEvent.dragging    = false;
                pointerEvent.pointerDrag = null;
                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }
                pointerEvent.pointerDrag = null;
                ExecuteEvents.ExecuteHierarchy(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler);
                pointerEvent.pointerEnter = null;
            }
        }
        protected void ProcessMousePress(PointerInputModule.MouseButtonEventData data)
        {
            PointerEventData buttonData  = data.buttonData;
            GameObject       gameObject1 = buttonData.pointerCurrentRaycast.gameObject;

            if (data.PressedThisFrame())
            {
                buttonData.eligibleForClick    = true;
                buttonData.delta               = Vector2.zero;
                buttonData.dragging            = false;
                buttonData.useDragThreshold    = true;
                buttonData.pressPosition       = buttonData.position;
                buttonData.pointerPressRaycast = buttonData.pointerCurrentRaycast;
                this.DeselectIfSelectionChanged(gameObject1, (BaseEventData)buttonData);
                GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject1, (BaseEventData)buttonData, ExecuteEvents.pointerDownHandler);
                if ((UnityEngine.Object)gameObject2 == (UnityEngine.Object)null)
                {
                    gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1);
                }
                float unscaledTime = Time.unscaledTime;
                if ((UnityEngine.Object)gameObject2 == (UnityEngine.Object)buttonData.lastPress)
                {
                    if ((double)(unscaledTime - buttonData.clickTime) < 0.300000011920929)
                    {
                        ++buttonData.clickCount;
                    }
                    else
                    {
                        buttonData.clickCount = 1;
                    }
                    buttonData.clickTime = unscaledTime;
                }
                else
                {
                    buttonData.clickCount = 1;
                }
                buttonData.pointerPress    = gameObject2;
                buttonData.rawPointerPress = gameObject1;
                buttonData.clickTime       = unscaledTime;
                buttonData.pointerDrag     = ExecuteEvents.GetEventHandler <IDragHandler>(gameObject1);
                if ((UnityEngine.Object)buttonData.pointerDrag != (UnityEngine.Object)null)
                {
                    ExecuteEvents.Execute <IInitializePotentialDragHandler>(buttonData.pointerDrag, (BaseEventData)buttonData, ExecuteEvents.initializePotentialDrag);
                }
            }
            if (!data.ReleasedThisFrame())
            {
                return;
            }
            ExecuteEvents.Execute <IPointerUpHandler>(buttonData.pointerPress, (BaseEventData)buttonData, ExecuteEvents.pointerUpHandler);
            GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1);

            if ((UnityEngine.Object)buttonData.pointerPress == (UnityEngine.Object)eventHandler && buttonData.eligibleForClick)
            {
                ExecuteEvents.Execute <IPointerClickHandler>(buttonData.pointerPress, (BaseEventData)buttonData, ExecuteEvents.pointerClickHandler);
            }
            else if ((UnityEngine.Object)buttonData.pointerDrag != (UnityEngine.Object)null && buttonData.dragging)
            {
                ExecuteEvents.ExecuteHierarchy <IDropHandler>(gameObject1, (BaseEventData)buttonData, ExecuteEvents.dropHandler);
            }
            buttonData.eligibleForClick = false;
            buttonData.pointerPress     = (GameObject)null;
            buttonData.rawPointerPress  = (GameObject)null;
            if ((UnityEngine.Object)buttonData.pointerDrag != (UnityEngine.Object)null && buttonData.dragging)
            {
                ExecuteEvents.Execute <IEndDragHandler>(buttonData.pointerDrag, (BaseEventData)buttonData, ExecuteEvents.endDragHandler);
            }
            buttonData.dragging    = false;
            buttonData.pointerDrag = (GameObject)null;
            if (!((UnityEngine.Object)gameObject1 != (UnityEngine.Object)buttonData.pointerEnter))
            {
                return;
            }
            this.HandlePointerExitAndEnter(buttonData, (GameObject)null);
            this.HandlePointerExitAndEnter(buttonData, gameObject1);
        }
        protected void ProcessMousePress(PointerInputModule.MouseButtonEventData data)
        {                                                                              /*	called in ProcessMouseEvent
                                                                                        *
                                                                                        *     sets pointerPress
                                                                                        *             pointerDrag
                                                                                        *             rawPointerPress
                                                                                        *
                                                                                        *     on press this frame
                                                                                        *             call OnPointerDown
                                                                                        *             call OnInitializePotentialDrag
                                                                                        *     on release this frame
                                                                                        *             call OnPointerUp
                                                                                        *             call OnPointerClick
                                                                                        *             call OnDrop
                                                                                        *             call OnEndDrag
                                                                                        */
            PointerEventData buttonData = data.buttonData;
            GameObject       gameObject = buttonData.pointerCurrentRaycast.gameObject; /*hit object. selected*/

            if (data.PressedThisFrame())
            {
                buttonData.eligibleForClick    = true;
                buttonData.delta               = Vector2.zero;
                buttonData.dragging            = false;
                buttonData.useDragThreshold    = true;
                buttonData.pressPosition       = buttonData.position;
                buttonData.pointerPressRaycast = buttonData.pointerCurrentRaycast;
                base.DeselectIfSelectionChanged(gameObject, buttonData);
                GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject, buttonData, ExecuteEvents.pointerDownHandler); /*pressed obj*/
                if (gameObject2 == null)                                                                                                                 /*if none turns out to handle OnPointerDown*/
                {
                    gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject);
                }
                float unscaledTime = Time.unscaledTime;
                if (gameObject2 == buttonData.lastPress)
                {                /*	if gameObject2 is the lastly pressed object
                                  *     and if the pressed is registered within .3 secs after the prev one, increment clickCount
                                  *     else clickCount = 1
                                  */
                    float num = unscaledTime - buttonData.clickTime;
                    if (num < 0.3f)
                    {
                        buttonData.clickCount++;
                    }
                    else
                    {
                        buttonData.clickCount = 1;
                    }
                    buttonData.clickTime = unscaledTime;
                }
                else
                {
                    buttonData.clickCount = 1;
                }
                buttonData.pointerPress    = gameObject2;
                buttonData.rawPointerPress = gameObject;
                buttonData.clickTime       = unscaledTime;
                buttonData.pointerDrag     = ExecuteEvents.GetEventHandler <IDragHandler>(gameObject);
                if (buttonData.pointerDrag != null)
                {
                    ExecuteEvents.Execute <IInitializePotentialDragHandler>(buttonData.pointerDrag, buttonData, ExecuteEvents.initializePotentialDrag);
                }
                if (m_topPopup != null)
                {
                    RectTransform rt = m_topPopup.GetComponent <RectTransform>();
                    if (rt != null)
                    {
                        if (!RectTransformUtility.RectangleContainsScreenPoint(rt, buttonData.position))
                        {
                            print("touched outside");
                            ExecuteEvents.Execute <IPopupHideHandler>(m_topPopup, buttonData, CustomEvents.popupHideHandler);
                            m_popupStack.Remove(m_topPopup);
                            if (m_topPopup != null)
                            {
                                ExecuteEvents.Execute <IPopupFocusHandler>(m_topPopup, buttonData, CustomEvents.popupFocusHandler);
                            }
                        }
                    }
                }
            }
            if (data.ReleasedThisFrame())
            {
                ExecuteEvents.Execute <IPointerUpHandler>(buttonData.pointerPress, buttonData, ExecuteEvents.pointerUpHandler);
                GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject);
                if (buttonData.pointerPress == eventHandler && buttonData.eligibleForClick)
                {
                    ExecuteEvents.Execute <IPointerClickHandler>(buttonData.pointerPress, buttonData, ExecuteEvents.pointerClickHandler);
                }
                else if (buttonData.pointerDrag != null && buttonData.dragging)
                {
                    ExecuteEvents.ExecuteHierarchy <IDropHandler>(gameObject, buttonData, ExecuteEvents.dropHandler);
                }
                buttonData.eligibleForClick = false;
                buttonData.pointerPress     = null;
                buttonData.rawPointerPress  = null;
                if (buttonData.pointerDrag != null && buttonData.dragging)
                {
                    ExecuteEvents.Execute <IEndDragHandler>(buttonData.pointerDrag, buttonData, ExecuteEvents.endDragHandler);
                }
                buttonData.dragging    = false;
                buttonData.pointerDrag = null;
                if (gameObject != buttonData.pointerEnter)
                {
                    base.HandlePointerExitAndEnter(buttonData, null);
                    base.HandlePointerExitAndEnter(buttonData, gameObject);
                }
            }
        }
        /*	protected void ProcessDelayedPress(CustomEventData eventData){
         *              //if pointerPressed remains the same && eventData.eligibleForDelayedPress , increment timer
         *              //if timer expires
         *                      //call OnDelayedPointerDown
         *                      //make sure this does not called again until new touch
         *                              //timer is reset
         *                              //eventData.eligibleForDelayedPress = false
         *                                      //eligibleForDelayedPress is reset to true when a new touch is detected
         *      }
         */

        protected void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released)
        {        /*	called in ProcessTouchEvents
                  *     sets PointerEventData.pointerEnter
                  *     sets PointerEventData.pointerPress
                  *     sets PointerEventData.rawPointerPress
                  *     sets PointerEventData.pointerDrag
                  *
                  *     on pressed this frame
                  *             calls OnPointerDown
                  *             calls OnInitializePotentialDrag
                  *
                  *     on released this frame
                  *             call OnPointerUp
                  *             call OnPointerClick
                  *             call OnDrop
                  *             call OnEndDrag
                  *             call OnPointerExit
                  */
            GameObject gameObject = pointerEvent.pointerCurrentRaycast.gameObject;

            if (pressed)            /*this frame, new touch*/
            {
                pointerEvent.eligibleForClick    = true;
                pointerEvent.delta               = Vector2.zero;
                pointerEvent.dragging            = false;
                pointerEvent.useDragThreshold    = true;
                pointerEvent.pressPosition       = pointerEvent.position;
                pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;
                base.DeselectIfSelectionChanged(gameObject, pointerEvent);
                if (pointerEvent.pointerEnter != gameObject)
                {
                    base.HandlePointerExitAndEnter(pointerEvent, gameObject /*newEnterTarget*/);
                    pointerEvent.pointerEnter = gameObject;
                }
                /*pointerEnter == gameobject*/
                GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject, pointerEvent, ExecuteEvents.pointerDownHandler); /*gameObject2 is the one int the hierarchy that handles the event. gameObject is the starting obj*/
                if (gameObject2 == null)
                {                                                                                                                                          /*	if none of gameObjects in the hierarchy can handle OnPointerDown, then assigne gameObject2 with the one in the hierarchy that handles OnPointerClick...????
                                                                                                                                                            */
                    gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject);
                }
                float unscaledTime = Time.unscaledTime;
                if (gameObject2 == pointerEvent.lastPress)
                {                /*	if gameObject2 is the lastly pressed object
                                  *     and if the pressed is registered within .3 secs after the prev one, increment clickCount
                                  *     else clickCount = 1
                                  */
                    float num = unscaledTime - pointerEvent.clickTime;
                    if (num < 0.3f)
                    {
                        pointerEvent.clickCount++;
                    }
                    else
                    {
                        pointerEvent.clickCount = 1;
                    }
                    pointerEvent.clickTime = unscaledTime;
                }
                else                /*gameObject2 == null || != pointerEvent.lastPress*/
                {
                    pointerEvent.clickCount = 1;
                }


                pointerEvent.pointerPress    = gameObject2;             /*could be null*/
                pointerEvent.rawPointerPress = gameObject;              /*could be null...*/
                pointerEvent.clickTime       = unscaledTime;
                pointerEvent.pointerDrag     = ExecuteEvents.GetEventHandler <IDragHandler>(gameObject);

                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute <IInitializePotentialDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
                }

                if (m_topPopup != null)
                {
                    RectTransform rt = m_topPopup.GetComponent <RectTransform>();
                    if (rt != null)
                    {
                        if (!RectTransformUtility.RectangleContainsScreenPoint(rt, pointerEvent.position))
                        {
                            // print("touched outside");
                            ExecuteEvents.Execute <IPopupHideHandler>(m_topPopup, pointerEvent, CustomEvents.popupHideHandler);
                            m_popupStack.Remove(m_topPopup);
                            if (m_topPopup != null)
                            {
                                ExecuteEvents.Execute <IPopupFocusHandler>(m_topPopup, pointerEvent, CustomEvents.popupFocusHandler);
                            }
                        }
                    }
                }
            }
            if (released)            /*this frame*/
            {
                ExecuteEvents.Execute <IPointerUpHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);
                GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject);
                if (pointerEvent.pointerPress == eventHandler && pointerEvent.eligibleForClick)
                {
                    ExecuteEvents.Execute <IPointerClickHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
                }
                else if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.ExecuteHierarchy <IDropHandler>(gameObject, pointerEvent, ExecuteEvents.dropHandler);
                }
                pointerEvent.eligibleForClick = false;
                pointerEvent.pointerPress     = null;
                pointerEvent.rawPointerPress  = null;
                if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.Execute <IEndDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                    prevDelta = Vector2.zero;
                }
                pointerEvent.dragging    = false;
                pointerEvent.pointerDrag = null;
                if (pointerEvent.pointerDrag != null)                /*??*/
                {
                    ExecuteEvents.Execute <IEndDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                    prevDelta = Vector2.zero;
                }
                pointerEvent.pointerDrag = null;
                ExecuteEvents.ExecuteHierarchy <IPointerExitHandler>(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler);
                pointerEvent.pointerEnter = null;
            }
        }
Exemple #13
0
        public override void Process()
        {
            GuiHit = false;
            //ButtonUsed = false;

            // send update events if there is a selected object - this is important for InputField to receive keyboard events
            SendUpdateEventToSelectedObject();
            if (ArbitraryInput.instances != null)
            {
                foreach (ArbitraryInput pointer in ArbitraryInput.instances)
                {
                    //Check if the Pointer is Active in the heirarchy. If it isn't, turn off the cursor and continue
                    if (pointer.gameObject.activeInHierarchy == false)
                    {
                        pointer.isHittingUI = false;

                        continue;
                    }

                    UpdateCameraPosition(pointer);

                    bool hit = GetLookPointerEventData(pointer);
                    if (hit == false)
                    {
                        continue;
                    }

                    pointer.CurrentPoint = pointer.PointEvent.pointerCurrentRaycast.gameObject;

                    // handle enter and exit events (highlight)
                    base.HandlePointerExitAndEnter(pointer.PointEvent, pointer.CurrentPoint);

                    UpdateCursor(pointer, pointer.PointEvent);

                    if (pointer != null)
                    {
                        if (pointer.buttonDown)
                        {
                            ClearSelection();

                            pointer.PointEvent.pressPosition       = pointer.PointEvent.position;
                            pointer.PointEvent.pointerPressRaycast = pointer.PointEvent.pointerCurrentRaycast;
                            pointer.PointEvent.pointerPress        = null;

                            if (pointer.CurrentPoint != null)
                            {
                                pointer.CurrentPressed = pointer.CurrentPoint;

                                GameObject newPressed = ExecuteEvents.ExecuteHierarchy(pointer.CurrentPressed.gameObject, pointer.PointEvent, ExecuteEvents.pointerDownHandler);

                                if (newPressed == null)
                                {
                                    // some UI elements might only have click handler and not pointer down handler
                                    newPressed = ExecuteEvents.ExecuteHierarchy(pointer.CurrentPressed, pointer.PointEvent, ExecuteEvents.pointerClickHandler);
                                    if (newPressed != null)
                                    {
                                        pointer.CurrentPressed = newPressed;
                                    }
                                }
                                else
                                {
                                    pointer.CurrentPressed = newPressed;
                                    // we want to do click on button down at same time, unlike regular mouse processing
                                    // which does click when mouse goes up over same object it went down on
                                    // reason to do this is head tracking might be jittery and this makes it easier to click buttons
                                    ExecuteEvents.Execute(newPressed, pointer.PointEvent, ExecuteEvents.pointerClickHandler);
                                }

                                if (newPressed != null)
                                {
                                    pointer.PointEvent.pointerPress = newPressed;
                                    pointer.CurrentPressed          = newPressed;
                                    Select(pointer.CurrentPressed);
                                    //ButtonUsed = true;
                                }

                                ExecuteEvents.Execute(pointer.CurrentPressed, pointer.PointEvent, ExecuteEvents.beginDragHandler);
                                pointer.PointEvent.pointerDrag = pointer.CurrentPressed;
                                pointer.CurrentDragging        = pointer.CurrentPressed;
                            }
                        }

                        if (pointer.buttonUp)
                        {
                            if (pointer.CurrentDragging)
                            {
                                ExecuteEvents.Execute(pointer.CurrentDragging, pointer.PointEvent, ExecuteEvents.endDragHandler);

                                if (pointer.CurrentPoint != null)
                                {
                                    ExecuteEvents.ExecuteHierarchy(pointer.CurrentPoint, pointer.PointEvent, ExecuteEvents.dropHandler);
                                }
                                pointer.PointEvent.pointerDrag = null;
                                pointer.CurrentDragging        = null;
                            }
                            if (pointer.CurrentPressed)
                            {
                                ExecuteEvents.Execute(pointer.CurrentPressed, pointer.PointEvent, ExecuteEvents.pointerUpHandler);
                                pointer.PointEvent.rawPointerPress = null;
                                pointer.PointEvent.pointerPress    = null;
                                pointer.CurrentPressed             = null;
                            }
                        }

                        // drag handling
                        if (pointer.CurrentDragging != null)
                        {
                            ExecuteEvents.Execute(pointer.CurrentDragging, pointer.PointEvent, ExecuteEvents.dragHandler);
                        }
                    }
                }
            }
        }
        private void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released)
        {
            var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject;

            // PointerDown notification
            if (pressed)
            {
                pointerEvent.eligibleForClick    = true;
                pointerEvent.delta               = Vector2.zero;
                pointerEvent.dragging            = false;
                pointerEvent.useDragThreshold    = true;
                pointerEvent.pressPosition       = pointerEvent.position;
                pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;

                DeselectIfSelectionChanged(currentOverGo, pointerEvent);

                if (pointerEvent.pointerEnter != currentOverGo)
                {
                    // send a pointer enter to the touched element if it isn't the one to select...
                    HandlePointerExitAndEnter(pointerEvent, currentOverGo);
                    pointerEvent.pointerEnter = currentOverGo;
                }

                // search for the control that will receive the press
                // if we can't find a press handler set the press
                // handler to be what would receive a click.
                var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler);

                // didnt find a press handler... search for a click handler
                if (newPressed == null)
                {
                    newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);
                }

                // Debug.Log("Pressed: " + newPressed);

                float time = Time.unscaledTime;

                if (newPressed == pointerEvent.lastPress)
                {
                    var diffTime = time - pointerEvent.clickTime;
                    if (diffTime < 0.3f)
                    {
                        ++pointerEvent.clickCount;
                    }
                    else
                    {
                        pointerEvent.clickCount = 1;
                    }

                    pointerEvent.clickTime = time;
                }
                else
                {
                    pointerEvent.clickCount = 1;
                }

                pointerEvent.pointerPress    = newPressed;
                pointerEvent.rawPointerPress = currentOverGo;

                pointerEvent.clickTime = time;

                // Save the drag handler as well
                pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentOverGo);

                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
                }
            }

            // PointerUp notification
            if (released)
            {
                // Debug.Log("Executing pressup on: " + pointer.pointerPress);
                ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);

                // Debug.Log("KeyCode: " + pointer.eventData.keyCode);

                // see if we mouse up on the same element that we clicked on...
                var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);

                // PointerClick and Drop events
                if (pointerEvent.pointerPress == pointerUpHandler && pointerEvent.eligibleForClick)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
                }
                else if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler);
                }

                pointerEvent.eligibleForClick = false;
                pointerEvent.pointerPress     = null;
                pointerEvent.rawPointerPress  = null;

                if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }

                pointerEvent.dragging    = false;
                pointerEvent.pointerDrag = null;

                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }

                pointerEvent.pointerDrag = null;

                // send exit events as we need to simulate this on touch up on touch device
                ExecuteEvents.ExecuteHierarchy(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler);
                pointerEvent.pointerEnter = null;
            }
        }
        // Token: 0x0600026F RID: 623 RVA: 0x0001F4AC File Offset: 0x0001D6AC
        private void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released)
        {
            GameObject gameObject = pointerEvent.pointerCurrentRaycast.gameObject;

            if (pressed)
            {
                if (!UIHintMask.bPassThrough)
                {
                    RaycastResult?maskRay = this.MaskRay;
                    if (maskRay != null && this.MaskEvent != null && gameObject != null && gameObject.name[0] != '~')
                    {
                        return;
                    }
                }
                pointerEvent.eligibleForClick    = true;
                pointerEvent.delta               = Vector2.zero;
                pointerEvent.dragging            = false;
                pointerEvent.useDragThreshold    = true;
                pointerEvent.pressPosition       = pointerEvent.position;
                pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;
                base.DeselectIfSelectionChanged(gameObject, pointerEvent);
                if (pointerEvent.pointerEnter != gameObject)
                {
                    base.HandlePointerExitAndEnter(pointerEvent, gameObject);
                    pointerEvent.pointerEnter = gameObject;
                }
                GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject, pointerEvent, ExecuteEvents.pointerDownHandler);
                if (gameObject2 == null)
                {
                    gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject);
                }
                float unscaledTime = Time.unscaledTime;
                if (gameObject2 == pointerEvent.lastPress)
                {
                    float num = unscaledTime - pointerEvent.clickTime;
                    if (num < 0.3f)
                    {
                        pointerEvent.clickCount++;
                    }
                    else
                    {
                        pointerEvent.clickCount = 1;
                    }
                    pointerEvent.clickTime = unscaledTime;
                }
                else
                {
                    pointerEvent.clickCount = 1;
                }
                pointerEvent.pointerPress    = gameObject2;
                pointerEvent.rawPointerPress = gameObject;
                pointerEvent.clickTime       = unscaledTime;
                pointerEvent.pointerDrag     = ExecuteEvents.GetEventHandler <IDragHandler>(gameObject);
                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute <IInitializePotentialDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
                }
            }
            if (released)
            {
                RaycastResult?maskRay2 = this.MaskRay;
                if (maskRay2 != null)
                {
                    ExecuteEvents.Execute <IPointerClickHandler>(this.MaskEvent.pointerCurrentRaycast.gameObject, this.MaskEvent, ExecuteEvents.pointerClickHandler);
                    if (!UIHintMask.bPassThrough && gameObject != null && gameObject.name[0] != '~')
                    {
                        pointerEvent.eligibleForClick = false;
                        pointerEvent.pointerPress     = null;
                        pointerEvent.rawPointerPress  = null;
                        pointerEvent.dragging         = false;
                        pointerEvent.pointerDrag      = null;
                        pointerEvent.pointerEnter     = null;
                        return;
                    }
                }
                ExecuteEvents.Execute <IPointerUpHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);
                GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject);
                if (pointerEvent.pointerPress == eventHandler && pointerEvent.eligibleForClick)
                {
                    ExecuteEvents.Execute <IPointerClickHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
                }
                else if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.ExecuteHierarchy <IDropHandler>(gameObject, pointerEvent, ExecuteEvents.dropHandler);
                }
                pointerEvent.eligibleForClick = false;
                pointerEvent.pointerPress     = null;
                pointerEvent.rawPointerPress  = null;
                if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.Execute <IEndDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }
                pointerEvent.dragging    = false;
                pointerEvent.pointerDrag = null;
                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute <IEndDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }
                pointerEvent.pointerDrag = null;
                ExecuteEvents.ExecuteHierarchy <IPointerExitHandler>(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler);
                pointerEvent.pointerEnter = null;
            }
        }
        /// <summary>
        /// Process the current mouse press.
        /// </summary>
        private void ProcessMousePress(MouseButtonEventData data)
        {
            var pointerEvent  = data.buttonData;
            var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject;

            // PointerDown notification
            if (data.PressedThisFrame())
            {
                pointerEvent.eligibleForClick    = true;
                pointerEvent.delta               = Vector2.zero;
                pointerEvent.dragging            = false;
                pointerEvent.useDragThreshold    = true;
                pointerEvent.pressPosition       = pointerEvent.position;
                pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;

                DeselectIfSelectionChanged(currentOverGo, pointerEvent);

                // search for the control that will receive the press
                // if we can't find a press handler set the press
                // handler to be what would receive a click.
                var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler);

                // didnt find a press handler... search for a click handler
                if (newPressed == null)
                {
                    newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);
                }

                // Debug.Log("Pressed: " + newPressed);

                float time = Time.unscaledTime;

                if (newPressed == pointerEvent.lastPress)
                {
                    var diffTime = time - pointerEvent.clickTime;
                    if (diffTime < 0.3f)
                    {
                        ++pointerEvent.clickCount;
                    }
                    else
                    {
                        pointerEvent.clickCount = 1;
                    }

                    pointerEvent.clickTime = time;
                }
                else
                {
                    pointerEvent.clickCount = 1;
                }

                pointerEvent.pointerPress    = newPressed;
                pointerEvent.rawPointerPress = currentOverGo;

                pointerEvent.clickTime = time;

                // Save the drag handler as well
                pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentOverGo);

                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
                }
            }

            // PointerUp notification
            if (data.ReleasedThisFrame())
            {
                // Debug.Log("Executing pressup on: " + pointer.pointerPress);
                ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);

                // Debug.Log("KeyCode: " + pointer.eventData.keyCode);

                // see if we mouse up on the same element that we clicked on...
                var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);

                // PointerClick and Drop events
                if (pointerEvent.pointerPress == pointerUpHandler && pointerEvent.eligibleForClick)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
                }
                else if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler);
                }

                pointerEvent.eligibleForClick = false;
                pointerEvent.pointerPress     = null;
                pointerEvent.rawPointerPress  = null;

                if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }

                pointerEvent.dragging    = false;
                pointerEvent.pointerDrag = null;

                // redo pointer enter / exit to refresh state
                // so that if we moused over somethign that ignored it before
                // due to having pressed on something else
                // it now gets it.
                if (currentOverGo != pointerEvent.pointerEnter)
                {
                    HandlePointerExitAndEnter(pointerEvent, null);
                    HandlePointerExitAndEnter(pointerEvent, currentOverGo);
                }
            }
        }
Exemple #17
0
        private void ReleaseMouse(PointerEventData pointerEvent, GameObject currentOverGo)
        {
            ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);

            var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);

            // PointerClick and Drop events
            if ((pointerEvent.pointerPress == pointerUpHandler || !Input.GetKey(KeyCode.Space)) && pointerEvent.eligibleForClick)
            {
                if (useRaycastObject)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
                }
                else
                {
                    // Verifica se o deslize foi para esquerda ou direita
                    // TODO Testar a necessidade de uma margem de erro para evitar deslizes indesejados
                    float diff = m_LastMousePosition.x - m_MousePosition.x;

                    // Uma flag para indicar se o movimento foi de toque ou deslize
                    swipe = false;
                    // Se o valor for negativo é um deslize para esquerda, caso contrário para direita
                    // À esquerda o item anterior é selecionado, a direita o item posterior é selecionado
                    // O movimento é realizado de forma cíclica pela interface
                    if (!dragging && diff < 0 && !interactableList.isEmpty)
                    {
                        currentOverGo = interactableList.Next();
                        eventSystem.SetSelectedGameObject(currentOverGo);
                        swipe = true;
                        ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, pointerDescriptionHandler);
                    }
                    else if (!dragging && diff > 0 && !interactableList.isEmpty)
                    {
                        currentOverGo = interactableList.Previous();
                        eventSystem.SetSelectedGameObject(currentOverGo);
                        swipe = true;
                        ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, pointerDescriptionHandler);
                    }
                    // Se o minimo de clicks para interação foi realizado, permite a interação;
                    if (pointerEvent.clickCount >= minClicks)
                    {
                        ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
                        pointerEvent.clickCount = 0;
                    }
                    // Se o movimento foi de toque, executa a descrição de audio
                    else if (!swipe)
                    {
                        ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, pointerDescriptionHandler);
                    }
                }
            }
            else if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
            {
                ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler);
            }

            pointerEvent.eligibleForClick = false;
            pointerEvent.pointerPress     = null;
            pointerEvent.rawPointerPress  = null;

            if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
            {
                ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
            }

            pointerEvent.dragging    = false;
            pointerEvent.pointerDrag = null;

            // redo pointer enter / exit to refresh state
            // so that if we moused over something that ignored it before
            // due to having pressed on something else
            // it now gets it.
            if (currentOverGo != pointerEvent.pointerEnter)
            {
                HandlePointerExitAndEnter(pointerEvent, null);
                HandlePointerExitAndEnter(pointerEvent, currentOverGo);
            }

            m_InputPointerEvent = pointerEvent;
        }
Exemple #18
0
 /**
  * Send an event to the root game object (which must be manually set).
  *
  * @param cb The event being sent
  */
 protected void rootEvent <T>(ExecEv.EventFunction <T> cb) where T : Handler
 {
     ExecEv.ExecuteHierarchy <T>(root, null, cb);
 }
        private void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released)
        {
            var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject;

            // PointerDown notification
            if (pressed)
            {
                pointerEvent.eligibleForClick    = true;
                pointerEvent.delta               = Vector2.zero;
                pointerEvent.dragging            = false;
                pointerEvent.useDragThreshold    = true;
                pointerEvent.pressPosition       = pointerEvent.position;
                pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;

                DeselectIfSelectionChanged(currentOverGo, pointerEvent);

                if (pointerEvent.pointerEnter != currentOverGo)
                {
                    // send a pointer enter to the touched element if it isn't the one to select...
                    HandlePointerExitAndEnter(pointerEvent, currentOverGo);
                    pointerEvent.pointerEnter = currentOverGo;
                }

                // search for the control that will receive the press
                var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler);

                // if we can't find a press handler set the press handler to be what would receive a click
                if (newPressed == null)
                {
                    newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);
                }

                pointerEvent.pointerPress    = newPressed;
                pointerEvent.rawPointerPress = currentOverGo;

                // Save the drag handler as well
                pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentOverGo);

                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
                }
            }

            if (released)
            {
                ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);

                var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);

                if (pointerEvent.pointerPress == pointerUpHandler && pointerEvent.eligibleForClick)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
                }
                else if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler);
                }

                pointerEvent.eligibleForClick = false;
                pointerEvent.pointerPress     = null;
                pointerEvent.rawPointerPress  = null;

                if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }

                pointerEvent.dragging    = false;
                pointerEvent.pointerDrag = null;

                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }

                pointerEvent.pointerDrag = null;

                ExecuteEvents.ExecuteHierarchy(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler);
                pointerEvent.pointerEnter = null;
            }
        }