void UpdatePerFinger() { for (int i = 0; i < FingerGestures.Instance.MaxFingers && i < MaxSimultaneousGestures; ++i) { FingerGestures.Finger finger = FingerGestures.GetFinger(i); T gesture = Gestures[i]; FingerGestures.FingerList touches = tempTouchList; touches.Clear(); if (finger.IsDown) { touches.Add(finger); } if (gesture.State == GestureRecognitionState.Ready) { if (CanBegin(gesture, touches)) { Begin(gesture, 0, touches); } } UpdateGesture(gesture, touches); } }
public void Update() { // already updated this frame, skip if (lastUpdateFrame == Time.frameCount) { return; } lastUpdateFrame = Time.frameCount; fingersAdded.Clear(); fingersRemoved.Clear(); for (int i = 0; i < FingerGestures.Instance.MaxFingers; ++i) { FingerGestures.Finger finger = FingerGestures.GetFinger(i); if (finger.IsDown) { // new touch? if (!finger.WasDown) { //Debug.Log( "ADDED " + finger ); fingersAdded.Add(finger); } } else { // lifted off finger if (finger.WasDown) { //Debug.Log( "REMOVED " + finger ); fingersRemoved.Add(finger); } } } // remove fingers from clusters foreach (FingerGestures.Finger finger in fingersRemoved) { // update active clusters for (int i = clusters.Count - 1; i >= 0; --i) { Cluster cluster = clusters[i]; if (cluster.Fingers.Remove(finger)) { // retire clusters that no longer have any fingers left if (cluster.Fingers.Count == 0) { //Debug.Log( "Recycling cluster " + cluster.Id ); // remove from active clusters list clusters.RemoveAt(i); // move back to pool clusterPool.Add(cluster); } } } } // add new fingers foreach (FingerGestures.Finger finger in fingersAdded) { // try to add finger to existing cluster Cluster cluster = FindExistingCluster(finger); // no valid active cluster found for that finger, create a new cluster if (cluster == null) { cluster = NewCluster(); cluster.StartTime = finger.StarTime; //Debug.Log( "Created NEW cluster " + cluster.Id + " for " + finger ); } else { //Debug.Log( "Found existing cluster " + cluster.Id + " for " + finger ); } // add finger to selected cluster cluster.Fingers.Add(finger); } }