- Home /
Is there an event being fired off when the Inspector is being resized?
Right now i'm doing essentially this:
public override void OnInspectorGUI()
{
if (Screen.width != storedWidth || Screen.height != storedHeight)
{
Refresh();
}
}
But this is super ugly and inefficient, it's getting called every frame while the inspector is being moved and if you shake it around a lot it can really screw things up.
Is there an event I can register my Refresh() with so that it's called only when the inspector is done being resized? Failing that is there a better way to do this?
Thanks!
Comment
Answer by rutter · Sep 01, 2014 at 06:22 AM
I'm not aware of a hook that will catch that, unfortunately.
But, you could avoid some overhead by waiting until the resolution has stopped changing:
Vector3 lastResolution;
bool pendingResize;
void OnInspectorGUI() {
Vector3 resolution = new Vector2(Screen.width, Screen.height);
//once resolution changes, mark pendingResize
//once resolution STOPS changing, do the resize
if (resolution != lastResolution) {
pendingResize = true;
} else if (pendingResize) {
Refresh();
}
lastResolution = resolution;
}