/// <summary> /// Process all mouse events. /// </summary> protected void ProcessMouseEvent(int id) { var mouseData = GetMousePointerEventData(id); var leftButtonData = mouseData.GetButtonState(PointerEventData.InputButton.Left).eventData; m_CurrentFocusedGameObject = leftButtonData.buttonData.pointerCurrentRaycast.gameObject; // Process the first mouse button fully ProcessMousePress(leftButtonData); ProcessMove(leftButtonData.buttonData); ProcessDrag(leftButtonData.buttonData); // Now process right / middle clicks ProcessMousePress(mouseData.GetButtonState(PointerEventData.InputButton.Right).eventData); ProcessDrag(mouseData.GetButtonState(PointerEventData.InputButton.Right).eventData.buttonData); ProcessMousePress(mouseData.GetButtonState(PointerEventData.InputButton.Middle).eventData); ProcessDrag(mouseData.GetButtonState(PointerEventData.InputButton.Middle).eventData.buttonData); if (!Mathf.Approximately(leftButtonData.buttonData.scrollDelta.sqrMagnitude, 0.0f)) { var scrollHandler = ExecuteEvents.GetEventHandler <IScrollHandler>(leftButtonData.buttonData.pointerCurrentRaycast.gameObject); ExecuteEvents.ExecuteHierarchy(scrollHandler, leftButtonData.buttonData, ExecuteEvents.scrollHandler); } }
// From BaseInputModule // walk up the tree till a common root between the last entered and the current entered is found // send exit events up to (but not inluding) the common root. Then send enter events up to // (but not including the common root). protected void HandlePointerExitAndEnter(PointerEventData currentPointerData, GameObject newEnterTarget) { // if we have no target / pointerEnter has been deleted // just send exit events to anything we are tracking // then exit if (newEnterTarget == null || currentPointerData.pointerEnter == null) { for (var i = 0; i < currentPointerData.hovered.Count; ++i) { ExecuteEvents.Execute(currentPointerData.hovered[i], currentPointerData, ExecuteEvents.pointerExitHandler); } currentPointerData.hovered.Clear(); if (newEnterTarget == null) { currentPointerData.pointerEnter = newEnterTarget; pointer.OnPointerExit(newEnterTarget); return; } } bool isTargetInteractive = currentPointerData.pointerPress != null || ExecuteEvents.GetEventHandler <IPointerClickHandler>(newEnterTarget) != null || ExecuteEvents.GetEventHandler <IDragHandler>(newEnterTarget) != null; // if we have not changed hover target if (currentPointerData.pointerEnter == newEnterTarget && newEnterTarget) { pointer.OnPointerHover(newEnterTarget, currentPointerData.pointerCurrentRaycast, isTargetInteractive); } return; GameObject commonRoot = FindCommonRoot(currentPointerData.pointerEnter, newEnterTarget); // and we already an entered object from last time if (currentPointerData.pointerEnter != null) { // send exit handler call to all elements in the chain // until we reach the new target, or null! Transform t = currentPointerData.pointerEnter.transform; while (t != null) { // if we reach the common root break out! if (commonRoot != null && commonRoot.transform == t) { break; } ExecuteEvents.Execute(t.gameObject, currentPointerData, ExecuteEvents.pointerExitHandler); pointer.OnPointerExit(newEnterTarget); currentPointerData.hovered.Remove(t.gameObject); t = t.parent; } } // now issue the enter call up to but not including the common root currentPointerData.pointerEnter = newEnterTarget; if (newEnterTarget != null) { Transform t = newEnterTarget.transform; while (t != null && t.gameObject != commonRoot) { pointer.OnPointerEnter(newEnterTarget, currentPointerData.pointerCurrentRaycast, isTargetInteractive); ExecuteEvents.Execute(t.gameObject, currentPointerData, ExecuteEvents.pointerEnterHandler); currentPointerData.hovered.Add(t.gameObject); t = t.parent; } } }
protected void ProcessMousePress(PointerInputModule.MouseButtonEventData data) { PointerEventData currentPointerData = data.buttonData; GameObject gameObject1 = currentPointerData.pointerCurrentRaycast.gameObject; if (data.PressedThisFrame()) { currentPointerData.eligibleForClick = true; currentPointerData.delta = Vector2.zero; currentPointerData.dragging = false; currentPointerData.useDragThreshold = true; currentPointerData.pressPosition = currentPointerData.position; currentPointerData.pointerPressRaycast = currentPointerData.pointerCurrentRaycast; this.DeselectIfSelectionChanged(gameObject1, (BaseEventData)currentPointerData); GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject1, (BaseEventData)currentPointerData, ExecuteEvents.pointerDownHandler); if ((UnityEngine.Object)gameObject2 == (UnityEngine.Object)null) { gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1); } float unscaledTime = Time.unscaledTime; if ((UnityEngine.Object)gameObject2 == (UnityEngine.Object)currentPointerData.lastPress) { if ((double)(unscaledTime - currentPointerData.clickTime) < 0.300000011920929) { ++currentPointerData.clickCount; } else { currentPointerData.clickCount = 1; } currentPointerData.clickTime = unscaledTime; } else { currentPointerData.clickCount = 1; } currentPointerData.pointerPress = gameObject2; currentPointerData.rawPointerPress = gameObject1; currentPointerData.clickTime = unscaledTime; currentPointerData.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(gameObject1); if ((UnityEngine.Object)currentPointerData.pointerDrag != (UnityEngine.Object)null) { ExecuteEvents.Execute <IInitializePotentialDragHandler>(currentPointerData.pointerDrag, (BaseEventData)currentPointerData, ExecuteEvents.initializePotentialDrag); } } if (!data.ReleasedThisFrame()) { return; } ExecuteEvents.Execute <IPointerUpHandler>(currentPointerData.pointerPress, (BaseEventData)currentPointerData, ExecuteEvents.pointerUpHandler); GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1); if ((UnityEngine.Object)currentPointerData.pointerPress == (UnityEngine.Object)eventHandler && currentPointerData.eligibleForClick) { ExecuteEvents.Execute <IPointerClickHandler>(currentPointerData.pointerPress, (BaseEventData)currentPointerData, ExecuteEvents.pointerClickHandler); } else if ((UnityEngine.Object)currentPointerData.pointerDrag != (UnityEngine.Object)null && currentPointerData.dragging) { ExecuteEvents.ExecuteHierarchy <IDropHandler>(gameObject1, (BaseEventData)currentPointerData, ExecuteEvents.dropHandler); } currentPointerData.eligibleForClick = false; currentPointerData.pointerPress = (GameObject)null; currentPointerData.rawPointerPress = (GameObject)null; if ((UnityEngine.Object)currentPointerData.pointerDrag != (UnityEngine.Object)null && currentPointerData.dragging) { ExecuteEvents.Execute <IEndDragHandler>(currentPointerData.pointerDrag, (BaseEventData)currentPointerData, ExecuteEvents.endDragHandler); } currentPointerData.dragging = false; currentPointerData.pointerDrag = (GameObject)null; if (!((UnityEngine.Object)gameObject1 != (UnityEngine.Object)currentPointerData.pointerEnter)) { return; } this.HandlePointerExitAndEnter(currentPointerData, (GameObject)null); this.HandlePointerExitAndEnter(currentPointerData, gameObject1); }
protected override void ProcessDrag(PointerEventData pointerEvent) { /* used in StandaloneInputModule.ProcessToucheEvents() and StandaloneInputModule.ProcessMouseEvent(int id) * call OnBeginDrag * call OnPointerUp, if for some reason pointerPress != pointerDrag * call OnDrag * * pointerDrag could be DragHandler, HorizontalDragHandler, or VerticalDragHandler */ if (pointerEvent.IsPointerMoving() && Cursor.lockState != CursorLockMode.Locked && !(pointerEvent.pointerDrag == null)) { if (!pointerEvent.dragging && ShouldStartDrag(pointerEvent.pressPosition, pointerEvent.position, (float)base.eventSystem.pixelDragThreshold, pointerEvent.useDragThreshold)) { ExecuteEvents.Execute <IBeginDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.beginDragHandler); pointerEvent.dragging = true; } if (pointerEvent.dragging) { // if (pointerEvent.pointerPress != pointerEvent.pointerDrag) // { // ExecuteEvents.Execute<IPointerUpHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); // pointerEvent.pointerPress = null; // pointerEvent.eligibleForClick = false; // pointerEvent.rawPointerPress = null; // } print("pointerDrag is " + pointerEvent.pointerDrag.gameObject.name); if (!ExecuteEvents.CanHandleEvent <IHorizontalDragHandler>(pointerEvent.pointerDrag) && !ExecuteEvents.CanHandleEvent <IVerticalDragHandler>(pointerEvent.pointerDrag) && ExecuteEvents.CanHandleEvent <IDragHandler>(pointerEvent.pointerDrag)) { ExecuteEvents.Execute <IDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler); } else { float thresh = (float)base.eventSystem.pixelDragThreshold; if (pointerEvent.delta.sqrMagnitude > (thresh * thresh)) { if (Mathf.Abs(Vector2.Dot(Vector2.right, pointerEvent.delta.normalized)) > Mathf.Cos(45f * Mathf.Deg2Rad)) { if (ExecuteEvents.CanHandleEvent <IHorizontalDragHandler>(pointerEvent.pointerDrag)) { ExecuteEvents.Execute <IHorizontalDragHandler>(pointerEvent.pointerDrag, pointerEvent, CustomEvents.horizontalDragHandler); } else { GameObject prevPointerDrag = pointerEvent.pointerDrag; pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IHorizontalDragHandler>(pointerEvent.pointerCurrentRaycast.gameObject); if (pointerEvent.pointerDrag != null) { // print("switch to h"); ExecuteEvents.Execute <IEndDragHandler>(prevPointerDrag, pointerEvent, ExecuteEvents.endDragHandler); ExecuteEvents.Execute <IInitializePotentialDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); ExecuteEvents.Execute <IBeginDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.beginDragHandler); ExecuteEvents.Execute <IHorizontalDragHandler>(pointerEvent.pointerDrag, pointerEvent, CustomEvents.horizontalDragHandler); } else { // print("no handler for h"); pointerEvent.pointerDrag = prevPointerDrag; ExecuteEvents.Execute <IDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler); } } } else { if (ExecuteEvents.CanHandleEvent <IVerticalDragHandler>(pointerEvent.pointerDrag)) { ExecuteEvents.Execute <IVerticalDragHandler>(pointerEvent.pointerDrag, pointerEvent, CustomEvents.verticalDragHandler); } else { GameObject prevPointerDrag = pointerEvent.pointerDrag; pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IVerticalDragHandler>(pointerEvent.pointerCurrentRaycast.gameObject); if (pointerEvent.pointerDrag != null) { // print("switch to v"); ExecuteEvents.Execute <IEndDragHandler>(prevPointerDrag, pointerEvent, ExecuteEvents.endDragHandler); ExecuteEvents.Execute <IInitializePotentialDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); ExecuteEvents.Execute <IBeginDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.beginDragHandler); ExecuteEvents.Execute <IVerticalDragHandler>(pointerEvent.pointerDrag, pointerEvent, CustomEvents.verticalDragHandler); } else { // print("no handler for v"); pointerEvent.pointerDrag = prevPointerDrag; ExecuteEvents.Execute <IDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler); } } } } else { // print("under thresh"); if (Mathf.Abs(Vector2.Dot(Vector2.right, pointerEvent.delta.normalized)) > Mathf.Cos(45f * Mathf.Deg2Rad)) { if (ExecuteEvents.CanHandleEvent <IHorizontalDragHandler>(pointerEvent.pointerDrag)) { ExecuteEvents.Execute <IHorizontalDragHandler>(pointerEvent.pointerDrag, pointerEvent, CustomEvents.horizontalDragHandler); } else { ExecuteEvents.Execute <IDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler); } } else { if (ExecuteEvents.CanHandleEvent <IVerticalDragHandler>(pointerEvent.pointerDrag)) { ExecuteEvents.Execute <IVerticalDragHandler>(pointerEvent.pointerDrag, pointerEvent, CustomEvents.verticalDragHandler); } else { ExecuteEvents.Execute <IDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler); } } } } prevDelta = pointerEvent.delta; } } }
/// <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); } } }
/// <summary> /// <para>This method is called by Unity whenever a touch event is processed. Override this method with a custom implementation to process touch events yourself.</para> /// </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> protected 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; // DeselectIfSelectionChanged(gameObject1, pointerEvent); if (pointerEvent.pointerEnter != gameObject1) { HandlePointerExitAndEnter(pointerEvent, gameObject1); pointerEvent.pointerEnter = gameObject1; } GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject1, pointerEvent, ExecuteEvents.pointerDownHandler); if (gameObject2 == null) { gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1); } float unscaledTime = Time.unscaledTime; if (gameObject2 == pointerEvent.lastPress) { if (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 (pointerEvent.pointerDrag != null) { ExecuteEvents.Execute <IInitializePotentialDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); } m_InputPointerEvent = pointerEvent; } if (!released) { return; } ExecuteEvents.Execute <IPointerUpHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1); if (pointerEvent.pointerPress == eventHandler && pointerEvent.eligibleForClick) { ExecuteEvents.Execute <IPointerClickHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler); } else if (pointerEvent.pointerDrag != null && pointerEvent.dragging) { ExecuteEvents.ExecuteHierarchy <IDropHandler>(gameObject1, 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; ExecuteEvents.ExecuteHierarchy <IPointerExitHandler>(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler); pointerEvent.pointerEnter = null; m_InputPointerEvent = pointerEvent; }
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; } }
// Executa ao liberar o botão do mouse. // O evento relacionado ao Click é executado neste momento private void ReleaseMouseButton(PointerEventData pointerEvent, GameObject currentGo) { // Realiza evento de "soltar o botão" ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentGo); // Se um click for realizado entra neste if // Em caso de um click pode ser um movimento de deslize, buscando o transido entre // Objetos interagíveis de forma cíclica // Em caso de dois clicks seguidos é uma interação if (pointerEvent.pointerPress == pointerUpHandler && pointerEvent.eligibleForClick) { // Verifica se o deslize foi para esquerda ou direita // TODO Testar a necessidade de uma margem de erro para evitar deslizes indesejados float diff = _LastMousePosition.x - _MousePosition.x; // Uma flag para indicar se o movimento foi de toque ou deslize bool 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 (diff < 0 && !interactableList.isEmpty) { currentGo = interactableList.Next(); eventSystem.SetSelectedGameObject(currentGo); swipe = true; ExecuteEvents.ExecuteHierarchy(currentGo, pointerEvent, pointerDescriptionHandler); } else if (diff > 0 && !interactableList.isEmpty) { currentGo = interactableList.Previous(); eventSystem.SetSelectedGameObject(currentGo); swipe = true; ExecuteEvents.ExecuteHierarchy(currentGo, 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(currentGo, pointerEvent, pointerDescriptionHandler); } } // Trata eventos relacionado ao arrastar else if (pointerEvent.pointerDrag != null && pointerEvent.dragging) { ExecuteEvents.ExecuteHierarchy(currentGo, pointerEvent, ExecuteEvents.dropHandler); } // Reseta variáveis do pointer pointerEvent.eligibleForClick = false; pointerEvent.pointerPress = null; pointerEvent.rawPointerPress = null; // Se necessário finaliza o movimento de arrastar if (pointerEvent.pointerDrag != null && pointerEvent.dragging) { ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler); } // reseta as variaveis do pointer 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 (currentGo != pointerEvent.pointerEnter) { HandlePointerExitAndEnter(pointerEvent, null); HandlePointerExitAndEnter(pointerEvent, currentGo); } _InputPointerEvent = pointerEvent; }
private void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released) { var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject; // pointer down 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 isnt the one to select... HandlePointerExitAndEnter(pointerEvent, currentOverGo); pointerEvent.pointerEnter = currentOverGo; } // search for the control that will receive the press // if we cant find a press handler set the press // handler to be that 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); } 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; } // 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 && pointerEvent.eligibleForClick) { ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler); // Extended By: xiaoxiao.yang if (pointerEvent.selectedObject == null || pointerEvent.selectedObject != pointerEvent.pointerPress) { pointerEvent.selectedObject = pointerEvent.pointerPress; } } pointerEvent.eligibleForClick = false; pointerEvent.pointerPress = null; pointerEvent.rawPointerPress = null; pointerEvent.dragging = false; pointerEvent.pointerDrag = null; // send exit events as we need to simulate this on touch up on touch device ExecuteEvents.ExecuteHierarchy(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerExitHandler); pointerEvent.pointerEnter = null; } }
/// <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; } }
/// <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; } }
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; }
// 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; } }
// Quando o botão é pressionado verifica se é um botão previamente pressionado // e conta o toque pra ele, desde que esteja dentro do tempo limite. // Aqui também é tratado os eventos de "pressionar" do toque, mas não o de click private void PressTouch(PointerEventData pointerEvent, GameObject currentGo) { pointerEvent.eligibleForClick = true; pointerEvent.delta = Vector2.zero; pointerEvent.dragging = false; pointerEvent.useDragThreshold = true; // A posição de pressionamento deve ser a do objeto pointerEvent.pressPosition = pointerEvent.position; if (pointerEvent.pointerEnter != currentGo) { // send a pointer enter to the touched element if it isn't the one to select... HandlePointerExitAndEnter(pointerEvent, currentGo); pointerEvent.pointerEnter = currentGo; } // 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. GameObject newPressed = ExecuteEvents.GetEventHandler <IPointerDownHandler>(currentGo); // didnt find a press handler... search for a click handler if (newPressed == null) { newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentGo); } // 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; } // Caso seja uma interação que o evento evento de "pressionar ocorra" // Tem maiores efeitos na responsividade do sistema. if (pointerEvent.clickCount >= minClicks) { ExecuteEvents.ExecuteHierarchy(currentGo, pointerEvent, ExecuteEvents.pointerDownHandler); } pointerEvent.pointerPress = newPressed; pointerEvent.rawPointerPress = currentGo; pointerEvent.clickTime = time; // Save the drag handler as well pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentGo); if (pointerEvent.pointerDrag != null) { ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); } _InputPointerEvent = pointerEvent; }
// Token: 0x06000264 RID: 612 RVA: 0x0001EF38 File Offset: 0x0001D138 private void ProcessMousePress(CusPointerInputModule.MouseButtonEventData data) { PointerEventData buttonData = data.buttonData; GameObject gameObject = buttonData.pointerCurrentRaycast.gameObject; if (data.PressedThisFrame()) { if (!UIHintMask.bPassThrough) { RaycastResult?maskRay = this.MaskRay; if (maskRay != null && gameObject != null && gameObject.name[0] != '~') { CusPointerInputModule.MouseButtonEventData eventData = this.m_MaskMouseState.GetButtonState(PointerEventData.InputButton.Left, 0).eventData; PointerEventData buttonData2 = eventData.buttonData; if (buttonData2.pointerCurrentRaycast.gameObject.activeInHierarchy) { return; } } } 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); 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()) { RaycastResult?maskRay2 = this.MaskRay; if (maskRay2 != null) { CusPointerInputModule.MouseButtonEventData eventData2 = this.m_MaskMouseState.GetButtonState(PointerEventData.InputButton.Left, 0).eventData; PointerEventData buttonData3 = eventData2.buttonData; if (buttonData3.pointerCurrentRaycast.gameObject.activeInHierarchy) { ExecuteEvents.Execute <IPointerClickHandler>(buttonData3.pointerCurrentRaycast.gameObject, buttonData3, ExecuteEvents.pointerClickHandler); if (!UIHintMask.bPassThrough && gameObject != null && gameObject.name[0] != '~') { buttonData.eligibleForClick = false; buttonData.pointerPress = null; buttonData.rawPointerPress = null; buttonData.dragging = false; buttonData.pointerDrag = null; if (gameObject != buttonData.pointerEnter) { base.HandlePointerExitAndEnter(buttonData, null); base.HandlePointerExitAndEnter(buttonData, gameObject); } return; } } } 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); } } }
private void PressMouseButton(PointerEventData pointerEvent, GameObject currentGo) { pointerEvent.eligibleForClick = true; pointerEvent.delta = Vector2.zero; pointerEvent.dragging = false; pointerEvent.useDragThreshold = true; // A posição de pressionamento deve ser a do objeto pointerEvent.pressPosition = pointerEvent.position; //pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast; //DeselectIfSelectionChanged(currentGo, 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. GameObject newPressed = ExecuteEvents.GetEventHandler <IPointerDownHandler>(currentGo); // didnt find a press handler... search for a click handler if (newPressed == null) { newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentGo); } // 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; } if (pointerEvent.clickCount >= minClicks) { ExecuteEvents.ExecuteHierarchy(currentGo, pointerEvent, ExecuteEvents.pointerDownHandler); } pointerEvent.pointerPress = newPressed; pointerEvent.rawPointerPress = currentGo; pointerEvent.clickTime = time; // Save the drag handler as well pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentGo); if (pointerEvent.pointerDrag != null) { ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); } _InputPointerEvent = pointerEvent; }
/* 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 (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); } 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; } }
protected 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; base.DeselectIfSelectionChanged(gameObject, pointerEvent); if (pointerEvent.pointerEnter != gameObject) { base.HandlePointerExitAndEnter(pointerEvent, gameObject); pointerEvent.pointerEnter = gameObject; } GameObject eventHandler = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject, pointerEvent, ExecuteEvents.pointerDownHandler); if (eventHandler == null) { eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject); } float unscaledTime = Time.unscaledTime; if (eventHandler == pointerEvent.lastPress) { float num2 = unscaledTime - pointerEvent.clickTime; if (num2 < 0.3f) { pointerEvent.clickCount++; } else { pointerEvent.clickCount = 1; } pointerEvent.clickTime = unscaledTime; } else { pointerEvent.clickCount = 1; } pointerEvent.pointerPress = eventHandler; 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) { ExecuteEvents.Execute <IPointerUpHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); GameObject obj4 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject); if ((pointerEvent.pointerPress == obj4) && 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); } 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; } }
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 (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); } } }
/// <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); } }
/// <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. /// /// 获取了点击事件数据后,紧接着会调用ProcessTouchPress,处理按下和释放 /// </remarks> protected void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released) { var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject; // PointerDown notification //初始化pointerEvent; //处理enter和exit事件,清除旧的选择对象selected,更新新的选择对象,并在HandlePointerExitAndEnter(...)中触发enter和exit的事件; //处理pointerDown的事件,这里使用的是ExecuteHierarchy,即会对从当前对象所在的树状结构中自下而上第一个可以响应该事件的对象执行该事件, // 后边讲到ExecuteEvents时还会再提到; //如果没有对象响应pointerDown,则会尝试执行click事件,也是会自下而上找一遍; //如果响应pointerDown的对象newPressed与上一帧的是同一对象,则处理连续点击的逻辑,竟然有一个写死的0.3f,然后是更新数据; //最后执行一个初始化潜在拖拽的事件; 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); } m_InputPointerEvent = pointerEvent; } // PointerUp notification //处理pointerUp的事件; //如果响应pointerUp的对象pointerUpHandler与按下对象相同且当前事件可用于点击,则执行click事件 //如果没有click事件,则判断是否有drag的对象以及当前是否是dragging,如有则执行drop事件; //更新一波数据,主要是清除; //执行endDrag并清除一些数据; //执行exit并清除一些数据; 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; } }
protected void ProcessMousePress(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; // DeselectIfSelectionChanged(gameObject1, buttonData); GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject1, buttonData, ExecuteEvents.pointerDownHandler); if (gameObject2 == null) { gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1); } float unscaledTime = Time.unscaledTime; if (gameObject2 == buttonData.lastPress) { if (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 (buttonData.pointerDrag != null) { ExecuteEvents.Execute <IInitializePotentialDragHandler>(buttonData.pointerDrag, buttonData, ExecuteEvents.initializePotentialDrag); } m_InputPointerEvent = buttonData; } if (!data.ReleasedThisFrame()) { return; } ExecuteEvents.Execute <IPointerUpHandler>(buttonData.pointerPress, buttonData, ExecuteEvents.pointerUpHandler); GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1); if (buttonData.pointerPress == eventHandler && buttonData.eligibleForClick) { ExecuteEvents.Execute <IPointerClickHandler>(buttonData.pointerPress, buttonData, ExecuteEvents.pointerClickHandler); } else if (buttonData.pointerDrag != null && buttonData.dragging) { ExecuteEvents.ExecuteHierarchy <IDropHandler>(gameObject1, 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 (gameObject1 != buttonData.pointerEnter) { HandlePointerExitAndEnter(buttonData, null); HandlePointerExitAndEnter(buttonData, gameObject1); } m_InputPointerEvent = buttonData; }
protected 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; buttonData.pointerPressRaycast = buttonData.pointerCurrentRaycast; base.DeselectIfSelectionChanged(gameObject, buttonData); GameObject eventHandler = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject, buttonData, ExecuteEvents.pointerDownHandler); if (eventHandler == null) { eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject); } float unscaledTime = Time.unscaledTime; if (eventHandler == buttonData.lastPress) { float num2 = unscaledTime - buttonData.clickTime; if (num2 < 0.3f) { buttonData.clickCount++; } else { buttonData.clickCount = 1; } buttonData.clickTime = unscaledTime; } else { buttonData.clickCount = 1; } buttonData.pointerPress = eventHandler; 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 obj4 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject); if ((buttonData.pointerPress == obj4) && 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 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); } 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; 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; m_InputPointerEvent = pointerEvent; } }
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; } }