Exemplo n.º 1
0
 private void PaintShape()
 {
     if (Event.current.type == EventType.MouseDown && Event.current.button == 0 || Event.current.type == EventType.MouseDrag && Event.current.button == 0)
     {
         Vector2 clickPos  = Event.current.mousePosition;
         Rect    shapeRect = new Rect(shapePosX, shapePosY, shape.width * pixelSize, shape.height * pixelSize);
         if (shapeRect.Contains(clickPos))
         {
             int x = Mathf.FloorToInt(((clickPos.x - shapePosX) * shape.width / (shape.width * pixelSize)));
             int y = Mathf.FloorToInt(((clickPos.y - shapePosY) * shape.height / (shape.height * pixelSize)));
             y = shape.height - y - 1;
             if (selectedCol.a == 0f)
             {
                 shape.SetPixel(x, y, new PixelTexture.Pixel(selectedCol.grayscale, 0f));
                 return;
             }
             shape.SetPixel(x, y, new PixelTexture.Pixel(selectedCol.grayscale, 1f));
         }
     }
 }