Search Unity

iOS developers around the world are waiting impatiently for Friday, November 2, when the new iPad4 and iPad Mini ship. The iPad4 promises improved CPU and GPU performance, meaning you can develop even more beautiful content for it. The iPad Mini introduces new physical dimensions for the screen with ~160 ppi, so it might require some minor fine-tuning of human interface design.

We are happy to announce that you can already begin designing your cool content for the new iPads with today’s release of the Unity 4 beta. The Unity 4 beta is perfectly tuned to make it easy for you to detect which device your game is running on. Both devices will also work out-of-the-box with Unity 3.5.6 and in this blog we will share a small snippet of plugin code that 3.5.6 developers can use until we update a couple of 3.5.6 APIs.

Before going straight to the code we would like to say thanks to our friends at Apple who kindly shared how iPad Mini and iPad4 can be distinguished from older iPads.

There are two main API entries in Unity that help you tune your game to specific iOS device features. They are Screen.dpi and iPhone.generation. Out of the box these will work with Unity 4.0 Open Beta, but Unity 3.5.6 runtime will detect iPad Mini as 2nd generation iPad and the iPad4 as a 3rd generation device. This will let most of the games work without any change, but as mentioned above, some of you might want a more fine-grained control on things. There comes simple iOSInfo plugin code package for Unity 3.5.6, which is not aimed to completely replace Screen.dpi and iPhone.generation APIs, but more like complement it until these changes get included into official Unity 3.5.x releases.

Installation and use instructions for Unity 3.5.6 are straightforward:

  1. Download iOSInfoPlugin_for_Unity_3_5_6.unitypackage;
  2. In Unity Editor 3.5.6 click Assets->Import Package->Custom Package.. and select just downloaded file; (Make sure all the files are selected for import)
  3. Start using the code. iOSInfo plugin offers four API entries:
    • iOSInfo.isIPadMini – this property evaluates to true when running on iPad Mini;
    • iOSInfo.isIPad4Gen – this property evaluates to true when running on 4th generation iPad;
    • iOSInfo.dpi – this property provides float number with dpi estimation for current device. It effictively can be used instead of Screen.dpi.
    • iOSInfo.GetDeviceModel() – this method provides string with raw hardware ID of the device, like iPad2,5.

Most likely your code will look like this:

or like this:

With Unity 4.0 Open Beta it is even simplier. Your code probably will look like this:

or like this:

Edit: updated iOSInfo plugin download URL, I hope this one works more reliably.

30 评论



  1. does anyone have problems unzipping the folder? I get a bunch of empty folders when i tried extracting the zipped package. I also tried just deleting the .zip extension and then importing into unity but no luck there. Unity complains about unknown format. Btw, I have a mac.

  2. Hey,

    So it seems the reported DPI should be 163.0f not 167.0f?

  3. It is free’d by mono when it is invoked via PInvoke (DllImport) :

  4. Projection Matrix

    十一月 5, 2012 4:27 下午

    In the provided C++ file, char *machine = (char *)malloc(size + 1); is never free’d. Is the C# interop smart enough to free this memory? Or should that string be static instead? I changed the cpp to avoid this.

    #define MAX_DEVICE_NAME 32;
    static char g_szDeviceName[MAX_DEVICE_NAME] = { 0 };

    extern “C” char* GetDeviceModel() {
    if (g_szDeviceName[0] == 0) {
    size_t size; // get string size by passing NULL
    sysctlbyname(“hw.machine”, NULL, &size, NULL, 0);

    //char *machine = (char *)malloc(size + 1);

    sysctlbyname(“hw.machine”, g_szDeviceName, &size, NULL, 0);
    g_szDeviceName[size] = 0;

    return g_szDeviceName;

  5. It looks like it was an issue with the default zip program I had on my MacBook. Thanks.

  6. @golden_gate: we do have plans for CVOpenGLESTextureCache extension in Unity 4.x release cycle and we would be very interested to get feedback on how it could help for you projects.

  7. sounds like a hardware issue, try to reset the network settings

  8. @Hart, it’s not so, unzip the file you downloaded to import the .unitypackage file contained in the zip file.

  9. We seem to be having issues with Unity being able to import the zip file, and if we unzip the files then we don’t really know where to put those files in our project. Can you re-upload the .zip file as a .unitypackage file, or tell us where to put the files manually? Thank you.

  10. Why don’t add a zoom slider to let resize the player area to avoid the need of bigger screen to test on “small” monitors for new iPad/iphone 5?

  11. @Aras Pranckevičius Thanks so much for the hard work to make Unity iOS compatible with the new Apple Products. As a iOS Pro user with a significant investment his would be my expectation.

    The e-mail that I received stated : “We have been working together with Apple to make sure the Unity 4 beta is ready in time for the releases of the new iPad and iPad mini.”

    Its great that you have worked with Apple to make the necessary changes for the iPAD mini and iPAD 4 but when are we going to work with Apple to update the Unity iOS Pro rendering pipeline. Its been over a year and a half since Apple introduced the iOS 5 API CVOpenGLESTextureCache. Are we working on this or has Unity abandoned Apples API enhancements in lieu of GPU/CPU hardware updates. We need Unity iOS Pro API compatible with Apple iOS’s… not just hardware. What good is a powerful CPU/GPU with antiquated Unity iOS 5 API support??

  12. @ratamorph : I believe all the objects should remain in place on iPad Mini.

  13. @Mantas: performance wise it should be no problem as the games runs pretty well on ipad2. I was wondering more about things looking out of place or any other issues that might come up when a user runs my game build on 3.5.6 on an ipad mini.

  14. @ratamorph : your assumption is slightly incorrect. It won’t be “Unknown”. If you do nothing (assuming you are using Unity 3.x) then iPad4 will be detected as iPad3 and iPad Mini as iPad2. It depends how your game treats iPad3 then..

  15. I’m a bit confused, Say I don’t do any of this, since my game is already in Apple QA. The new devices will report as unknown, which in my case assumes is a new device so it applies all effects and such. No aspect ratio changes like for iPhone 5, so what exactly should I be watching for? or is this just if we wish to modify the UI somehow for the smaller iPad?

  16. Thank you very much Mantas, got it now!

  17. Thanks Mantas, is working now ;)

  18. @Angelo, @Guillermo: I just updated download url. Could you please refresh the site and try once again?

  19. Tried right now, getting 404 too.

  20. Getting 404 error on download link

  21. @Ishsaid: it does not depend on specific SDK version, but most likely you will need Xcode 4.5 to deploy to new devices.

  22. @hippo, @Paul : are you still getting 404? I can’t reproduce this..

  23. Interesting, I was already wondering how this would get supported in the current version of Unity. I’m glad that even 3.5.x users are getting this candy. Some other software companies just ignore support for older versions, if there is another version coming. Thanks =)

  24. Aras Pranckevičius

    十一月 1, 2012 9:32 下午

    @John: seriously? Same out of the box new iPad models support will come into Unity 3.5.7. Here we’re providing a way to achieve that in the already released version (3.5.6).

  25. Unity 3.5 owners are now 2nd class and slumming it……interesting way to get us to pay 6k more to and the “pro” keys we already purchased. Go Unity!

  26. Excellent! Can’t wait!

  27. Guys, getting 404 on that download link.


  28. Which iOS SDK would we need to have for these?

  29. It’s ok now guys! Will this eventually be integrated in 3.5.x ?

  30. 404 on link.