Issues with changing GUI.matrix


I’m writing an editor extension and am having some trouble when I mess with GUI.matrix. Basically, i’m multiplying GUI.matrix by a matrix I construct using Matrix.TRS(). The purpose of this is to be able to pan and zoom the GUI that i’m drawing as if there was a camera.

It works as expected, but some things break. For example if I drag one of my GUI elements so that it is half outside of the EditorWindow and then pan / zoom my camera so as to see the whole element again, everything scales properly, but the part of the GUI element that was offscreen doesn’t get drawn even though the whole element should now be visible. I’m guessing there is some sort of culling mask somewhere that isn’t being updated, but if that is the case I don’t know where it is.
Has anyone else run into this problem and have a solution?

The other issue I have is that i’m using GUIUtility.RotateAroundPivot() to draw a GUI element, and if I scale or translate the GUI, this rotation gets very confused and doesn’t scale along with the GUI. Any idea how I can get the two to work together properly?


The reason that this is happening is sort of inherent in how the GUI works. The GUI in Untiy works (as far as I am aware) by drawing a rectangle the size of your screen (i.e. from -1, -1 to 1, 1 in screen coords). The reason why something you can’t see is not drawing is because it is not on the rectangle in the first place, and TRS won’t change that-only move it. What you could do is to scale the GUI rect up, then TRS that, so the edge of the screen isn’t really the edge of the rectangle. However, you will get more low res problems then, so you could just prevent dragging past the edge of the screen.