예제 #1
0
        private void Update()
        {
            if (!controlTarget)
            {
                return;
            }
            foreach (var touch in Input.touches)
            {
                if (touch.phase == TouchPhase.Began)
                {
                    originalPosition[touch.fingerId] = touch.position;
                }
                else if (touch.phase == TouchPhase.Ended)
                {
                    originalPosition.Remove(touch.fingerId);
                }
            }

            if (curGesture == GestureControl.OutOfControl)
            {
                if (Input.touchCount == 0)
                {
                    StopAllCoroutines();
                    curGesture = GestureControl.NoTouch;
                }
            }
            else if (curGesture == GestureControl.TwoMove || curGesture == GestureControl.TwoRotate || curGesture == GestureControl.TwoScale)
            {
                if (Input.touchCount != 2)
                {
                    StopAllCoroutines();
                    curGesture = GestureControl.OutOfControl;
                }
            }
            else if (curGesture == GestureControl.TwoWait)
            {
                if (Input.touchCount != 2)
                {
                    StopAllCoroutines();
                    curGesture = GestureControl.OutOfControl;
                }
                else
                {
                    Vector2 touch1Delta = Input.GetTouch(0).position - originalPosition[Input.GetTouch(0).fingerId];
                    Vector2 touch2Delta = Input.GetTouch(1).position - originalPosition[Input.GetTouch(1).fingerId];
                    if (touch1Delta.magnitude > gestureEnableDistanceThreshold && touch2Delta.magnitude > gestureEnableDistanceThreshold)
                    {
                        StopAllCoroutines();
                        if (Vector2.Dot(touch1Delta, touch2Delta) > 0)
                        {
                            Vector3 xMov;
                            Vector3 yMov;
                            GetRelativeTouch(touch1Delta + touch2Delta, out xMov, out yMov);
                            if (xMov.sqrMagnitude > yMov.sqrMagnitude)
                            {
                                curGesture = GestureControl.TwoRotate;
                                if (isTwoFingerRotatable)
                                {
                                    StartCoroutine(OnTwoRotate());
                                }
                            }
                            else
                            {
                                curGesture = GestureControl.TwoMove;
                                if (isTwoFingerDraggable)
                                {
                                    StartCoroutine(OnTwoMove());
                                }
                            }
                        }
                        else
                        {
                            curGesture = GestureControl.TwoScale;
                            if (isTwoFingerScalable)
                            {
                                StartCoroutine(OnTwoScale());
                            }
                        }
                    }
                }
            }
            else if (curGesture == GestureControl.OneMove)
            {
                if (Input.touchCount == 2)
                {
                    StopAllCoroutines();
                    curGesture = GestureControl.TwoWait;
                }
                else if (Input.touchCount != 1)
                {
                    StopAllCoroutines();
                    curGesture = GestureControl.OutOfControl;
                }
            }
            else if (curGesture == GestureControl.NoTouch)
            {
                if (Input.touchCount == 1)
                {
                    curGesture = GestureControl.OneMove;
                    if (isOneFingerDraggable)
                    {
                        StopAllCoroutines();
                        StartCoroutine(OnOneMove());
                    }
                }
                else if (Input.touchCount == 2)
                {
                    curGesture = GestureControl.TwoWait;
                    StopAllCoroutines();
                }
            }
            if (controlTarget != null)
            {
                targetCamDistance = (cameraTarget.transform.position - controlTarget.position).magnitude;
            }
        }