Unity iPhone enhancement pack

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.

I assume this will require the Advanced License?

Nope, this should work fine with Basic, except you can’t change Default.png.

Although I need to figure out what to do w/r/t WebView, since that would overcome the OpenURL restriction in Basic.

“sb_getInput”

yes please.

I added a method for getting individual keystrokes from the keyboard.

I also added a way to take pictures with the camera. The “Take Picture” interface rolls in from the right, and then rolls back offscreen when its done. I can write this picture to a sandbox file, but I’m not sure how to read it into a texture in Unity – if someone needs this feature and will help me test that out, I would appreciate it.

Looks great! I’d be interested in using it… especially the camera texture stuff :slight_smile:

Getting a texture into Unity would be most easy if you can write out that file to a png. Then it would be easy to read the file in Unity and pass the bytes to Texture2D.LoadImage().

Cheers,
-Jon

We’d be interested (despite having our own solution)…happy to support efforts like this.

Pretty nice one, congratulations.

so the important questions:

  • What is it going to cost?
  • Where can I buy it?

I’d say unity should buy you and make you put it into unity iphone basic. but if that doesn’t happen, I’d be reasonably interested too… :slight_smile:

Sounds good. As long as its robust then will be happy to purchase depending upon cost

Ok, I’m excited. :lol:

Great!
I’ll buy it!

Just reading up on this; sounds like a worthy addition Rob!

joe

Sounds awesome. :slight_smile:

Although this should probably eventually just be included in Unity iPhone proper.

I’d be interested in using this also. It looks like a nice addition to Unity iPhone.

I’m interested, depending on cost of course.

I’ve added these commands:

  • takePicture: open a camera view and lets the user take a picture with the camera; saves it as a PNG in the application’s Documents directory, and returns the path to the file

  • photoPicker: shows the photo gallery and lets the user select a photo; saves it as a PNG in the application’s Documents directory, and returns the path to the file

  • getKeystrokes: as opposed to getInput, it doesn’t pause the engine. The keyboard appears over the (running) engine. Keystrokes are captured one-by-one and sent to the engine.

I don’t have a sample for using the PNG files generated by the camera or photo gallery (and shouldn’t those be JPG files anyway? Someone asked for PNG but I think that’s a bit much.) I tried to load the resulting file into Unity like this:

renderer.material.mainTexture = Resources.Load(fname, Texture2D);

But that doesn’t work for me. I’m not sure if the issue is the the fact that fname is the full path (i.e. “/var/mobile/Applications/75E6DA4E-BBC9-4047-9039-E24470ABD96C/Documents/29D15523-9183-4F92-886E-510C6078BAAB”), or if Resources.Load() doesn’t load from the Documents directory, or if it’s something else.

Any suggestions?

you can not load external files through resources

you would have to load them through the WWW class actually, the only way to access non-build time media files through unity own commands
don’t know if the related commands exist on the iphone thought

Wow, this looks very cool. For me, especially getting keyboard access would be very interesting :wink:

Easy access and ability to play video files is very good, since when I get around to it I want to make some fmv’s