The simplest geometric way to define a rectangle is with two points. There is no constructor for this. Having one would greatly simplify gui ↔ viewport calculations for rects. I could code this myself and probably will eventually. I just resent having to cover such a basic piece of functionality.
Apologies in advance if this does in fact exist and my rtfm skills just suck.
hmm… I think your phrase is better written “The simplest geometric way to define a rectangles size or position is with 2 points.” If you want to define it’s size and position, you need 4 points. Unless I’m missing something?
4 ints is fine too, I just want to be able to use GUIUtility.ScreenToGUIPoint for selection boxes. Currently this only works if the player drags the mouse in one direction, the other three directions give inside out rectangles which render badly as gui boxes and also don’t work with .contains
I just did something similar but without GUIUtility. I stored the left mouse button down position and compared it to the current position to determine which direction the user was dragging. Works perfectly.
Yes that is what i did too, roughly. My complaint is that in doing so you are taking two points, storedMouse and currentMouse, and then through a series of checks evaluating whether one is top left, and if neither is then calculating a new top left from the combined position, then calculating the width and height. It is not rocket science, and if I couldn’t work it out it may have indicated I am not cut out to be a programmer. But in a framework like unity which is specifically developed for using mouse positions on a gui and a screen layer, which have differing coordinate systems, and is also specifically designed to make things simple for the programmer I see it as a major oversight. You have storedMouse and currentMouse, which contain two x and two y coordinates, descibing a non-ambiguous rectangle, and yet you have to do up to 4 checks and 4 calculations to make a rect from it, and then repeat the whole process again when converting between coordinate systems. To me it is like having 2d arrays implemented but not having a constructor so you have to create them in another scripting language and pass them to unityscript… oh wait they did that too.
Disclaimer: I don’t hate unity, but I love complaining.