I am building an app for iPad composed of two parts:
- a user interface built with cocoa
- a Unity scene
And I needed to find a way of integrating both parts and have them communicate with each other.
After a lot of research the best approach that I have found was one based on this tutorial
Basically, I have two UIWindows on my app delegate, one where I keep the hierarchy of all cocoa viewcontrollers and the other is the Unity window. When I want to switch which window is visible I just call [someWindow makeKeyAndVisible]; on the target window. When I need to communicate from the cocoa side to Unity I call UnitySendMessage.
This approach seems to work fairly well in the beginning but as I play with my app and after switching between UIWindows a couple of times, the calls to UnitySendMessage randomly stop producing any effects, the Unity scene stops updating frames and it even reaches a point where the windows don't change anymore and until the app explodes...
Basically, what I would like to know is:
- Is this the best approach to integrate Unity and cocoa views? Is there an 'official' way of doing this? Can anyone point me out an exhaustive tutorial or sample code?
- Being this the best approach, any idea on why does it starts failing after a while? Do I need to take any precautions when changing windows? (memory management? Pausing Unity thread?)
Note: I am using Unity Pro, and I have tried both xcode4/ios6 and xcode5/ios7 and the behavior is the same.
Any help would be much appreciated.