/// <summary>
 /// EventReleased, dispatched by Scaffoldings InputManager
 /// Passes through a InputTracker of the current touch.
 /// </summary>
 /// <param name="tracker">Tracker.</param>
 public override void HandleEventReleased(InputTracker tracker)
 {
     base.HandleEventReleased(tracker);
     if (_inputs.Contains(tracker.FingerId))
     {
         _inputs.Remove(tracker.FingerId);
     }
 }
Example #2
0
        /// <summary>
        /// EventDragged, dispatched by Scaffoldings InputManager
        /// Passes through a InputTracker of the current touch.
        /// </summary>
        /// <param name="tracker">Tracker.</param>
        public override void HandleEventDragged(InputTracker tracker)
        {
            base.HandleEventDragged(tracker);

            if (_trackers.Count == 2)
            {
                UpdateRotation();
            }
        }
Example #3
0
 /// <summary>
 /// EventPressed, dispatched by Scaffoldings InputManager
 /// Passes through a InputTracker of the current touch.
 /// </summary>
 /// <param name="tracker">Tracker.</param>
 public override void HandleEventPressed(InputTracker tracker)
 {
     if (tracker.FingerId > 0)
     {
         return;
     }
     base.HandleEventPressed(tracker);
     _mousePressed = true;
 }
Example #4
0
        /// <summary>
        /// EventReleased, dispatched by Scaffoldings InputManager
        /// Passes through a InputTracker of the current touch.
        /// </summary>
        /// <param name="tracker">Tracker.</param>
        public override void HandleEventReleased(InputTracker tracker)
        {
            base.HandleEventReleased(tracker);

            _angle = -1;
            if (_trackers.ContainsKey(tracker.FingerId))
            {
                _trackers.Remove(tracker.FingerId);
            }
        }
Example #5
0
 /************************************************
 * AbstractInput overrides.
 ************************************************/
 /// <summary>
 /// EventDragged, dispatched by Scaffoldings InputManager
 /// Passes through a InputTracker of the current touch.
 /// </summary>
 /// <param name="tracker">Tracker.</param>
 public override void HandleEventDragged(InputTracker tracker)
 {
     base.HandleEventDragged(tracker);
     _dragDelta = tracker.DeltaPosition;
     _velocity  = tracker.Velocity;
     if (!_gestureFound)
     {
         CalculateDirection();
     }
 }
Example #6
0
 /// <summary>
 /// EventReleased, dispatched by Scaffoldings InputManager
 /// Passes through a InputTracker of the current touch.
 /// </summary>
 /// <param name="tracker">Tracker.</param>
 public override void HandleEventReleased(InputTracker tracker)
 {
     if (tracker.FingerId > 0)
     {
         return;
     }
     base.HandleEventReleased(tracker);
     _dragDelta    = Vector3.zero;
     _mousePressed = false;
 }
Example #7
0
        /// <summary>
        /// Updates the velocity for each tracker.
        /// The tracker handles the calculations indivudually, this just gives them their data.
        /// </summary>
        /// <param name="trackers">Trackers.</param>
        private void UpdateTrackerVelocity(List <InputTracker> trackers)
        {
            int          i = 0, l = trackers.Count;
            InputTracker tracker = null;

            for (; i < l; ++i)
            {
                tracker = trackers[i];
                tracker.SetNewVelocityData(Time.realtimeSinceStartup, tracker.Position + tracker.DeltaPosition);
            }
        }
Example #8
0
        /************************************************
        * AbstractInput overrides.
        ************************************************/
        /// <summary>
        /// EventPressed, dispatched by Scaffoldings InputManager
        /// Passes through a InputTracker of the current touch.
        /// </summary>
        /// <param name="tracker">Tracker.</param>
        public override void HandleEventPressed(InputTracker tracker)
        {
            base.HandleEventPressed(tracker);

            if (tracker.HitGameObject(_collider.gameObject))
            {
                RunButtonDownCallbacks();
                _hit        = true;
                _clickedPos = tracker.Position;
                ChangeState(ButtonState.Down);
            }
        }
