Esempio n. 1
0
        public void Update()
        {
            //handle the touch input
            if (Input.touchCount > 0)
            {
                Touch currentTouch = Input.GetTouch(0);
                if (currentTouch.phase == TouchPhase.Began)
                {
                    canStartTouchManipulation = CanStartTouchManipulation();
                }

                if (canStartTouchManipulation)
                {
                    if (currentTouch.phase == TouchPhase.Began)
                    {
                        startNewSketchObject = true;
                    }
                    else if (currentTouch.phase == TouchPhase.Stationary || (currentTouch.phase == TouchPhase.Moved && startNewSketchObject == false && currentLineSketchObject.getNumberOfControlPoints() > 0))
                    {
                        if (startNewSketchObject)
                        {
                            //create a new sketch object
                            CreateNewLineSketchObject();
                            startNewSketchObject = false;
                        }
                        else if (currentLineSketchObject)
                        {
                            //Add new control point according to current device position
                            currentLineSketchObject.addControlPointContinuous(FirstPersonCamera.transform.position + FirstPersonCamera.transform.forward * .3f);
                        }
                    }
                    else if (currentTouch.phase == TouchPhase.Ended)
                    {
                        //if an empty sketch object was created, delete it
                        if (startNewSketchObject == false && currentLineSketchObject.getNumberOfControlPoints() < 1)
                        {
                            Destroy(currentLineSketchObject.gameObject);
                            currentLineSketchObject = null;
                        }

                        //if a swipe occured and no new sketch object was created, delete the last sketch object
                        if ((currentTouch.position - currentTouch.rawPosition).magnitude > Screen.width * 0.05 &&
                            ((startNewSketchObject == false && currentLineSketchObject == null) || startNewSketchObject == true))
                        {
                            DeleteLastLineSketchObject();
                        }
                        else
                        {
                            AddCurrentLineSketchObjectToStack();
                        }

                        canStartTouchManipulation = false;
                    }
                }
            }
        }