-
Notifications
You must be signed in to change notification settings - Fork 1
/
LeanTouch.cs
794 lines (651 loc) · 22.6 KB
/
LeanTouch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
namespace Lean
{
// If you add this component to your scene, then it will convert all mouse and touch data into easy to use data
[ExecuteInEditMode]
[AddComponentMenu("Lean/Touch")]
public class LeanTouch : MonoBehaviour
{
// This contains the current LeanTouch instance
public static LeanTouch Instance;
// This list contains all currently active fingers (including simulated ones)
public static List<LeanFinger> Fingers = new List<LeanFinger>();
// This list contains all currently inactive fingers (e.g. this allows for pooling and tapping)
public static List<LeanFinger> InactiveFingers = new List<LeanFinger>();
// This contains the combined screen position delta of all fingers
public static Vector2 DragDelta;
// This contains the screen position delta of a single finger (if more than one finger is pressed down, then this value will be reset to 0,0)
public static Vector2 SoloDragDelta;
// This contains the combined screen position delta of multiple fingers (if only one finger is pressed down, then this value will be reset to 0,0)
public static Vector2 MultiDragDelta;
// This contains the average screen twist delta of multiple fingers in degrees (this requires at least two fingers to be pressed down)
public static float TwistDegrees;
// This contains the average screen twist delta of multiple fingers in radians (this requires at least two fingers to be pressed down)
public static float TwistRadians;
// This contains the average screen pinch scale of multiple fingers (this requires at least two fingers to be pressed down)
public static float PinchScale = 1.0f;
// This gets fired when a finger begins touching the screen (LeanFinger = The current finger)
public static System.Action<LeanFinger> OnFingerDown;
// This gets fired every frame a finger is touching the screen (LeanFinger = The current finger)
public static System.Action<LeanFinger> OnFingerSet;
// This gets fired when a finger stops touching the screen (LeanFinger = The current finger)
public static System.Action<LeanFinger> OnFingerUp;
// This gets fired when a finger moves across the screen (LeanFinger = The current finger)
public static System.Action<LeanFinger> OnFingerDrag;
// This gets fired when a finger taps the screen (this is when a finger begins and stops touching the screen within the 'TapThreshold' time) (LeanFinger = The current finger)
public static System.Action<LeanFinger> OnFingerTap;
// This gets fired when a finger swipes the screen (this is when a finger begins and stops touching the screen within the 'TapThreshold' time, and also moves more than the 'SwipeThreshold' distance) (LeanFinger = The current finger)
public static System.Action<LeanFinger> OnFingerSwipe;
// This gets fired when a finger begins being held on the screen (this is when a finger has been set for longer than the 'HeldThreshold' time) (LeanFinger = The current finger)
public static System.Action<LeanFinger> OnFingerHeldDown;
// This gets fired when a finger is held on the screen (this is when a finger has been set for longer than the 'HeldThreshold' time) (LeanFinger = The current finger)
public static System.Action<LeanFinger> OnFingerHeldSet;
// This gets fired when a finger stops being held on the screen (this is when a finger has been set for longer than the 'HeldThreshold' time) (LeanFinger = The current finger)
public static System.Action<LeanFinger> OnFingerHeldUp;
// This gets fired when at least one finger taps the screen (int = Highest Finger Count)
public static System.Action<int> OnMultiTap;
// This gets fired when a finger moves across the screen (Vector2 = DragDelta)
public static System.Action<Vector2> OnDrag;
// This gets fired when a single finger moves across the screen (if more than one finger is pressed down, then this value will not get fired) (Vector2 = SoloDragDelta)
public static System.Action<Vector2> OnSoloDrag;
// This gets fired when a multiple fingers moves across the screen (if only one finger is pressed down, then this value will not get fired) (Vector2 = MultiDragDelta)
public static System.Action<Vector2> OnMultiDrag;
// This gets fired when a pinch gesture occurs (float = PinchScale)
public static System.Action<float> OnPinch;
// This gets fired when a twist gesture occurs (float = TwistDegrees)
public static System.Action<float> OnTwistDegrees;
// This gets fired when a twist gesture occurs (float = TwistRadians)
public static System.Action<float> OnTwistRadians;
// This allows you to set how many seconds are required between a finger down/up for a tap to be registered
public float TapThreshold = 0.5f;
// This allows you to set how many pixels of movement (relative to the ReferenceDpi) are required within the TapThreshold for a swipe to be triggered
public float SwipeThreshold = 50.0f;
// This allows you to set how many seconds a finger must be held down for it to be regarded as being held down
public float HeldThreshold = 1.0f;
// This allows you to set the default DPI you want the input scaling to be based on
public int ReferenceDpi = 200;
// This allows you to enable recording of finger movements
public bool RecordFingers = true;
// This allows you to set the amount of pixels a finger must move for another snapshot to be stored
public float RecordThreshold = 5.0f;
// This allows you to set the maximum amount of seconds that can be recorded, 0 = unlimited
public float RecordLimit;
// This allows you to simulate multi touch inputs on devices that don't support them (e.g. desktop)
public bool SimulateMultiFingers = true;
// This allows you to set which key is required to simulate multi key twisting
public KeyCode PinchTwistKey = KeyCode.LeftControl;
// This allows you to set which key is required to simulate multi key dragging
public KeyCode MultiDragKey = KeyCode.LeftAlt;
// This allows you to set which texture will be used to show the simulated fingers
public Texture2D FingerTexture;
// This stores the highest mouse button index
private static int highestMouseButton = 7;
// This stores how many fingers were touching the screen last frame
private int lastFingerCount;
// This stores how many seconds at least one finger has been touching the screen
private float multiFingerTime;
// This stores how many fingers at most were held during the multiFingerTime
private int multiFingerCount;
// If you multiply this value with any other pixel delta (e.g. DragDelta), then it will become device resolution independant
public static float ScalingFactor
{
get
{
var scalingFactor = 1.0f;
var referenceDpi = 200;
// Grab the current reference DPI, if it exists
if (Instance != null)
{
referenceDpi = Instance.ReferenceDpi;
}
// If this screen has a known DPI, scale the value based on it
if (Screen.dpi > 0 && referenceDpi > 0)
{
scalingFactor = Mathf.Sqrt(referenceDpi) / Mathf.Sqrt(Screen.dpi);
}
return scalingFactor;
}
}
// This will return the DragDelta after it's been scaled to current DPI
public static Vector2 ScaledDragDelta
{
get
{
return DragDelta * ScalingFactor;
}
}
// This will return the SoloDragDelta after it's been scaled to current DPI
public static Vector2 ScaledSoloDragDelta
{
get
{
return SoloDragDelta * ScalingFactor;
}
}
// This will return the MultiDragDelta after it's been scaled to current DPI
public static Vector2 ScaledMultiDragDelta
{
get
{
return MultiDragDelta * ScalingFactor;
}
}
// Returns true if any mouse button is pressed
public static bool AnyMouseButtonSet
{
get
{
for (var i = 0; i < highestMouseButton; i++)
{
if (Input.GetMouseButton(i) == true)
{
return true;
}
}
return false;
}
}
// This will return true if the mouse or any finger is currently using the GUI
public static bool GuiInUse
{
get
{
// Legacy GUI in use?
if (GUIUtility.hotControl > 0)
{
return true;
}
// New GUI in use?
for (var i = Fingers.Count - 1; i >= 0; i--)
{
if (Fingers[i].IsOverGui == true)
{
return true;
}
}
return false;
}
}
// The center point of all fingers, or default
public static Vector2 GetCenterOfFingers()
{
var total = Vector2.zero;
var fingerCount = Fingers.Count;
if (fingerCount > 0)
{
for (var i = 0; i < fingerCount; i++)
{
total += Fingers[i].ScreenPosition;
}
total /= fingerCount;
}
return total;
}
// The last center point of all fingers, or default
public static Vector2 GetLastCenterOfFingers()
{
var total = Vector2.zero;
var fingerCount = Fingers.Count;
if (fingerCount > 0)
{
for (var i = 0; i < fingerCount; i++)
{
total += Fingers[i].LastScreenPosition;
}
total /= fingerCount;
}
return total;
}
// This will return the average distance between all fingers and the reference point
public static float GetAverageFingerDistance(Vector2 referencePoint)
{
var total = 0.0f;
var fingerCount = Fingers.Count;
if (fingerCount > 0)
{
for (var i = 0; i < fingerCount; i++)
{
total += Fingers[i].GetDistance(referencePoint);
}
total /= fingerCount;
}
return total;
}
// This will return the last average distance between all fingers and the reference point
public static float GetLastAverageFingerDistance(Vector2 referencePoint)
{
var total = 0.0f;
var fingerCount = Fingers.Count;
if (fingerCount > 0)
{
for (var i = 0; i < fingerCount; i++)
{
total += Fingers[i].GetLastDistance(referencePoint);
}
total /= fingerCount;
}
return total;
}
// This allows you to drag an object on screen by a change in screen position
public static void MoveObject(Transform transform, Vector2 deltaPosition, Camera camera = null)
{
if (transform != null)
{
if (deltaPosition.x != 0.0f || deltaPosition.y != 0.0f)
{
var rectTransform = transform as RectTransform;
// If this is RectTransform then modify the anchoredPosition
if (rectTransform != null)
{
rectTransform.anchoredPosition += deltaPosition;
}
// If this is Transform then modify the position
else
{
transform.position = MoveObject(transform.position, deltaPosition, camera);
}
}
}
}
public static Vector3 MoveObject(Vector3 worldPosition, Vector2 deltaPosition, Camera camera = null)
{
if (camera == null) camera = Camera.main;
if (camera != null)
{
// Find current screen position of world position
var screenPosition = camera.WorldToScreenPoint(worldPosition);
// Modify screen position
screenPosition += (Vector3)deltaPosition;
// Write new world position
worldPosition = camera.ScreenToWorldPoint(screenPosition);
}
return worldPosition;
}
// This allows you to rotate an object on screen by a change in screen rotation
public static void RotateObject(Transform transform, float deltaRotation, Camera camera = null)
{
if (transform != null && deltaRotation != 0.0f)
{
transform.rotation = RotateObject(transform.rotation, deltaRotation, camera);
}
}
public static Quaternion RotateObject(Quaternion worldRotation, float deltaRotation, Camera camera = null)
{
if (deltaRotation != 0.0f)
{
if (camera == null) camera = Camera.main;
if (camera != null)
{
worldRotation = Quaternion.AngleAxis(deltaRotation, camera.transform.forward) * worldRotation;
}
}
return worldRotation;
}
// This allows you to scale an object by a change in pinch scale
public static void ScaleObject(Transform transform, float scale)
{
if (transform != null && scale != 1.0f)
{
transform.localScale *= scale;
}
}
// This allows you to scale an object by a change in pinch scale, relative to a point on the screen
public static void ScaleObjectRelative(Transform transform, float scale, Vector2 referencePoint, Camera camera = null)
{
if (transform != null && scale != 1.0f)
{
if (camera == null) camera = Camera.main;
if (camera != null)
{
// Find screen position of transform
var localPosition = camera.WorldToScreenPoint(transform.position);
// Scale screen position away from referencePoint
localPosition.x = referencePoint.x + (localPosition.x - referencePoint.x) * scale;
localPosition.y = referencePoint.y + (localPosition.y - referencePoint.y) * scale;
// Update position
transform.position = camera.ScreenToWorldPoint(localPosition);
// Scale up
transform.localScale *= scale;
}
}
}
// This allows you to rotate an object on screen by a change in screen rotation, relative to a point on the screen
public static void RotateObjectRelative(Transform transform, float deltaRotation, Vector2 referencePoint, Camera camera = null)
{
if (transform != null && deltaRotation != 0.0f)
{
if (camera == null) camera = Camera.main;
if (camera != null)
{
transform.RotateAround(camera.ScreenToWorldPoint(referencePoint), camera.transform.forward, deltaRotation);
}
}
}
protected virtual void OnEnable()
{
// Make sure there's only one LeanTouch active in the scene
if (Instance != null && Instance != this)
{
Debug.LogWarning("Your scene already contains a " + typeof(LeanTouch).Name + ", destroying the old one...");
DestroyImmediate(Instance.gameObject);
}
Instance = this;
#if UNITY_EDITOR
// Set the finger texture?
if (FingerTexture == null)
{
var guids = UnityEditor.AssetDatabase.FindAssets("FingerVisualization t:texture2d");
if (guids.Length > 0)
{
var path = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[0]);
FingerTexture = UnityEditor.AssetDatabase.LoadMainAssetAtPath(path) as Texture2D;
}
}
#endif
}
protected virtual void Update()
{
UpdateAllInputs();
}
protected virtual void OnGUI()
{
// Show simulated multi fingers?
if (FingerTexture != null && Input.touchCount == 0 && Fingers.Count > 1)
{
for (var i = Fingers.Count - 1; i >= 0; i--)
{
Fingers[i].Show(FingerTexture);
}
}
}
private void UpdateAllInputs()
{
UpdateFingers();
UpdateMultiTap();
UpdateGestures();
UpdateEvents();
}
private void UpdateFingers()
{
// Age inactive fingers
for (var i = InactiveFingers.Count - 1; i >= 0; i--)
{
InactiveFingers[i].Age += Time.unscaledDeltaTime;
}
// Reset finger data
for (var i = Fingers.Count - 1; i >= 0; i--)
{
var finger = Fingers[i];
// Was this set to up last time?
if (finger.Up == true)
{
// Make finger inactive
Fingers.RemoveAt(i); InactiveFingers.Add(finger);
// Reset age so we can time how long it's been inactive
finger.Age = 0.0f;
// Pool old snapshots
finger.ClearSnapshots();
}
else
{
finger.LastSet = finger.Set;
finger.LastHeldSet = finger.HeldSet;
finger.LastScreenPosition = finger.ScreenPosition;
finger.Set = false;
finger.HeldSet = false;
finger.Tap = false;
}
}
// Update real fingers
if (Input.touchCount > 0)
{
for (var i = 0; i < Input.touchCount; i++)
{
var touch = Input.GetTouch(i);
AddFinger(touch.fingerId, touch.position);
}
}
// If there are no real touches, simulate some from the mouse?
else if (AnyMouseButtonSet == true)
{
var screen = new Rect(0, 0, Screen.width, Screen.height);
var mousePosition = (Vector2)Input.mousePosition;
// Is the mouse within the screen?
if (screen.Contains(mousePosition) == true)
{
AddFinger(0, mousePosition);
// Simulate pinch & twist?
if (SimulateMultiFingers == true)
{
if (Input.GetKey(PinchTwistKey) == true)
{
var center = new Vector2(Screen.width * 0.5f, Screen.height * 0.5f);
AddFinger(1, center - (mousePosition - center));
}
// Simulate multi drag?
else if (Input.GetKey(MultiDragKey) == true)
{
AddFinger(1, mousePosition);
}
}
}
}
// Go through all fingers
for (var i = Fingers.Count - 1; i >= 0; i--)
{
var finger = Fingers[i];
// Up?
if (finger.Up == true)
{
// Tap?
if (finger.Age <= TapThreshold && finger.ScaledTotalDeltaMagnitude < SwipeThreshold)
{
finger.Tap = true;
finger.TapCount += 1;
}
else
{
finger.TapCount = 0;
}
}
// Down?
else if (finger.Down == false)
{
// Age it
finger.Age += Time.unscaledDeltaTime;
// Held?
if (finger.Age >= HeldThreshold)
{
finger.HeldSet = true;
}
}
finger.TotalDeltaMagnitude += finger.DeltaScreenPosition.magnitude;
}
}
// This handles the OnMultiTap event
private void UpdateMultiTap()
{
var fingerCount = Fingers.Count;
// At least one finger set?
if (fingerCount >= 1)
{
multiFingerTime += Time.unscaledDeltaTime;
multiFingerCount = Mathf.Max(multiFingerCount, fingerCount);
// Did this just begin?
if (lastFingerCount == 0)
{
multiFingerTime = 0.0f;
multiFingerCount = 0;
}
}
// All fingers released?
if (fingerCount == 0 && lastFingerCount > 0)
{
// Was at least one finger tapped?
if (multiFingerTime <= TapThreshold)
{
if (OnMultiTap != null) OnMultiTap(multiFingerCount);
}
}
lastFingerCount = fingerCount;
}
// Read finger data to find any gestures
private void UpdateGestures()
{
var fingerCount = Fingers.Count;
// Reset values
DragDelta = Vector3.zero;
SoloDragDelta = Vector2.zero;
MultiDragDelta = Vector2.zero;
PinchScale = 1.0f;
TwistRadians = 0.0f;
TwistDegrees = 0.0f;
// Fingers?
if (fingerCount > 0)
{
// Drag delta
for (var i = 0; i < fingerCount; i++)
{
DragDelta += Fingers[i].DeltaScreenPosition;
}
// Solo?
if (fingerCount == 1)
{
// Drag
SoloDragDelta = Fingers[0].DeltaScreenPosition;
}
// Multi?
else
{
var lastCenter = GetLastCenterOfFingers();
var center = GetCenterOfFingers();
var lastDistance = GetLastAverageFingerDistance(lastCenter);
var distance = GetAverageFingerDistance(center);
// Pinch?
if (lastDistance > 0.0f && distance > 0.0f)
{
PinchScale = distance / lastDistance;
}
// Twist?
for (var i = 0; i < fingerCount; i++)
{
TwistRadians += Fingers[i].GetDeltaRadians(lastCenter, center);
TwistDegrees += Fingers[i].GetDeltaDegrees(lastCenter, center);
}
// Drag
for (var i = 0; i < fingerCount; i++)
{
MultiDragDelta += Fingers[i].DeltaScreenPosition;
}
}
// Scale values
TwistRadians /= fingerCount;
TwistDegrees /= fingerCount;
DragDelta /= fingerCount;
MultiDragDelta /= fingerCount;
}
}
// Fire events if there are any listeners
private void UpdateEvents()
{
for (var i = 0; i < Fingers.Count; i++)
{
var finger = Fingers[i];
if (finger.Down == true && OnFingerDown != null) OnFingerDown(finger);
if (finger.Set == true && OnFingerSet != null) OnFingerSet(finger);
if (finger.Up == true && OnFingerUp != null) OnFingerUp(finger);
if (finger.Tap == true && OnFingerTap != null) OnFingerTap(finger);
if (finger.HeldDown == true && OnFingerHeldDown != null) OnFingerHeldDown(finger);
if (finger.HeldSet == true && OnFingerHeldSet != null) OnFingerHeldSet(finger);
if (finger.HeldUp == true && OnFingerHeldUp != null) OnFingerHeldUp(finger);
// Dragged?
if (finger.DeltaScreenPosition != Vector2.zero)
{
if (OnFingerDrag != null) OnFingerDrag(finger);
}
// Swiped?
if (finger.Up == true && finger.GetScaledSnapshotDelta(TapThreshold).magnitude >= SwipeThreshold)
{
if (OnFingerSwipe != null) OnFingerSwipe(finger);
}
}
if (DragDelta != Vector2.zero && OnDrag != null) OnDrag(DragDelta);
if (SoloDragDelta != Vector2.zero && OnSoloDrag != null) OnSoloDrag(SoloDragDelta);
if (MultiDragDelta != Vector2.zero && OnMultiDrag != null) OnMultiDrag(MultiDragDelta);
if (PinchScale != 1.0f && OnPinch != null) OnPinch(PinchScale);
if (TwistDegrees != 0.0f)
{
if (OnTwistDegrees != null) OnTwistDegrees(TwistDegrees);
if (OnTwistRadians != null) OnTwistRadians(TwistRadians);
}
}
// Add a finger based on index, or return the existing one
private void AddFinger(int index, Vector2 screenPosition)
{
var finger = Fingers.Find(t => t.Index == index);
// No finger found?
if (finger == null)
{
var inactiveIndex = InactiveFingers.FindIndex(t => t.Index == index);
// Use inactive finger?
if (inactiveIndex >= 0)
{
finger = InactiveFingers[inactiveIndex]; InactiveFingers.RemoveAt(inactiveIndex);
// Inactive for too long?
if (finger.Age > TapThreshold)
{
finger.TapCount = 0;
}
// Reset values
finger.Age = 0.0f;
finger.LastSet = false;
finger.Set = false;
finger.LastHeldSet = false;
finger.HeldSet = false;
finger.Tap = false;
}
// Create new finger?
else
{
finger = new LeanFinger();
finger.Index = index;
}
finger.StartScreenPosition = screenPosition;
finger.LastScreenPosition = screenPosition;
finger.ScreenPosition = screenPosition;
finger.StartedOverGui = finger.IsOverGui;
finger.TotalDeltaMagnitude = 0.0f;
Fingers.Add(finger);
}
finger.Set = true;
finger.ScreenPosition = screenPosition;
// Record?
if (RecordFingers == true)
{
// Too many snapshots?
if (RecordLimit > 0.0f)
{
if (finger.SnapshotDuration > RecordLimit)
{
var removeCount = finger.GetLowerSnapshotIndex(finger.Age - RecordLimit);
finger.ClearSnapshots(removeCount);
}
}
// Record snapshot?
if (RecordThreshold > 0.0f)
{
if (finger.Snapshots.Count == 0 || finger.LastSnapshotDelta.magnitude >= RecordThreshold)
{
finger.RecordSnapshot();
}
}
else
{
finger.RecordSnapshot();
}
}
}
}
}