Example #9
0
 /************************************************
 * AbstractInput overrides.
 ************************************************/
 /// <summary>
 /// EventPressed, dispatched by Scaffoldings InputManager
 /// Passes through a InputTracker of the current touch.
 /// </summary>
 /// <param name="tracker">Tracker.</param>
 public override void HandleEventPressed(InputTracker tracker)
 {
     base.HandleEventPressed(tracker);
     if (!_trackers.ContainsKey(tracker.FingerId))
     {
         _trackers.Add(tracker.FingerId, tracker);
     }
     else
     {
         _angle = -1;
     }
 }
Example #10
0
        /// <summary>
        /// Destroy a tracker that isn't used.
        /// </summary>
        /// <param name="tracker">Tracker.</param>
        private void EndTracking(InputTracker tracker)
        {
            tracker.StopTracking();

            _trackers.Remove(tracker);
            _trackerLookup.Remove(tracker.FingerId);

            if (EventReleased != null)
            {
                EventReleased(tracker);
            }

            tracker = null;
        }
Example #11
0
        /// <summary>
        /// Handle all the trackers we have that are alive.
        /// Fire off the dragged event if they have moved.
        /// </summary>
        /// <param name="alive">Alive.</param>
        private void FilterAliveTrackers(List <InputTracker> alive)
        {
            //calculate average delta moved
            Vector3      averageDelta = Vector3.zero;
            int          activeCount = 0;
            float        averageX = 0;
            float        averageY = 0;
            int          i = 0, l = alive.Count;
            InputTracker tracker = null;

            for (; i < l; ++i)
            {
                tracker = alive[i];

                // you want to filter the movement slightly so that little finger movements dont affect real movements.
                if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android)
                {
                    averageX += tracker.DeltaPosition.x;
                    averageY += tracker.DeltaPosition.y;

                    if (EventDragged != null)
                    {
                        EventDragged(tracker);
                    }
                    activeCount++;
                }
                else
                {
                    if (EventDragged != null)
                    {
                        EventDragged(tracker);
                    }
                }
            }
            averageX = averageX / activeCount;
            if (float.IsNaN(averageX))
            {
                averageX = 0;
            }
            averageY = averageY / activeCount;
            if (float.IsNaN(averageY))
            {
                averageY = 0;
            }
            averageDelta = new Vector3(averageX, averageY, 0);
            if (EventDraggedDelta != null)
            {
                EventDraggedDelta(averageDelta);
            }
        }
        /************************************************
        * AbstractInput overrides.
        ************************************************/
        /// <summary>
        /// EventPressed, dispatched by Scaffoldings InputManager
        /// Passes through a InputTracker of the current touch.
        /// </summary>
        /// <param name="tracker">Tracker.</param>
        public override void HandleEventPressed(InputTracker tracker)
        {
            base.HandleEventPressed(tracker);
            Ray        ray = _inputCamera.ScreenPointToRay(tracker.Position);
            RaycastHit hitInfo;

            if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity))
            {
                if (hitInfo.collider == _collider)
                {
                    _enabled = true;
                }
            }
        }
Example #13
0
 void OnDrawGizmos()
 {
     if (Application.isEditor && Application.isPlaying)
     {
         int i = 0, l = 2;
         for (; i < l; ++i)
         {
             if (_trackerLookup.ContainsKey(i))
             {
                 InputTracker tracker = _trackerLookup[i];
                 Vector3      pos     = Camera.main.ScreenToWorldPoint(tracker.Position);
                 pos.z = 0;
                 Gizmos.DrawSphere(pos, 0.1f);
             }
         }
     }
 }
