Exemple #1
0
    void Update()
    {
        if (Global.LeftArrowActiveMovie == true)                                           //updatesleft and right toolbat arrows
        {
            GameObject.Find("LeftArrowMovie").GetComponent <Button>().interactable = true;
        }
        else
        {
            GameObject.Find("LeftArrowMovie").GetComponent <Button>().interactable = false;
        }

        if (Global.RightArrowActiveMovie == true)
        {
            GameObject.Find("RightArrowMovie").GetComponent <Button>().interactable = true;
        }
        else
        {
            GameObject.Find("RightArrowMovie").GetComponent <Button>().interactable = false;
        }


        if (Input.touchCount > 0)                                                                                                        //at least one touch detected
        {
            wp       = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);                                                       //Vector3 of the touch location on the screen
            touchPos = new Vector2(wp.x, wp.y);

            foreach (string name in movieArray)
            {
                GameObject go = GameObject.Find(name);

                if (go)
                {
                    myCollider = go.gameObject.GetComponent <CircleCollider2D>();

                    if (myCollider)                                                       //collider will not exist for the anchor shape0
                    {
                        if (myCollider == Physics2D.OverlapPoint(touchPos))               //if the touch position overlaps with the 2D collider of the shape
                        {
                            playArray[System.Array.IndexOf(movieArray, go.name)] = true;  //in play


                            if (Input.touchCount == 2)
                            {                                                                                                            //updates rotation
                                Quaternion desiredRotation = go.gameObject.transform.rotation;                                           //start desiredRotation as the current orientation of the shape
                                float      pinchAmount     = 0;

                                DetectTouchPinch.Calculate();

                                if (Mathf.Abs(DetectTouchPinch.pinchDistanceDelta) > 0)
                                {    //PINCH
                                    pinchAmount = DetectTouchPinch.pinchDistanceDelta;

                                    if (pinchAmount > pinchThresh)
                                    {
                                        //positive pinch scale up
                                        if (Mathf.Abs(go.gameObject.transform.localScale.x) < maxScale && Mathf.Abs(go.gameObject.transform.localScale.y) < maxScale)
                                        {
                                            go.gameObject.transform.localScale *= (1 + scaleIncrement);
                                        }
                                    }
                                    if (pinchAmount < -pinchThresh)
                                    {
                                        //negative pinch scale down
                                        if (Mathf.Abs(go.gameObject.transform.localScale.x) > minScale && Mathf.Abs(go.gameObject.transform.localScale.y) > minScale)
                                        {
                                            go.gameObject.transform.localScale *= (1 - scaleIncrement);
                                        }
                                    }
                                }

                                if (Mathf.Abs(DetectTouchPinch.turnAngleDelta) > 0) //if the detected turn angle is large enough and the shape is not small/circular
                                {                                                   //ROTATE
                                    Vector3 rotationDeg = Vector3.zero;
                                    rotationDeg.z    = DetectTouchPinch.turnAngleDelta;
                                    desiredRotation *= Quaternion.Euler(rotationDeg);                                                  //update the desiredRotation to include this change in angle

                                    go.gameObject.transform.rotation = desiredRotation;                                                //upate the shape rotated orientation
                                }
                            }
                            foreach (UnityEngine.Touch touch in Input.touches)
                            {                            //https://answers.unity.com/questions/369230/how-to-detect-double-tap-in-android.html?childToView=1695525#answer-1695525
                                if (touch.tapCount >= 2) //flips on vertical axis if double tapped (finnicky)
                                {                        //DOUBLE TAP
                                    Vector3 temp = go.gameObject.transform.localScale;
                                    temp.x *= -1;
                                    go.gameObject.transform.localScale = temp;
                                }
                                else if (Input.touchCount == 1)
                                {   //TRANSLATE                                                                                          //updates shape translated position https://answers.unity.com/questions/991083/dragging-a-2d-sprite-with-touch.html
                                    go.gameObject.transform.position = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x,
                                                                                   Camera.main.ScreenToWorldPoint(Input.mousePosition).y,
                                                                                   0.0f);
                                }
                            }
                        }
                    }
                }
            }
        }
        else
        { //no touch counts
            foreach (string name in movieArray)
            {
                GameObject go = GameObject.Find(name);

                if (go)
                {
                    if ((go.transform.position.y < Camera.main.ScreenToWorldPoint(GameObject.Find("Divider").transform.position).y) && (Global.Recording == false))
                    {
                        //if released in the toolbar return to correct place, orientation and scale
                        playArray[System.Array.IndexOf(movieArray, go.name)] = false;                               //not in play

                        go.transform.position = selectionArray[System.Array.IndexOf(movieArray, go.name)];
                        go.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
                        go.gameObject.transform.localScale = new Vector3(0.5f, 0.5f, 1f);
                    }
                }
            }
        }
    } //end update
