Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0)
        {
            nFinger = Input.touchCount;
            if (nFinger > 0)
            {
                touch1 = Input.GetTouch(0);

                if (EventSystem.current.IsPointerOverGameObject(touch1.fingerId))
                {
                    return;
                }

                switch (currState)
                {
                case AppState.NONE:
                {
                    break;
                }

                case AppState.ADD:
                {
                    if (touch1.phase == TouchPhase.Began)
                    {
                        SelectedObject(traAIni.ObjectInstantiate(touch1));
                        SetInitialOrientation();
                        confirmButton.SetActive(true);
                        ChangeState(2);
                        InteractInAuthoringMode(true);
                    }
                    break;
                }

                case AppState.AUTORING:
                {
                    if (touch1.phase == TouchPhase.Began || touch1.phase == TouchPhase.Moved)
                    {
                        if (touch1.phase == TouchPhase.Began)
                        {
                            InteractInAuthoringMode(true);
                        }


                        var tmpTouch = touch1.position;
                        tmpTouch.y += 100;
                        sObject.transform.position = traAIni.GetRealWorldPos(tmpTouch);
                    }
                    else if (touch1.phase == TouchPhase.Ended || touch1.phase == TouchPhase.Canceled)
                    {
                        InteractInAuthoringMode(false);
                    }
                    break;
                }

                case AppState.EDIT:
                {
                    if (nFinger == 1)
                    {
                        if (Mathf.Abs(touch1.deltaPosition.x) >= 2.3f)
                        {
                            sObject.transform.RotateAround(sObject.transform.position, Camera.main.transform.up,
                                                           touch1.deltaPosition.x * 17.0f * Time.deltaTime * -1);
                        }

                        if (Mathf.Abs(touch1.deltaPosition.y) >= 2.3f)
                        {
                            sObject.transform.RotateAround(sObject.transform.position, Camera.main.transform.right,
                                                           touch1.deltaPosition.y * 17.0f * Time.deltaTime);
                        }
                    }
                    else
                    {
                        touch2 = Input.GetTouch(1);

                        //Debug.Log ("2Finger distance: "+ Mathf.Abs(Vector2.Distance(touch1.position,touch2.position) ));

                        if (touch1.phase == TouchPhase.Moved)
                        {
                            t1PrevPos = touch1.position - touch1.deltaPosition;
                            t2PrevPos = touch2.position - touch2.deltaPosition;

                            prevMagnitude = (t1PrevPos - t2PrevPos).magnitude;
                            cMagnitude    = (touch1.position - touch2.position).magnitude;
                            diffMagnitude = (prevMagnitude - cMagnitude);
                            //print (diffMagnitude);

                            if (Mathf.Abs(diffMagnitude) >= minPitcgDis)
                            {
                                //Debug.Log ("Scale : "+ (diffMagnitude * 0.00009f));
                                //rayDis += diffMagnitude * 0.00009f;
                                //sObject.transform.localScale *= diffMagnitude * 0.00005f;
                                //Pitch finger
                            }
                            else
                            {
                                prevDir    = t2PrevPos - t1PrevPos;
                                currentDir = touch2.position - touch1.position;

                                sObject.transform.RotateAround(sObject.transform.position, Camera.main.transform.forward, orienCont.ZTwistGesture(prevDir, currentDir));
                                //sObject.transform.Rotate (Camera.main.transform.forward, orienCont.ZTwistGesture (prevDir, currentDir)*-1);
                            }
                        }
                    }
                    break;
                }

                default:
                    break;
                }
            }
        }

        if (sObject != null && currState == AppState.EDIT && !lockPosition)
        {
            DeviceMovemnt();
        }
    }