Example #14
0
        /************************************************
        * AbstractInput overrides.
        ************************************************/
        /// <summary>
        /// EventPressed, dispatched by Scaffoldings InputManager
        /// Passes through a InputTracker of the current touch.
        /// </summary>
        /// <param name="tracker">Tracker.</param>
        public override void HandleEventPressed(InputTracker tracker)
        {
            base.HandleEventPressed(tracker);
            Ray        ray = _inputCamera.ScreenPointToRay(tracker.Position);
            RaycastHit hitInfo;

            if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity))
            {
                if (hitInfo.collider == _collider)
                {
                    if (!_inputs.Contains(tracker.FingerId))
                    {
                        _inputs.Add(tracker.FingerId);
                    }
                }
            }
        }
Example #15
0
 /// <summary>
 /// EventReleased, dispatched by Scaffoldings InputManager
 /// Passes through a InputTracker of the current touch.
 /// </summary>
 public virtual void HandleEventReleased(InputTracker tracker)
 {
 }
Example #16
0
 /// <summary>
 /// EventPressed, dispatched by Scaffoldings InputManager
 /// Passes through a InputTracker of the current touch.
 /// </summary>
 public virtual void HandleEventPressed(InputTracker tracker)
 {
 }
Example #17
0
        /// <summary>
        /// Update all the trackers available and find and kill any unused ones.
        /// </summary>
        private void UpdateTrackers()
        {
            // Set all trackers to be killed, if they arent picked up again during the frame, they arnt being used.
            foreach (InputTracker tracker in _trackers)
            {
                tracker.KillTracker();
            }

            if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android)
            {
                //update or start trackers.
                int i = 0, l = UnityEngine.Input.touchCount;
                for (; i < l; ++i)
                {
                    Touch t = UnityEngine.Input.GetTouch(i);

                    // try to get our tracker for this finger id
                    InputTracker tracker = _trackerLookup.ContainsKey(t.fingerId) ? _trackerLookup[t.fingerId] : null;

                    if (tracker != null)
                    {
                        tracker.UpdateTracker(t.position);
                    }
                    else
                    {
                        tracker = BeginTracking(t.fingerId, t.position);
                    }
                }
            }
            else
            {
                // try to get our tracker for the mouse or simulated second finger.
                InputTracker tracker = null;
                if (UnityEngine.Input.GetMouseButton(0))
                {
                    tracker = _trackerLookup.ContainsKey(0) ? _trackerLookup[0] : null;

                    if (tracker != null)
                    {
                        tracker.UpdateTracker(UnityEngine.Input.mousePosition);
                    }
                    else
                    {
                        tracker = BeginTracking(0, UnityEngine.Input.mousePosition);
                    }
                }

                tracker = null;
                if (UnityEngine.Input.GetKey(KeyCode.LeftCommand) || UnityEngine.Input.GetKey(KeyCode.LeftControl))
                {
                    tracker = _trackerLookup.ContainsKey(1) ? _trackerLookup[1] : null;

                    if (tracker != null)
                    {
                        tracker.UpdateTracker(_secondaryMouseStartPosition - (UnityEngine.Input.mousePosition - _secondaryMouseStartPosition));
                    }
                    else
                    {
                        _secondaryMouseStartPosition = UnityEngine.Input.mousePosition - Vector3.right * 50;
                        tracker = BeginTracking(1, _secondaryMouseStartPosition - Vector3.right * 50);
                    }
                }
            }
        }
Example #18
0
 /// <summary>
 /// EventDragged, dispatched by Scaffoldings InputManager
 /// Passes through a InputTracker of the current touch.
 /// </summary>
 public virtual void HandleEventDragged(InputTracker tracker)
 {
 }
 /// <summary>
 /// EventReleased, dispatched by Scaffoldings InputManager
 /// Passes through a InputTracker of the current touch.
 /// </summary>
 /// <param name="tracker">Tracker.</param>
 public override void HandleEventReleased(InputTracker tracker)
 {
     base.HandleEventReleased(tracker);
     _enabled = false;
 }