Some very important questions

Here are a few very important questions I have regarding using the iPhone that I don’t see addressed in the docs. I would put them each in separate threads, but I’d hate to spam the forum, so here they are:

  1. How to detect the interruption of your game, either by an incoming phone call or by the user pressing the home button so that you can save your game state, and subsequently resume in such a case.

  2. How to allow the user to listen to their own music while playing (this is a very common feature among iPhone apps, and quite necessary given that our own music would have to be PCM). I understand there may be a performance hit here and may not be possible, but I have seen other games do it.

  3. Is there a way to use the native iPhone GUI controls at any point?

  4. For puzzle-type games, is there a way to selectively re-render the display? i.e. Not have to redraw the entire screen repeatedly, but rather only when and where something has changed? This is a major concern since many puzzle games can run slower than 3D games since they involve several “pieces” which each require their own separate draw call, leading to 50-100 draw calls per frame. But they usually don’t move at all most of the time, and when they do, it is usually just one or two at a time, meaning we are drawing lots and lots of unchanging things needlessly and killing the framerate (as well as the player’s ability to provide smooth input).

Now for me to get back to Unity iPhone! :slight_smile:

  1. Looking at the docs and at AppController.mm it appears this is not implemented. Surely they will get to it in the next release (let’s hope!)
  2. I am guessing you can add a line of code to AppController.mm to do it, but it’s a good question.
  3. I think I read in another thread that might be in the roadmap eventually.
  4. No idea!
  5. I think you asked about Screen lock too, but maybe edited your post? anyways this works:
    iPhoneSettings.screenCanDarken = false;

Yeah, I came across the screenCanDarken right after posting, so I removed that one.

Thanks for the thoughtful reply. I am totally new to this side of things - so you’re saying I could add features by modifying the source code Unity uses when it does its build in Xcode? I wasn’t aware of this.

  1. Is there a way to use the native iPhone GUI controls at any point?

The more I think think about this one- it’s really unlikely, or at least, a lot trickier than you might think. I have read that the OpenGL view in CocoaTouch works optimally as the only view on screen and if you composite other UIViews over it, performance is horrid. Since all UI widgets in CocoaTouch are UIViews (if I recall) there is a dilemma. Instead use Unity Gui :smile:

Sure no problem! There is a little bit of code in the Unity-iPhone.xcodeproj that you can change or enhance. For example turning on the iphone status bar in applicationDidFinishLaunching:. It’s kind of a trivial example but it works I tried it. You could even add new code into there, I suppose if you knew what you were doing.

However I’m sure 99% of the Unity functionality comes in the various Libraries that it links with such as Unityengine.dll. So it’s pretty much a black box, certainly at the indie level it is. I guess it’s different if you have a source license! :shock:

As for the puzzle game thing (4), you’ll want to look into the MeshFilter.

It seems a bit daunting at first, but you could combine all the temporarily non moving stuff into a single mesh. One nice benefit is that you can still move the camera around and get the benefit of less draw calls.

The downside is considerably more planning and care so that your combined mesh uses a single texture and can be combined and have parts transition back to the individual objects when they need to move.

You know what ? I asked the question about accessing your own music and the reply was no - and unless the guy did not really understand my question (which is possible) its not coming anytime soon, its not even on their list in fact - which I was a bit gobsmacked at.

I asked the question during the Q&A at Unite 2008 - about the iPhone.

I think when people respond they may change their minds?

[quote=“”]
3. Is there a way to use the native iPhone GUI controls at any point?

The more I think think about this one- it’s really unlikely, or at least, a lot trickier than you might think. I have read that the OpenGL view in CocoaTouch works optimally as the only view on screen and if you composite other UIViews over it, performance is horrid. Since all UI widgets in CocoaTouch are UIViews (if I recall) there is a dilemma. Instead use Unity Gui :smile:
[/quote]Drawing(preferably small) UIKit controls over an OpenGL view is fine. It’s when you draw any OpenGL views over the UIKit views is when you run into problems.

that would be great.

option screens without UIKit will likely look ugly and virtual keyboards are a total no go due to the language dependent stuff without UIKit. (-> High Scores)

Even if we could use UIKit on top of our games… how would we call those UI elements? How can our scripts talk to cocoa??

by having the related stuff exposed to unity scripting from the UIKit.
Thats the purpose of an engine, to wrap functionality into higher level functionality.

Yeah I understand the basic concept… I was asking specifically… How can it be done? How would I code something in Unity to call code in cocoa?

I’m not getting the iPhone add-on till next week so I’m not sure if it’s mentioned in the docs already.

Ah I see.
You can not do it, thats something that must be integrated into Unity first which I hope (and assume) will happen in the forseable future.
Would potentially be something for advanced for example (or having UIKit only in both, but 3d context with UIKit overlay only in advanced for example or just more flexibility in advanced.)

I’m still intrigued by the idea of modifying some of the Xcode source to tweak functionality…

I’ve never used Xcode (I’m a Visual Studio guy), and never developed for the iPhone before, so I have absolutely no sense of what can and cannot be done this way. But I’m sure some of you out there do, and it would be awesome if you could help enlighten the rest of us as to the possibilities.

I’m thinking along the lines of question #1, or being able to access or otherwise utilize unexposed portions of the iPhone’s featureset.

Oh, and thanks, Aaron, for the tip about using procedural meshes as a solution. That sounds like a possible solution, if perhaps vastly more complicated than what I was hoping. :slight_smile:

modifying the xcode for that will not work. The scripts are a compiled module, the engine is fully compiled. All you can do is alter the basic application not nothing in the game itself.

If you want to do that, you would need to use a source based iPhone technology.

Well, for example, it looked like you could tweak the accelerometer polling interval as well as the base framerate in Xcode. So I was thinking there may be a way to write code in there to monitor for an interrupt event, then set some flag that could be checked within Unity in an attempt to catch notice of it before Unity is forced to quit.