Пример #1
0
        // Records a snapshot of the current finger
        public void RecordSnapshot()
        {
            // Get an unused snapshot and set it up
            var snapshot = LeanSnapshot.Pop();

            snapshot.Age            = Age;
            snapshot.ScreenPosition = ScreenPosition;

            // Add to list
            Snapshots.Add(snapshot);


            //	Debug.Log (ScreenPosition);

            RotationListTOUCH.RotationLogTOUCH.Add(new RotationDataTOUCH());
            RotationListTOUCH.RotationLogTOUCH[RotationListTOUCH.RotationLogTOUCH.Count - 1].qRotation.x = ScreenPosition.x;
            RotationListTOUCH.RotationLogTOUCH[RotationListTOUCH.RotationLogTOUCH.Count - 1].qRotation.y = ScreenPosition.y;

            RotationListTOUCH.RotationLogTOUCH[RotationListTOUCH.RotationLogTOUCH.Count - 1].deltaTime = Age;

            //		Debug.Log (RotationListTOUCH.RotationLogTOUCH[RotationListTOUCH.RotationLogTOUCH.Count - 1].qRotation.x);


            RotationListTOUCH.Save(Path.Combine(Application.dataPath, "Data/" + "TOUCH.xml"));
        }
Пример #2
0
        // This will return the recorded position of the current finger when it was at 'targetAge'
        public Vector2 GetSnapshotScreenPosition(float targetAge)
        {
            var screenPosition = ScreenPosition;

            LeanSnapshot.TryGetScreenPosition(Snapshots, targetAge, ref screenPosition);

            return(screenPosition);
        }
Пример #3
0
        // Records a snapshot of the current finger
        public void RecordSnapshot()
        {
            // Get an unused snapshot and set it up
            var snapshot = LeanSnapshot.Pop();

            snapshot.Age            = Age;
            snapshot.ScreenPosition = ScreenPosition;

            // Add to list
            Snapshots.Add(snapshot);
        }
Пример #4
0
        protected virtual void Update()
        {
            // Is the recording being played back?
            if (Playing == true)
            {
                PlayTime += Time.deltaTime;

                var screenPosition = default(Vector2);

                if (LeanSnapshot.TryGetScreenPosition(snapshots, PlayTime, ref screenPosition) == true)
                {
                    Cursor.position = ScreenDepth.Convert(screenPosition, Camera, gameObject);
                }
            }
        }
Пример #5
0
        private void CopySnapshots(LeanFinger finger)
        {
            // Clear old snapshots
            snapshots.Clear();

            // Go through all new snapshots
            for (var i = 0; i < finger.Snapshots.Count; i++)
            {
                // Copy data into new snapshot
                var snapshotSrc = finger.Snapshots[i];
                var snapshotCpy = new LeanSnapshot();

                snapshotCpy.Age            = snapshotSrc.Age;
                snapshotCpy.ScreenPosition = snapshotSrc.ScreenPosition;

                // Add new snapshot to list
                snapshots.Add(snapshotCpy);
            }
        }
Пример #6
0
        protected virtual void Update()
        {
            // Is the recording being played back?
            if (Playing == true)
            {
                PlayTime += Time.deltaTime;

                var screenPosition = default(Vector2);

                if (LeanSnapshot.TryGetScreenPosition(snapshots, PlayTime, ref screenPosition) == true)
                {
                    // Make sure the camera exists
                    var camera = LeanTouch.GetCamera(Camera, gameObject);

                    if (camera != null)
                    {
                        Cursor.position = camera.ScreenToWorldPoint(new Vector3(screenPosition.x, screenPosition.y, Distance));
                    }
                }
            }
        }
Пример #7
0
        // Add a finger based on index, or return the existing one
        private void AddFinger(int index, Vector2 screenPosition, float pressure)
        {
            var finger = FindFinger(index);

            // No finger found?
            if (finger == null)
            {
                var inactiveIndex = FindInactiveFingerIndex(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.Set     = false;
                    finger.LastSet = false;
                    finger.Tap     = false;
                    finger.Swipe   = false;
                }
                // Create new finger?
                else
                {
                    finger = new LeanFinger();

                    finger.Index = index;
                }

                finger.StartScreenPosition = screenPosition;
                finger.LastScreenPosition  = screenPosition;
                finger.LastPressure        = pressure;
                finger.StartedOverGui      = PointOverGui(screenPosition);

                Fingers.Add(finger);
            }

            finger.Set            = true;
            finger.ScreenPosition = screenPosition;
            finger.Pressure       = pressure;

            // Record?
            if (RecordFingers == true)
            {
                // Too many snapshots?
                if (RecordLimit > 0.0f)
                {
                    if (finger.SnapshotDuration > RecordLimit)
                    {
                        var removeCount = LeanSnapshot.GetLowerIndex(finger.Snapshots, finger.Age - RecordLimit);

                        finger.ClearSnapshots(removeCount);
                    }
                }

                // Record snapshot?
                if (RecordThreshold > 0.0f)
                {
                    if (finger.Snapshots.Count == 0 || finger.LastSnapshotScreenDelta.magnitude >= RecordThreshold)
                    {
                        finger.RecordSnapshot();
                    }
                }
                else
                {
                    finger.RecordSnapshot();
                }
            }
        }
Пример #8
0
        // Add a finger based on index, or return the existing one
        private LeanFinger AddFinger(int index, Vector2 screenPosition, float pressure, bool set)
        {
            var finger = FindFinger(index);

            // No finger found?
            if (finger == null)
            {
                // If a finger goes up but hasn't been registered yet then it will mess up the event flow, so skip it (this shouldn't normally occur).
                if (set == false)
                {
                    return(null);
                }

                var inactiveIndex = FindInactiveFingerIndex(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.Old     = false;
                    finger.Set     = false;
                    finger.LastSet = false;
                    finger.Tap     = false;
                    finger.Swipe   = false;
                    finger.Expired = false;
                }
                else
                {
#if LEAN_ALLOW_RECLAIM
                    // Before we create a new finger, try reclaiming one in case the finger ID was given incorrectly
                    finger = ReclaimFinger(index, screenPosition);
#endif
                    // Create new finger?
                    if (finger == null)
                    {
                        finger = new LeanFinger();

                        finger.Index = index;
                    }
                }

                finger.StartScreenPosition = screenPosition;
                finger.LastScreenPosition  = screenPosition;
                finger.LastPressure        = pressure;
                finger.StartedOverGui      = PointOverGui(screenPosition);

                Fingers.Add(finger);
            }

            finger.Set            = set;
            finger.ScreenPosition = screenPosition;
            finger.Pressure       = pressure;

            // Record?
            if (RecordFingers == true)
            {
                // Too many snapshots?
                if (RecordLimit > 0.0f)
                {
                    if (finger.SnapshotDuration > RecordLimit)
                    {
                        var removeCount = LeanSnapshot.GetLowerIndex(finger.Snapshots, finger.Age - RecordLimit);

                        finger.ClearSnapshots(removeCount);
                    }
                }

                // Record snapshot?
                if (RecordThreshold > 0.0f)
                {
                    if (finger.Snapshots.Count == 0 || finger.LastSnapshotScreenDelta.magnitude >= RecordThreshold)
                    {
                        finger.RecordSnapshot();
                    }
                }
                else
                {
                    finger.RecordSnapshot();
                }
            }

            return(finger);
        }