예제 #1
0
 internal TapInput(ActiveGesture gesture) : this()
 {
     PressPosition   = gesture.StartPosition;
     ReleasePosition = gesture.EndPosition;
     TapDuration     = gesture.EndTime - gesture.StartTime;
     TapDrift        = gesture.TravelDistance;
     TimeStamp       = gesture.EndTime;
 }
예제 #2
0
        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);

#if UNITY_EDITOR
            DebugInfo(newGesture);
#endif
            var swipeInput = new SwipeInput(newGesture);
            Pressed?.Invoke(swipeInput);
            onPressed?.Invoke(swipeInput);
        }
예제 #3
0
        /// <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);
            }
        }
예제 #4
0
        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("Direction: {0}", (gesture.EndPosition - gesture.StartPosition).normalized);
            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 = builder.ToString();
            // if (_camera)
            // {
            //     var worldStart = _camera.ScreenToWorldPoint(gesture.StartPosition);
            //     var worldEnd = _camera.ScreenToWorldPoint(gesture.EndPosition);

            //     worldStart.z += 5;
            //     worldEnd.z += 5;
            // }
        }
예제 #5
0
 /// <summary>
 /// Checks whether a given active gesture will be a valid tap.
 /// </summary>
 private bool IsValidTap(ref ActiveGesture gesture)
 {
     return(gesture.TravelDistance <= maxTapDrift &&
            (gesture.StartTime - gesture.EndTime) <= maxTapDuration);
 }
예제 #6
0
 /// <summary>
 /// Checks whether a given active gesture will be a valid swipe.
 /// </summary>
 private bool IsValidSwipe(ref ActiveGesture gesture)
 {
     return(gesture.TravelDistance >= minSwipeDistance &&
            (gesture.StartTime - gesture.EndTime) <= maxSwipeDuration &&
            gesture.SwipeDirectionSameness >= swipeDirectionSamenessThreshold);
 }