xCode to Unity communication?

Hey everybody,

The guys at Unity have done a great job implementing access to plug-in's through Unity iPhone. But I was wondering if there was a way to communicate the other way. For example, if I would like to respond to the user pushing the sleep button on the top of their device by responding to the "applicationWillResignActive" delegate.

Is there a way that I can tell Unity that this happened when it happened?



The easiest way to do this is to do polling on the Unity side of things.

One way to do it is use the PlayerPrefs. Unity iPhone has this handy hack that the PlayerPrefs (on the Unity side of things) and the NSUserDefaults (on the Objective C side) are basically the same thing. So you could store data in there and poll it from within Unity.

Or you could set up something yourself where you call a function from within Unity that essentially is a native function you wrote that returns whether or not that particular callback happened. This one requires Unity iPhone Advanced.

Another way to do it that involves calling mono functions directly is described here: http://www.tinytimgames.com/2010/01/10/the-unityobjective-c-divide/ and discussed on this forum post http://forum.unity3d.com/viewtopic.php?t=41092