internal TapInput(ActiveGesture gesture) : this() { PressPosition = gesture.StartPosition; ReleasePosition = gesture.EndPosition; TapDuration = gesture.EndTime - gesture.StartTime; TapDrift = gesture.TravelDistance; TimeStamp = gesture.EndTime; }
private void OnPressed(PointerInput input, double time) { Debug.Assert(!activeGestures.ContainsKey(input.InputId)); var newGesture = new ActiveGesture(input.InputId, input.Position, time); activeGestures.Add(input.InputId, newGesture); DebugInfo(newGesture); Pressed?.Invoke(new SwipeInput(newGesture)); }
/// <summary> /// Construct a new swipe input from a given gesture. /// </summary> internal SwipeInput(ActiveGesture gesture) : this() { InputId = gesture.InputId; StartPosition = gesture.StartPosition; PreviousPosition = gesture.PreviousPosition; EndPosition = gesture.EndPosition; SwipeDirection = (EndPosition - StartPosition).normalized; SwipeDuration = gesture.EndTime - gesture.StartTime; TravelDistance = gesture.TravelDistance; SwipeSameness = gesture.SwipeDirectionSameness; if (SwipeDuration > 0.0f) { SwipeVelocity = (float)(TravelDistance / SwipeDuration); } }
private void DebugInfo(ActiveGesture gesture) { if (label == null) { return; } var builder = new StringBuilder(); builder.AppendFormat("ID: {0}", gesture.InputId); builder.AppendLine(); builder.AppendFormat("Start Position: {0}", gesture.StartPosition); builder.AppendLine(); builder.AppendFormat("Position: {0}", gesture.EndPosition); builder.AppendLine(); builder.AppendFormat("Duration: {0}", gesture.EndTime - gesture.StartTime); builder.AppendLine(); builder.AppendFormat("Sameness: {0}", gesture.SwipeDirectionSameness); builder.AppendLine(); builder.AppendFormat("Travel distance: {0}", gesture.TravelDistance); builder.AppendLine(); builder.AppendFormat("Samples: {0}", gesture.Samples); builder.AppendLine(); builder.AppendFormat("Realtime since startup: {0}", Time.realtimeSinceStartup); builder.AppendLine(); builder.AppendFormat("Starting Timestamp: {0}", gesture.StartTime); builder.AppendLine(); builder.AppendFormat("Ending Timestamp: {0}", gesture.EndTime); builder.AppendLine(); label.text = builder.ToString(); var worldStart = Camera.main.ScreenToWorldPoint(gesture.StartPosition); var worldEnd = Camera.main.ScreenToWorldPoint(gesture.EndPosition); worldStart.z += 5; worldEnd.z += 5; }
/// <summary> /// Checks whether a given active gesture will be a valid tap. /// </summary> private bool IsValidTap(ref ActiveGesture gesture) { return(gesture.TravelDistance <= maxTapDrift && (gesture.EndTime - gesture.StartTime) <= maxTapDuration); }
/// <summary> /// Checks whether a given active gesture will be a valid swipe. /// </summary> private bool IsValidSwipe(ref ActiveGesture gesture) { return(gesture.TravelDistance >= minSwipeDistance && (gesture.EndTime - gesture.StartTime) <= maxSwipeDuration && gesture.SwipeDirectionSameness >= swipeDirectionSamenessThreshold); }