Пример #1
0
    // Update is called once per frame
    void Update()
    {
        //Zoom in and zoom out.
        //Debug.Log(Input.mouseScrollDelta);
        float zoomingOffset = Camera.main.transform.position.z + Input.mouseScrollDelta.y * scrollspeed * Time.deltaTime;

        if (zoomingOffset > zoomingbottom && zoomingOffset < zoomingtop)
        {
            Camera.main.transform.position = new Vector3(Camera.main.transform.position.x,
                                                         Camera.main.transform.position.y,
                                                         zoomingOffset);
        }

        Vector3 mousePos = Input.mousePosition;

        // For Perspective camera, z is the distance from the camera.
        mousePos.z = -Camera.main.transform.position.z;

        Vector3 mousePositionOnScreen = Camera.main.ScreenToWorldPoint(mousePos);
        Vector3 mousePositionOnPlane  = new Vector3(mousePositionOnScreen.x, mousePositionOnScreen.y, plane.transform.position.z - offset);

        if (firstClick)
        {
            //Debug.Log(mousePositionOnScreen);
            currentLine.SetPosition(vertexCount - 1, mousePositionOnPlane);
        }

        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            // Here it goes the first click.
            if (!firstClick)
            {
                RaycastHit hitObject = new RaycastHit();
                Ray        ray       = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hitObject) && hitObject.transform.tag == "Cube")
                {
                    firstPoint = hitObject.transform.GetComponent <Glow>().getPosition();
                }

                LineInit(DashedLine);

                firstDrawingPoint = new Vector3(firstPoint.x, firstPoint.y, firstPoint.z - offset);
                currentLine.SetPosition(vertexCount - 2, firstDrawingPoint);
                firstClick = true;
            }
            // Here it goes the second click.
            else
            {
                RaycastHit hitObject = new RaycastHit();
                Ray        ray       = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hitObject) && hitObject.transform.tag == "Cube")
                {
                    secondPoint = hitObject.transform.GetComponent <Glow>().getPosition();
                }

                secondDrawingPoint = new Vector3(secondPoint.x, secondPoint.y, secondPoint.z - offset);
                currentLine.SetPosition(vertexCount - 1, secondDrawingPoint);

                int existIndex = 0;
                if (secondPoint == firstPoint)
                {
                    Destroy(currentLine.gameObject);
                }
                else if ((existIndex = CheckExist(firstDrawingPoint, secondDrawingPoint)) >= 0)
                {
                    // Add log.
                    logTool.LineDel(firstDrawingPoint, secondDrawingPoint);

                    Destroy(currentLine.gameObject);
                    LineRenderer line = AllLines[existIndex];
                    AllLines.RemoveAt(existIndex);
                    Destroy(line.gameObject);
                }
                else
                {
                    AllLines.Add(currentLine);

                    // Add Log.
                    logTool.LineAdd(firstDrawingPoint, secondDrawingPoint);
                }
                firstClick = false;
            }
        }
    }