Esempio n. 1
0
 /// <summary>
 /// Add given TouchState to list of tracking touches and start track this touch
 /// </summary>
 /// <param name="ts">TouchState to track</param>
 protected void TrackTouch(TouchState ts)
 {
     _TrackingTouches.Add(ts);
 }
Esempio n. 2
0
        protected override void Update()
        {
            if (Global.IsGamePaused || Global.CutSceneEnable)
            {
                return;
            }
            UpdateBoundary();

            _MaxOffset = (RenderArea.width + RenderArea.height) * 0.2f;

            if (_Touch != null)
            {
                if (_Touch.Phase == TouchPhase.Canceled || _Touch.Phase == TouchPhase.Ended)
                {
                    if (_Touch.IsLockedBy(this))
                    {
                        _Touch.UnLock(this);
                    }
                    _Touch                = null;
                    _Delta                = Vector3.zero;
                    HorizontalAxis        = 0;
                    VerticalAxis          = 0;
                    RoundedHorizontalAxis = 0;
                    RoundedVerticalAxis   = 0;
                }
            }

            if (_Touch == null && InputManager.Instance != null)
            {
                foreach (var item in InputManager.Instance.GetFreeTouches(TouchPhase.Began, _Boundary))
                {
                    _Touch = item;
                    _Touch.Lock(this);
                    _Delta = Vector3.zero;
                    if (Free)
                    {
                        StartPosition = _Touch.Position;
                    }
                    else
                    {
                        StartPosition = RenderArea.center;
                    }
                    break;
                }
            }

            if (_Touch != null)
            {
                if (Free)
                {
                    RenderArea.x = StartPosition.x - RenderArea.width * 0.5f;
                    RenderArea.y = StartPosition.y - RenderArea.height * 0.5f;
                }


                if (Free)
                {
                    _Delta += _Touch.DeltaPosition;
                }
                else
                {
                    _Delta = _Touch.Position - RenderArea.center;
                }

                _Delta.x = Mathf.Clamp(_Delta.x, -_MaxOffset, _MaxOffset);
                _Delta.y = Mathf.Clamp(_Delta.y, -_MaxOffset, _MaxOffset);


                HorizontalAxis        = _Delta.x / _MaxOffset;
                VerticalAxis          = _Delta.y / _MaxOffset;
                RoundedHorizontalAxis = Round(HorizontalAxis, HorizontalRoundThreshold);
                RoundedVerticalAxis   = Round(VerticalAxis, VerticalRoundThreshold);
            }
            else
            {
                HorizontalAxis        = 0;
                VerticalAxis          = 0;
                RoundedHorizontalAxis = 0;
                RoundedVerticalAxis   = 0;
            }

            base.Update();
        }
Esempio n. 3
0
        /// <summary>
        /// Detection
        /// </summary>
        /// <returns>Result of detection </returns>
        protected override GestureDetectionResult Detection()
        {
            // if we have a time stipulation and we exceeded it stop listening for swipes
            if ((Time.time - _StartTime) > _TimeToSwipe)
            {
                return(GestureDetectionResult.Failed);
            }

            for (int i = 0; i < FingerCount; i++)
            {
                TouchState ts = GetTrackingToucheByIndex(i);

                if (!ts.IsValidFor(this))
                {
                    return(GestureDetectionResult.Failed);
                }
                // check the delta move positions.  We can rule out at least 2 directions
                if (ts.DeltaPosition.x > 0.0f)
                {
                    _SwipeDetectionState &= ~SwipeDirection.Left;
                }
                if (ts.DeltaPosition.x < 0.0f)
                {
                    _SwipeDetectionState &= ~SwipeDirection.Right;
                }

                if (ts.DeltaPosition.y < 0.0f)
                {
                    _SwipeDetectionState &= ~SwipeDirection.Up;
                }
                if (ts.DeltaPosition.y > 0.0f)
                {
                    _SwipeDetectionState &= ~SwipeDirection.Down;
                }
            }

            // Grab the total distance moved in both directions
            Vector2 deltaLocation = _StartPoint - TouchLocation();

            deltaLocation.x = Mathf.Abs(deltaLocation.x);
            deltaLocation.y = Mathf.Abs(deltaLocation.y);


            if (CheckForEvent(SwipeDirection.Left, deltaLocation.x, deltaLocation.y)) // left check
            {
                return(GestureDetectionResult.Detected);
            }
            else if (CheckForEvent(SwipeDirection.Right, deltaLocation.x, deltaLocation.y)) // right check
            {
                return(GestureDetectionResult.Detected);
            }
            else if (CheckForEvent(SwipeDirection.Up, deltaLocation.y, deltaLocation.x)) // up check
            {
                return(GestureDetectionResult.Detected);
            }
            else if (CheckForEvent(SwipeDirection.Down, deltaLocation.y, deltaLocation.x)) // down check
            {
                return(GestureDetectionResult.Detected);
            }

            return(GestureDetectionResult.None);
        }