示例#1
0
    void Update()
    {
        bool    keepLastPoint = false;
        Vector3 currentPoint  = GetNewPoint();

        bool canDraw = !NoDraw.isInNoDraw(currentPoint);


        if (Input.GetKeyUp(KeyCode.Mouse0) || !canDraw)
        {
            if (currentSegment)
            {
                currentSegment.Complete();
            }
            currentSegment = null;
            lastPoint      = Vector3.zero;
            lastQuad       = null;
        }

        if (currentPoint == Vector3.zero || !Input.GetKey(KeyCode.Mouse0) || !canDraw)
        {
            lastPoint      = Vector3.zero;
            currentSegment = null;
            lastQuad       = null;
            return;
        }



        if (lastPoint != Vector3.zero)
        {
            if (currentSegment == null) //Create first part of new segment
            {
                lastQuad       = MakeQuad(lastPoint, currentPoint, lineSize);
                currentSegment = CreateNewSegment(lastQuad);
            }

            else if (Vector3.Distance(currentPoint, lastPoint) > minimumSectionLength)  //Continue segment
            {
                lastQuad = MakeQuadWithPrevious(lastPoint, currentPoint, lastQuad, lineSize);
                currentSegment.AddLine(lastQuad, false);
                currentSegment.CreateCollider();
            }
            else //Don't draw section yet, not big enough section
            {
                keepLastPoint = true;
            }
        }

        if (!keepLastPoint)
        {
            lastPoint = currentPoint;
        }
    }