I originally posted this question under this topic, but I didn’t get a response so I thought I’d try here. Any insight is appreciated.
I have a working round-edged minimap in the upper right corner of my screen. It’s being put there by a normalized viewport and was created via the method outlined here. However, I want to add a GUI overlay on top of it (a simple ring graphic) to give it a border and mask out the straight edges of the hole in the mask plane.
I’m noticing that the viewport is scaling in the game window when I toggle between fullscreen/2-split mode. This is problematic for a couple of reasons-- it’s making getting the size of the GUI border and lining it up properly a pain. The machine I’m on is also not the same resolution as the target platform, so if I get it lined up in the editor if it keeps resizing there’s no guarantee it’ll look right on the kiosk.
Any suggestions on how to tackle this?
This is a totally blind guess:
The normalized viewport rect is a floating scale from 0 to 1, so rendering a GUI border around it should be based on the same.
Take the normalized X and Y of the viewport and multiply it by the screen.width and screen.height.
something like this (fake code):
xPositionInPixels = screen.width * viewportX
yPositionInPixels = screen.height * viewportY
This should give you the upper-left position of the viewport in pixels. So you can place a GUI element there to test it.
I’d work on just getting upper-right correct first. Then once you do, work on getting the lower right corner, which, should be something like:
First get the width and height of the viewport in pixels:
width = screen.width * viewportWidth
height = screen.width * viewportHeight
Then Add them to the original X and Y to get actual screen coordinates
viewportRight = xPositionInPixels + width
viewportBottom= yPositionInPixels + height
This is completely untested in Unity, but it works perfectly in my head.