Пример #1
0
    private void Start()
    {
        // setup the brush
        SetBrushColor(brushColorStateDefault);
        SetBrushSize(brushSizeDefault);
        oldLine = new OldLine(0f, 0f, 0f, Vector2.zero);

        // setup the mouse cursor
        cursorObj = new GameObject("Cursor");
        cursorObj.AddComponent <SpriteRenderer>();
        cursorSprite = cursorObj.GetComponent <SpriteRenderer>();
        SetCursorTexture(defaultCursorTexture);
        cursorSprite.sortingLayerName = "Cursor";
        Vector3 paperScale         = GameObject.FindGameObjectWithTag("Paper").GetComponent <Transform>().localScale;
        Vector3 currentCursorScale = cursorObj.transform.localScale;
        float   newScaleX          = paperScale.x * currentCursorScale.x;
        float   newScaleY          = paperScale.y * currentCursorScale.y;

        cursorObj.transform.localScale = new Vector3(newScaleX, newScaleY, 1f);
        cursorObj.SetActive(false);

        // clear all the paintings
        Clear();

        paintLayer = (1 << LayerMask.NameToLayer("Paint"));
    }
Пример #2
0
    private void OverwriteOldLine(Vector2 controlPoint, Vector2 endpoint, Vector2 pixelCoordinates)
    {
        Vector2 p1       = controlPoint;
        Vector2 p2       = endpoint;
        Vector2 paperPos = pixelCoordinates;
        OldLine ol       = new OldLine();

        // normalize the vector between the control and end points to find direction for the next control
        Vector2 endVector = (p2 - p1);

        if ((int)endVector.magnitude == 0)
        {
            ol.direction = Vector2.zero;
        }
        else
        {
            ol.direction = endVector.normalized;
        }

        ol.ctrlTangetLength = endVector.magnitude;
        ol.endX             = paperPos.x;
        ol.endY             = paperPos.y;

        oldLine = ol;
    }