Beispiel #2
0
    void Update()
    {
        nFinger = Input.touchCount;
        if (nFinger > 0)
        {
            touch1 = Input.GetTouch(0);

            if (EventSystem.current.IsPointerOverGameObject(touch1.fingerId))
            {
                return;
            }

            switch (currState)
            {
            case AppState.NONE:
            {
                if (touch1.phase == TouchPhase.Began)
                {
                    if (GetSelectedObject(touch1))
                    {
                        editPannel.SetActive(true);
                        ChangeState(3);
                    }
                }
                break;
            }

            case AppState.ADD:
            {
                if (touch1.phase == TouchPhase.Began)
                {
                    //sObject = traAIni.ObjectInstantiate (touch1,tmp);
                    SelectedObject(traAIni.ObjectInstantiate(touch1, tmp));
                    oInfo = (ObjectInfo)sObject.GetComponent(typeof(ObjectInfo));
                    SetInitialOrientation();
                    confirmButton.SetActive(true);
                    ChangeState(2);

                    EventSystemInteractInAthoringMode(true);
                }
                break;
            }

            case AppState.AUTORING:
            {
                if (touch1.phase == TouchPhase.Began || touch1.phase == TouchPhase.Moved)
                {
                    if (touch1.phase == TouchPhase.Began)
                    {
                        EventSystemInteractInAthoringMode(true);
                    }


                    var tmpTouch = touch1.position;
                    tmpTouch.y += 100;
                    sObject.transform.position = traAIni.GetRealWorldPos(tmpTouch);
                }
                else if (touch1.phase == TouchPhase.Ended || touch1.phase == TouchPhase.Canceled)
                {
                    EventSystemInteractInAthoringMode(false);
                }
                break;
            }

            case AppState.EDIT:
            {
                break;
            }

            case AppState.SLIDAR:
            {
                if (nFinger == 1)
                {
                    if (touch1.phase == TouchPhase.Began || touch1.phase == TouchPhase.Moved)
                    {
                        sObject.transform.position = slidAR.SlidAR(touch1.position);
                    }
                }
                else
                {
                    slidAR.ShowSlidARLine(false);
                    touch2 = Input.GetTouch(1);
                    if (touch1.phase == TouchPhase.Began || touch1.phase == TouchPhase.Moved)
                    {
                        /*
                         *                      var tmpTouch = touch1.position;
                         *                      tmpTouch.y += 100;
                         *                      sObject.transform.position = traAIni.GetRealWorldPos (tmpTouch);
                         */
                        var tmpDis   = Vector3.Distance(Camera.main.transform.position, sObject.transform.position);
                        var tmpTouch = touch1.position;
                        tmpTouch.y += 100;
                        sObject.transform.position = traAIni.GetRealWorldPos(tmpTouch, tmpDis);
                    }
                    else if (touch1.phase == TouchPhase.Ended || touch1.phase == TouchPhase.Canceled || touch2.phase == TouchPhase.Ended || touch2.phase == TouchPhase.Canceled)
                    {
                        SaveInitialData();
                        PrepareSlidARData();
                        slidAR.ShowSlidARLine(true);
                    }
                }

                break;
            }

            case AppState.ROTATION:
            {
                if (nFinger == 1)
                {
                    /*
                     *                  sObject.transform.RotateAround (sObject.transform.position,orienCont.GetGravityVector(),
                     *                          touch1.deltaPosition.x * 17.0f * Time.deltaTime);
                     */
                    sObject.transform.RotateAround(sObject.transform.position, Vector3.down,
                                                   touch1.deltaPosition.x * 17.0f * Time.deltaTime);

                    /*
                     * if (Mathf.Abs (touch1.deltaPosition.x) > Mathf.Abs (touch1.deltaPosition.y)) {
                     *  sObject.transform.Rotate (Camera.main.transform.up,orienCont.ARCBALLX(touch1));
                     * } else {
                     *  sObject.transform.Rotate (Camera.main.transform.right, orienCont.ARCBALLY (touch1));
                     * }*/
                }
                else
                {
                    touch2 = Input.GetTouch(1);

                    //Debug.Log ("2Finger distance: "+ Mathf.Abs(Vector2.Distance(touch1.position,touch2.position) ));

                    if (touch1.phase == TouchPhase.Moved)
                    {
                        if (Mathf.Abs(Vector2.Distance(touch1.position, touch2.position)) <= 270f)
                        {
                            if (Mathf.Abs(touch1.deltaPosition.x) >= 2.3f)
                            {
                                sObject.transform.RotateAround(sObject.transform.position, Camera.main.transform.up,
                                                               touch1.deltaPosition.x * 17.0f * Time.deltaTime * -1);
                            }

                            if (Mathf.Abs(touch1.deltaPosition.y) >= 2.3f)
                            {
                                //selectedObject.transform.Rotate (Camera.main.transform.up,touch.deltaPosition.y*rotaSpeed*Time.deltaTime);
                                sObject.transform.RotateAround(sObject.transform.position, Camera.main.transform.right,
                                                               touch1.deltaPosition.y * 17.0f * Time.deltaTime);
                            }
                        }
                        else
                        {
                            t1PrevPos = touch1.position - touch1.deltaPosition;
                            t2PrevPos = touch2.position - touch2.deltaPosition;

                            prevMagnitude = (t1PrevPos - t2PrevPos).magnitude;
                            cMagnitude    = (touch1.position - touch2.position).magnitude;

                            diffMagnitude = (prevMagnitude - cMagnitude);
                            //print (diffMagnitude);

                            /*
                             *                              if (Mathf.Abs (diffMagnitude) >= minPitcgDis) {
                             *                                      Debug.Log ("Scale : "+ (diffMagnitude * 0.003f));
                             *                                      var tmpScale = sObject.transform.localScale;
                             *                                      tmpScale.x+=(diffMagnitude * 0.0003f);
                             *                                      tmpScale.y+=(diffMagnitude * 0.0003f);
                             *                                      tmpScale.z+=(diffMagnitude * 0.0003f);
                             *
                             *                                      sObject.transform.localScale = tmpScale;
                             *                                      //sObject.transform.localScale *= diffMagnitude * 0.00005f;
                             *                                      //Pitch finger
                             *                              } else {*/
                            prevDir    = t2PrevPos - t1PrevPos;
                            currentDir = touch2.position - touch1.position;

                            sObject.transform.RotateAround(sObject.transform.position, Camera.main.transform.forward, orienCont.ZTwistGesture(prevDir, currentDir));
                            //sObject.transform.Rotate (Camera.main.transform.forward, orienCont.ZTwistGesture (prevDir, currentDir)*-1);

                            //}
                        }
                    }
                }

                break;
            }

            default:
                break;
            }
        }


        if (currState == AppState.SLIDAR)
        {
            if (sObject == null)
            {
                if (slidAR.GetSlidARStatus())
                {
                    slidAR.ShowSlidARLine(false);
                }
            }
        }
    }