Admin’s note: this product appears to be unsupported as of March 2011 although the website may still allow you to buy and download it.
I’m close to completing a new system for extending Unity for iPhone. I’m thinking about offering this for sale.
EDIT: it’s done! And it’s now up to version 1.1. You can get it here: Unity iPhone Enhancement - Better iPhone Games
The goal for this enhancement system was to provide access to some additional device features (CoreLocation, video playback, and on-screen keyboard primarily) without making the developer re-do all their work in XCode with each build in Unity. I’m aiming to make this a complete bolt-on that doesn’t touch ReJ’s code at all (which goes against my normal gleeful urge to rip it to shreds.)
Unlike the method posted recently by Flashbang, this system uses Objective-C categories to override the existing applicationDidFinishLaunching: which provides a couple of benefits. One is, the new code becomes part of the existing AppController class, so we don’t need to modify the Unity source (i.e. to make variables public). It also gives me the opportunity to add new methods (to conform to other protocols, like CLLocationManagerDelegate and AdMobViewDelegate) and, finally, to insert a new handler for commands sent from inside Unity scripts.
This allows your Unity script to send a command to the Objective-C code to do things like:
(fyi, edited to keep this first post current with the latest info)
- allow users to play iPod music while the game plays
- show a second splash screen, to break up the initial startup time, and allow the user to press the “home” button to quit before the engine is fully initialized
- playVideo and playVideoFromUrl: play an mp4 video, with or without controls, from a URL or from a file bundled inside the app
- startLocationManager, stopLocationManager: turn on or off CoreLocation updates
- getInput: open the standard on-screen keyboard to retrieve text input
- showWebView: show a webview with a given URL (don’t need to quit the app and go to safari)
- showAdMobView and hideAdMobView: show, hide, or refresh an AdMob ad view. Optionally specify the orientation for the ad.
- getKeystrokes: open the standard keyboard and pass individual keystrokes back to the engine
- getPreferredLang: returns the language code for the device’s currently preferred language
- getMemoryInfo: returns the used, free and total bytes for the device
- takePicture: opens the standard camera interface, saves the photo takes to a JPEG in the app sandbox directory, and passes the filename back to the Unity script. You can optionally specify the size of the JPEG (128, 256 and 512).
- photoPicker: opens the standard photo selection interface, lets the user select a photo, saves the photo takes to a JPEG in the app sandbox directory, and passes the filename back to the Unity script. You can optionally specify the size of the JPEG (128, 256 and 512).
- screenshot: grabs the current OpenGL bitmap and saves it to a texture file (optionally pass in the texture dimensions) or the phone’s photo album.
- showList: shows a standard iPhone table view, with items you specify. Returns the item you specified, or a flag if cancelled.
-alert: displays a standard alert dialog box, with a message and up to two buttons with titles specified by you.
-checkIPA: checks to see if the running app has been cracked.
For example, here’s the CoreLocation command in action:
The best part is, you don’t have to do anything in XCode. The PostprocessBuildPlayer script fires off a bunch of AppleScript commands to XCode to add the new files and frameworks to the project. And your Default.png, Icon.png and any other assets (i.e. videos) are copied over and added to the project, too.
Here’s another screen shot with the keyboard up:
I have a screenshot of the video playing… but it’s just a video playing. You’ve seen that before, I’d bet.
Right now I’m stuck on making AdMob work without modifying ReJ’s code (I haven’t yet managed to add the view after the Unity engine initializes without messing up the OpenGL view, in a way that is oddly similar to what happened when I added TV out). If I can’t get that working, I will probably accept that I can’t do it all through my category, and have the script edit the AppController, ala FlashBang.
If this is interesting enough to you that you’d be willing to pay something for it, please PM me and let me know.