/// <summary> /// Process keyboard events. /// </summary> protected bool SendMoveEventToSelectedObject(NavigationInput input) { float time = Time.unscaledTime; Vector2 movement = input.MovementDelta; if (Mathf.Approximately(movement.x, 0f) && Mathf.Approximately(movement.y, 0f)) { m_ConsecutiveMoveCount = 0; return(false); } // If user pressed key again, always allow event //bool allow = Input.GetButtonDown(m_HorizontalAxis) || Input.GetButtonDown(m_VerticalAxis); bool allow = false; bool similarDir = (Vector2.Dot(movement, m_LastMoveVector) > 0); if (!allow) { // Otherwise, user held down key or axis. // If direction didn't change at least 90 degrees, wait for delay before allowing consequtive event. if (similarDir && m_ConsecutiveMoveCount == 1) { allow = (time > m_PrevActionTime + m_RepeatDelay); } // If direction changed at least 90 degree, or we already had the delay, repeat at repeat rate. else { allow = (time > m_PrevActionTime + 1f / m_InputActionsPerSecond); } } if (!allow) { return(false); } // Debug.Log(m_ProcessingEvent.rawType + " axis:" + m_AllowAxisEvents + " value:" + "(" + x + "," + y + ")"); var axisEventData = GetAxisEventData(movement.x, movement.y, 0.6f); ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler); if (!similarDir) { m_ConsecutiveMoveCount = 0; } m_ConsecutiveMoveCount++; m_PrevActionTime = time; m_LastMoveVector = movement; return(axisEventData.used); }
/// <summary> /// Process submit keys. /// </summary> protected bool SendSubmitEventToSelectedObject(NavigationInput input) { if (eventSystem.currentSelectedGameObject == null) { return(false); } var data = GetBaseEventData(); if (input.SubmitEvent == PointerEventData.FramePressState.Pressed) { ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.submitHandler); } // if (input.CancelEvent == PointerEventData.FramePressState.Pressed) // ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.cancelHandler); return(data.used); }
public void Process(CursorInput cursorInput, NavigationInput navInput) { bool usedEvent = SendUpdateEventToSelectedObject(); if (eventSystem.sendNavigationEvents) { if (!usedEvent) { usedEvent |= SendMoveEventToSelectedObject(navInput); } if (!usedEvent) { SendSubmitEventToSelectedObject(navInput); } } ProcessMouseEvent(cursorInput); }