I have this Android plugin for Unity. Currently it's re-calculating a projection matrix for the camera once per frame and, while this works, it is obviously very wasteful. I'd like to be able to recalculate the matrix only when the screen orientation changes, as this is the only time it would need to be recalculated.
However, when I look online, all the answers I can seem to find always implement onConfigurationChanged or some such, which ultimately all require you to do the same thing: Extend the Activity class, which is something I can't really do, since there is no Activity. It's just a library that gets built, not a full application.
I know there's OrientationEventListener
, but that fires every time the orientation of the device changes by even one degree, so that approach would still be very wasteful.
What I want to know is, is there a way to detect screen orientation changes like some kind of onConfigurationChanged
event that doesn't require extending Activity to use?
Basically what I want to end up with is something like:
// Event fired only when the screen orientation changes
void onScreenOrientationChanged (ScreenOrientation orientation)
{
recalculateMatrix(orientation);
}
Rather than what I have now which is more like:
// Method called once per frame
void Draw ()
{
// Draw code
ScreenOrientation orientation = getOrientation();
recalculateMatrix(orientation);
}