Beispiel #1
0
 public bool isHeld()
 {
     return(_isDown && Epoch.MillisElapsed(startTouchTime) >= HOLD_TIME);
 }
Beispiel #2
0
        public void OnGUI()
        {
            // TODO: Decouple from gui.
            previousTouchPosition = touchPosition;
            touchPosition         = queryTouchPosition();
            _didTap = false;

            bool upStart, downStart;

            upStart   = queryUpStart();
            downStart = queryDownStart();

            if (_isDown)
            {
                dragDistance += getDragVector().magnitude;
                dragVectorFrames[dragVectorFrameIndex++] = (touchPosition - previousTouchPosition);

                if (dragVectorFrameIndex >= DRAG_VECTOR_FRAME_COUNT)
                {
                    dragVectorFrameIndex -= DRAG_VECTOR_FRAME_COUNT;
                }

                coolDownFrac = 1;
            }
            else
            {
                coolDownFrac += (0 - coolDownFrac) / 30;
            }

            // If equal, nothing changed.
            if (upStart == downStart)
            {
                // Do nothing.
            }
            // Otherwise, if down started, set down to true.
            else if (downStart && !_isDown)
            {
                _isDown = true;

                previousTouchPosition = touchPosition;

                startTouchTime = Epoch.CurrentMillis();
                dragDistance   = 0;

                // Clear drag vector frames.
                for (int i = 0; i < DRAG_VECTOR_FRAME_COUNT; i++)
                {
                    dragVectorFrames[i] = Vector2.zero;
                }
            }
            else if (upStart && _isDown)
            {
                _isDown = false;

                // TODO: Tweak these values.
                if (Epoch.MillisElapsed(startTouchTime) < HOLD_TIME && dragDistance / Screen.dpi < .25)
                {
                    _didTap = true;
                }
                else
                {
                    _didTap = false;
                }
            }
        }