It’s more than that though. It doesn’t make sense for it to be the next number.
If I position an element on the GUI, using Rect. What’s the last pixel shown? It’s xMax-1, and yMax-1.
That’s intended? Why is the implementation the next pixel? Who’s this help?
Rects are in Cartesian coordinates. Nothing to do with pixels. In unity, your whole world is floats. Pixels are just an unfortunate product of the rendering process. Best not to get too hung-up on them.
I need a very pixel perfect GUI system. I have a ton of xMax - 1, and yMax - 1 typed out to target the last pixel showing of an element.
For example, a bottom border of a gui element, and the border has a height. The top pixel of the border is yMax - borderHeight - 1. The bottom of that border is yMax - 1.
It’s everywhere.
Should I continue that as my best case? Any recommendations?
Are you hand-hammering all your UI out with good old OnGUI()?? If you are, more power to you, but you should consider moving to either UGUI or UIElements and just doing it with proper layout tools. As KDG points out it’s all floats, all the way down.
Pixel perfect stuff requires exquisite attention to detail at all points in the render-transform stack, from generation of the vertices to the camera transform to the final scissoring and all points in between. Pixel perfect is sort of like bank monetary transactions: even one slip up and the money is gone.
I tried some experimenting with low res pixel stuff with UGUI one time. I got a fairly tolerable result by rendering the whole screen down to a render texture (to control the actual rendering resolution.) I made the image size, anchor, sprite ppu and canvas reference size all perfectly based around that resolution. For it to work, you have to adjust everything so that it lines-up perfectly and resamples perfectly.
Frankly (as much as I love Unity) if you’re trying to get a retro-pixel look, I recommend the GameMaker engine. The workflow is based around pixels, and the rendering process is much simpler with fewer transformations to mess things up. Essentially, you’d need to write your own GUI system from scratch, but there are “draw immediate” tools that make that pretty easy.
The app is not a game, We use the 3d engine for things like CAD drawings, and the rest of the app is all 2D GUI/networking that can deploy cross platform.
Hey, slap me five man… I’m still using it for at least half of my game UI needs, but I’ve been slowly migrating to UGUI, which is now also deprecated, alas.
OTOH, I also don’t put a super-high emphasis on good looking UI. I’m a programmer nerd and I just need it to function (not negotiable) and to be nominally clear to the user.
As for the Rect structure, that isn’t (hopefully) going to change, so keep your -1 and +1 warts and just push forward, unless you want to waste time making your own Rect. I would NOT recommend that.
The latest UI attempt in progress is called UIElements / UI Toolkit but even Unity’s official page says it isn’t ready for use yet:
I quote:
Unity intends for UI Toolkit to become the recommended UI system for new UI development projects, but it is still missing some features found in Unity UI (uGUI) and IMGUI. These older systems are more appropriate for certain use cases, and are required to support legacy projects.
UI Toolkit is in active development. This page will update frequently as the feature set evolves.