Exemplo n.º 1
0
        protected virtual void ProcessDrag(Pointer3DEventData pointerEvent)
        {
            if (!pointerEvent.IsPointerMoving() ||
                Cursor.lockState == CursorLockMode.Locked ||
                pointerEvent.pointerDrag == null)
            {
                return;
            }

            if (!pointerEvent.dragging &&
                ShouldStartDrag(pointerEvent, dragThreshold))
            {
                ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.beginDragHandler);
                pointerEvent.dragging = true;
            }

            // Drag notification
            if (pointerEvent.dragging)
            {
                // Before doing drag we should cancel any pointer down state
                // And clear selection!
                if (pointerEvent.pointerPress != pointerEvent.pointerDrag)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);

                    pointerEvent.eligibleForClick = false;
                    pointerEvent.pointerPress     = null;
                    pointerEvent.rawPointerPress  = null;
                }
                ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler);
            }
        }
Exemplo n.º 2
0
 protected void CopyFromTo(Pointer3DEventData @from, Pointer3DEventData @to)
 {
     @to.position              = @from.position;
     @to.delta                 = @from.delta;
     @to.worldDelta            = @from.worldDelta;
     @to.scrollDelta           = @from.scrollDelta;
     @to.pointerCurrentRaycast = @from.pointerCurrentRaycast;
     @to.pointerEnter          = @from.pointerEnter;
 }
Exemplo n.º 3
0
 protected bool GetPointerData(int id, out Pointer3DEventData data, bool create)
 {
     if (!mPointerData.TryGetValue(id, out data) && create)
     {
         data = new Pointer3DEventData(eventSystem)
         {
             pointerId = id,
         };
         mPointerData.Add(id, data);
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
        protected virtual void ProcessMove(Pointer3DEventData pointerEvent)
        {
            var lastPointerEnter = pointerEvent.pointerEnter;

            var targetGO = (Cursor.lockState == CursorLockMode.Locked ? null : pointerEvent.pointerCurrentRaycast.gameObject);

            HandlePointerExitAndEnter(pointerEvent, targetGO);

            if (pointerEvent.pointerEnter != lastPointerEnter)
            {
                if (enterChangedCallback != null)
                {
                    enterChangedCallback(pointerEvent, lastPointerEnter);
                }
            }
        }
Exemplo n.º 5
0
        private static bool ShouldStartDrag(Pointer3DEventData ptr, float threshold)
        {
            if (!ptr.useDragThreshold)
            {
                return(true);
            }

            if (ptr.canvas)
            {
                return((ptr.pressPosition - ptr.position).sqrMagnitude >= threshold * threshold);
            }

            if (ptr.pointerPressRaycast.gameObject && ptr.pointerCurrentRaycast.gameObject)
            {
                return((ptr.pointerPressRaycast.worldPosition - ptr.pointerCurrentRaycast.worldPosition).sqrMagnitude >= threshold * threshold);
            }

            return(false);
        }
Exemplo n.º 6
0
 protected void RemovePointerData(Pointer3DEventData data)
 {
     mPointerData.Remove(data.pointerId);
 }
Exemplo n.º 7
0
        protected void ProcessPress(Pointer3DEventData 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)
                {
                    var lastPointerEnter = pointerEvent.pointerEnter;

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

                    if (enterChangedCallback != null)
                    {
                        enterChangedCallback(pointerEvent, lastPointerEnter);
                    }
                }

                // 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: " + pointerEvent.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;

                // 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)
                {
                    var lastPointerEnter = pointerEvent.pointerEnter;

                    HandlePointerExitAndEnter(pointerEvent, null);
                    HandlePointerExitAndEnter(pointerEvent, currentOverGo);

                    if (pointerEvent.pointerEnter != lastPointerEnter)
                    {
                        if (enterChangedCallback != null)
                        {
                            enterChangedCallback(pointerEvent, lastPointerEnter);
                        }
                    }
                }
            }
        }