I'm trying to take advantage of some Cocoa/iPhone OS features inside my Unity application on the iPad.
The current problem I'm running in to is that what cocoa thinks is going on and what the unity application thinks is going on with respect to the orientation of the device don't seem to be in sync. I would try to use a UIPopoverController for something, and the orientation of that would just follow the orientation of the device, whereas the game portion would stay fixed.
I managed to fix that by adding in this function in http://AppController.mm
It's not perfect, but it's mostly functional. For my purposes having the game run in both landscape and portrait isn't a big deal, but I would imagine that most people would probably want to put in some kind of limitation in the app to prevent orientation switches to portrait types.
The next problem I ran in to is that the coordinate system for Unity GUI and a UIPopoverController don't seem to be the same on any orientation other than portrait.
For example, I have a GUI button that opens a UIPopoverController to do something. So code that looks like this:
(Where SelectPhoto eventually calls a function in native code that pushes a UIPopoverController with a photo picker.)
On the cocoa side, I have this code:
This only points to the button correctly in portrait. If I press the button in any other orientation it's pointing to some weird position. I'm assuming I'm going to need to change the rect that it's presenting from depending on the current interface orientation, but I'm somewhat stumped as to how to figure it out.
Also, weirdly enough, if I press the button in portrait and rotate to any given orientation, the popover points correctly to the button. It's only if I press it while I'm in a different orientation that it fails to work.
Question 1: How do I get cocoa-appropriate positions from unity screen positions?
Answered: I fiddled around with it for a bit and managed to make a function that seems to solve my problems:
Question 2: What do I need to do with Unity cameras to make the horizontal FOV in landscape modes match the vertical FOV in portraits modes
This was a limitation with previous versions of Unity. With Unity 3.4 this issue is addressed:
answered Aug 16 '11 at 01:06 AM