Fit canvas to UI Rect

Fit canvas to UIRect

Often you need to place paintcraft canvas somwhere on the scene between UI element, and it's hard to calculate side offset on ScreenCameraAndInput gameObject. To fix this problem you can use utility class which will take data from any specified rect on your UI and set Paintcraft canvas accordingly.

Step by step guide

  1. Add UIRect to your unity ui which will represent Paintcraft canvas

  2. Add RectToCanvasPosition script on this script and select ScreenCameraController on it


  1. IMPORTANT: Current version doesn't handle UIRect properly if you have canvasScaller on your UI, until new changes is pushed, please take working script from here.

  2. Ui Canvas component has "PixelPerfect" option. please use it if you have some visual glitches on the side like paintcraft canvas has small offset (1 pixel or less) with your ui element.‚Äč

  3. Only ScreenSpace-Overlay supported

  4. UIRect must be transparent and no any another ui element must not overlap paintcraft canvas - otherwise you will just not see it, or you will see it partially (which is in some case could be ok by your design)