I have a unity app, that uses Vuforia AR library. I extended this app with some iOs code. I wanted to be able to display my custom UIViewControllers sometimes instead of the main view controller that Unity uses. But I want to be able to switch back. I.e: I have a button that opens UIViewController with "About app" information and this controller then has "Exit" button to return to Unity controller.
This is my code for adding the new controller instead of the Unity View Controller:
self.unityRootController = self.keyWindow.rootViewController; // keep reference to the Unity Controller
self.keyWindow.rootViewController = controller; // display my own controller
// this pauses the unity and qcar -> so that QCAR doesn't try to recognize objects, when Unity Controller is not up
Then when returning from my own controller to Unity controller:
self.keyWindow.rootViewController = self.unityRootController; // return to Unity Controller
// start tracking with QCAR and unpause Unity View
This works fine except one case, that's caused me to pull my hair ever since encountering it. My app supports changing orientation of screen in both Unity and ObjectiveC code. And this is the trouble: If I open my View Controller while the device is for example in Portrait Orientation, then turn the device to Landscape orientation, my controller gets correctly rotated. But if I at this moment want to close my custom view controller and return to unity controller, the screen gets black suddenly. After rotating the device to portrait orientation, the unity controller suddenly starts working as expected.
I'd like the unity controller to start directly after closing my custom view controller even if the screen orientation is changed. I suppose I have to add some code after I start again the Unity Player here: QCARUnityPlayer::getInstance().QCARPause(false); UnityPause(NO); // TODO: supposedly some code should go here, that fixes black screen
But I tried to find something in the AppController.mm, that is builded by Unity and I could not find anything, that would help me. I found few lines of unity code, that had the word "orientation" in it, but I tried to use that code and didn't help. Does anybody know, what should I do, please? Thanks a bunch :)