Exemple #2
0
    void Update()
    {
        for (int i = 0; i < popUps.Length; i++)
        {
            if (i == popUpIndex)
            {
                popUps[i].SetActive(true);
            }
            else
            {
                popUps[i].SetActive(false);
            }
        }

        //adapted movierotate script here (actions are stopped by flags depending on tutorial progress)
        if ((Input.touchCount > 0) && (translateFlag == true) && (disableFlag == false))                                                  //at least one touch detected
        {
            wp       = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);                                                        //Vector3 of the touch location on the screen
            touchPos = new Vector2(wp.x, wp.y);

            GameObject go = GameObject.Find("Rooster");

            if (go)
            {
                myCollider = go.gameObject.GetComponent <CircleCollider2D>();


                if (myCollider)                                                                                                     //collider will not exist for the anchor shape0
                {
                    if (myCollider == Physics2D.OverlapPoint(touchPos))                                                             //if the touch position overlaps with the 2D collider of the shape
                    {
                        if ((Input.touchCount == 2) && (rotateFlag == true))
                        {
                            Quaternion desiredRotation = go.gameObject.transform.rotation;                                        //start desiredRotation as the current orientation of the shape
                            DetectTouchPinch.Calculate();                                                                         //determines turnAngle and turnAngleDelta from 2 finger rotation on screen

                            float pinchAmount = 0;

                            if (Mathf.Abs(DetectTouchPinch.turnAngleDelta) > 0) //if the detected turn angle is large enough and the shape is not small/circular
                            {                                                   //ROTATION
                                Vector3 rotationDeg = Vector3.zero;
                                rotationDeg.z    = DetectTouchPinch.turnAngleDelta;
                                desiredRotation *= Quaternion.Euler(rotationDeg);                                                    //update the desiredRotation to include this change in angle

                                go.gameObject.transform.rotation = desiredRotation;                                                  //upate the shape rotated orientation

                                if (popUpIndex == 6)
                                {
                                    popUpIndex = 7;
                                    TuteLoadManager();
                                }
                            }


                            if ((Mathf.Abs(DetectTouchPinch.pinchDistanceDelta) > 0) && pinchFlag == true)
                            { //PINCH
                                pinchAmount = DetectTouchPinch.pinchDistanceDelta;

                                if (pinchAmount > pinchThresh)
                                {
                                    //positive pinch scale up
                                    if (Mathf.Abs(go.gameObject.transform.localScale.x) < maxScale && Mathf.Abs(go.gameObject.transform.localScale.y) < maxScale)
                                    {
                                        go.gameObject.transform.localScale *= (1 + scaleIncrement);

                                        if (popUpIndex == 8)
                                        {
                                            popUpIndex = 9;
                                            TuteLoadManager();
                                        }
                                    }
                                }
                                if (pinchAmount < -pinchThresh)
                                {
                                    //negative pinch scale down
                                    if (Mathf.Abs(go.gameObject.transform.localScale.x) > minScale && Mathf.Abs(go.gameObject.transform.localScale.y) > minScale)
                                    {
                                        go.gameObject.transform.localScale *= (1 - scaleIncrement);

                                        if (popUpIndex == 8)
                                        {
                                            popUpIndex = 9;
                                            TuteLoadManager();
                                        }
                                    }
                                }
                            }
                        }

                        foreach (UnityEngine.Touch touch in Input.touches)
                        {                                                                   //https://answers.unity.com/questions/369230/how-to-detect-double-tap-in-android.html?childToView=1695525#answer-1695525
                            if ((touch.tapCount >= 2))                                      //flips on vertical axis if double tapped (finnicky)
                            {
                                Vector3 temp = go.gameObject.transform.localScale;
                                temp.x *= -1;
                                go.gameObject.transform.localScale = temp;


                                if (popUpIndex == 7)
                                {
                                    popUpIndex = 8;
                                    TuteLoadManager();
                                }
                            }
                            else if (Input.touchCount == 1)
                            {                                                                                                                                                  //updates shape translated position https://answers.unity.com/questions/991083/dragging-a-2d-sprite-with-touch.html
                                if (Camera.main.ScreenToWorldPoint(Input.mousePosition).y < Camera.main.ScreenToWorldPoint(GameObject.Find("MaxHeight").transform.position).y) // stops shape going behind instructions
                                {
                                    go.gameObject.transform.position = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x,
                                                                                   Camera.main.ScreenToWorldPoint(Input.mousePosition).y,
                                                                                   0.0f);

                                    if (popUpIndex == 5)
                                    {
                                        popUpIndex = 6;
                                        TuteLoadManager();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        else
        { //no touch counts
            GameObject go = GameObject.Find("Rooster");

            if (go)
            {
                if ((go.transform.position.y < Camera.main.ScreenToWorldPoint(GameObject.Find("Divider").transform.position).y) && (toolbarFlag == true))
                {
                    //if released in the toolbar return to correct place orientation and scale
                    go.transform.position = new Vector3(-0.0159f, Global.toolbarY, 0f);
                    go.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
                    go.gameObject.transform.localScale = new Vector3(1f, 1f, 1f);

                    if (popUpIndex == 9)
                    {
                        popUpIndex = 10;
                        TuteLoadManager();
                    }
                }
            }
        }
    }