Beispiel #1
0
    void OnMouseUp()
    {
        snapPiece();

        if (snapped)
        {
            // play snapped audio
            mainAudioSource.clip = Resources.Load("Audio/SnapPiece") as AudioClip;
            mainAudioSource.Play();
        }
        else
        {
            // play put down audio
            mainAudioSource.clip = Resources.Load("Audio/PutDownPiece") as AudioClip;
            mainAudioSource.Play();
        }

        GameObject           background           = GameObject.FindGameObjectWithTag("BackgroundEffect");
        BackgroundController backgroundController = background.GetComponent <BackgroundController>();

        backgroundController.setColor(Color.white);

        //Destroy rotation icon
        Destroy(displayedRotationIconTop);
        Destroy(displayedRotationIconBottom);

        boardWrapper.updateErrors();
    }
Beispiel #2
0
    void OnMouseDrag()
    {
        snapped = false;

        Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
        Vector3 curPosition    = Camera.main.ScreenToWorldPoint(curScreenPoint);

        float newX = Mathf.Clamp(curPosition.x - localMouseXY.x, -13, 13);
        float newY = Mathf.Clamp(curPosition.y - localMouseXY.y, -10, 5);

        transform.position = new Vector3(newX, newY, -1);

        float mouseWheel = Input.GetAxisRaw("Mouse ScrollWheel");

        if (mouseWheel > 0 && rotateDelay == 0)
        {
            rotateCounterClockwise();
        }
        else if (mouseWheel < 0 && rotateDelay == 0)
        {
            rotateClockwise();
        }

        handleInput();

        GameObject           background           = GameObject.FindGameObjectWithTag("BackgroundEffect");
        BackgroundController backgroundController = background.GetComponent <BackgroundController>();

        backgroundController.setColor(ColorUtils.lightenColor(backColor, 0.2f));

        if (rotateDelay != 0)
        {
            DestroyIcons();
        }
        else if (displayedRotationIconBottom == null && displayedRotationIconTop == null)
        {
            DisplayIcons();
        }
    }
Beispiel #3
0
    void Update()
    {
        if (rotateDelay > 0)
        {
            rotateDelay--;
        }

        if (Input.touchCount > 0)
        {
            if (Input.touchCount == 1)
            {
                if (Input.GetTouch(0).phase == TouchPhase.Began)
                {
                    //check for intersection, will also need to see if top piece, also global is holding
                    if (false)
                    {
                        snapped = false;

                        Vector3 curScreenPoint = new Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y, 0);
                        Vector3 curPosition    = Camera.main.ScreenToWorldPoint(curScreenPoint);

                        float newX = Mathf.Clamp(curPosition.x - localMouseXY.x, -13, 13);
                        float newY = Mathf.Clamp(curPosition.y - localMouseXY.y, -10, 5);

                        transform.position = new Vector3(newX, newY, -1);


                        GameObject           background           = GameObject.FindGameObjectWithTag("BackgroundEffect");
                        BackgroundController backgroundController = background.GetComponent <BackgroundController>();

                        backgroundController.setColor(ColorUtils.lightenColor(backColor, 0.2f));

                        if (rotateDelay != 0)
                        {
                            DestroyIcons();
                        }
                        else if (displayedRotationIconBottom == null && displayedRotationIconTop == null)
                        {
                            DisplayIcons();
                        }
                    }
                }
                else if (Input.GetTouch(0).phase == TouchPhase.Ended && isHolding)
                {
                }
                else if (Input.GetTouch(0).phase == TouchPhase.Moved && isHolding)
                {
                    gameObject.SendMessage("OnMouseUp");
                    isHolding = false;
                }

                rotating = false;
            }
            else if (Input.touchCount == 2)
            {
                if (isHolding)
                {
                    if (!rotating)
                    {
                        startVector = Input.GetTouch(1).position - Input.GetTouch(0).position;
                    }
                    else
                    {
                        var currVector  = Input.GetTouch(1).position - Input.GetTouch(0).position;
                        var angleOffset = Vector2.Angle(startVector, currVector);
                        var LR          = Vector3.Cross(startVector, currVector);

                        if (angleOffset > 30)
                        {
                            if (LR.z > 0)
                            {
                                // Anticlockwise turn equal to angleOffset.
                                rotateCounterClockwise();
                            }
                            else if (LR.z < 0)
                            {
                                // Clockwise turn equal to angleOffset.
                                rotateClockwise();
                            }
                        }
                    }
                }
            }
        }
        else
        {
            rotating  = false;
            isHolding = false;
        }
    }