/// <summary> /// Invoke the long-pressed event. /// </summary> /// <param name="sender">The sender.</param> internal void InvokeLongPressed(View sender) { LongPressed?.Invoke(sender, null); if (Command is ICommand cmd && cmd.CanExecute(CommandParameter)) { cmd.Execute(CommandParameter); } }
private void CheckLongPress() { if (Input.touchCount > 0) { var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { _touchStarted = true; _startTouchPosition = touch.position; _startTouchTime = Time.unscaledTime; } if (touch.phase == TouchPhase.Ended) { _touchStarted = false; Clicked?.Invoke(touch.position); } if (touch.phase == TouchPhase.Ended && _touchStarted) { _touchStarted = false; Vector2 deltaPos = touch.position - _startTouchPosition; float deltaTime = Time.unscaledTime - _startTouchTime; bool isLongPressOffset = deltaPos.sqrMagnitude < Constants.LongPressOffsetTreshhold * Constants.LongPressOffsetTreshhold; bool isLongPressTime = deltaTime <Constants.LongPressMaxTime && deltaTime> Constants.LongPressMinTime; if (isLongPressOffset && isLongPressTime) { Debug.Log("LongPress detected"); LongPressed?.Invoke(touch.position); } } if (touch.phase == TouchPhase.Canceled) { _touchStarted = false; } } }
internal void SendLongPressed() { LongPressed?.Invoke(this, EventArgs.Empty); }