- Home /
how can i add a window running Unity, in an xcode project
I am trying to make a desktop app using cocoa and xcode, and would like to have a window running unity inside the main UIView (something like a managerial game, where you have all your buttons and UI items and then you have the 3d window where something happens ); and i need to load dynamically assets into the unity view,based on what happens in the main view.
I wonder if there is a way to add a component to xcode (like UILabel, UIButton, and so on), so i can use it on a xib file and add an outlet so i can drive unity from my main application.
Thanks
Answer by ikeo · Sep 28, 2011 at 08:20 PM
I don't agree that Unity isn't "meant for embedding". Unity's iPhone build simply creates an iOS application which has it's own Window, application delegate, etc. They don't make it easy to do so, but you can embed Unity within another application by forwarding all the application delegate methods from your application's delegate to those in the unity app delegate. Basically unhook Unity as the application delegate, create an instance of the Unity view controller manually and forward the delegate methods (ex. ApplicationDidFinishLaunching) to your new unity view controller instance.
Depending on your view setup, you can hack the AppController.mm file to get the Unity View controller and use that in your application. For instance, I've got a tab bar application where one of the tabs is running Unity. It's a bit tricky telling Unity when to start and pausing/unpausing when you switch tabs, but it's totally doable.
In addition, once you have a reference to the Unity view controller, you can use its view just like you would for anything else. You can add sub views (UIKit stuff like buttons for ex.), do layer animations, etc. I've got a UIKit toolbar over Unity which looks pretty spiffy as well.
If there's enough interest in this, I can publish a tutorial. It took me a little while to figure out.
I would be very interested in a Tutorial, and I know many other people would be also. $$anonymous$$any of us haven't come with xCode backgrounds, and a pointer in the right direction is always a handy thing.
We're starting to develop some apps that will require integration with iOS SD$$anonymous$$ so this will be a great point to start from. If you ever do write something up, even if its small, know it is definitely appreciated.
Cheers matty.
Yes, please create a tutorial. I know a lot of people that would be very interesting.
That would be very helpful for me too!
I need to do the exact same thing, and I had attempted to do what ikeo described a few weeks ago, but I ended up with a LOT of errors in Xcode, mostly about not recognizing classes and objects, even though they were imported/included....
Another point is the project settings. The Xcode project, in which the Unity component needs to be embedded, must have project settings that do not conflict with the iOS code project exported from Unity, especially crucial things, like Automatic Reference Counting.
Thank you very much ! Any tutorial is more than welcome ! Please !
Answer by Ricardo · Jul 11, 2010 at 08:56 AM
Unity's not really meant for embedding, so I can't think of any trivial answers to this. You could display an HTML page embedded in your application which displays a webplayer, doing Interop via SendMessage. It all seems very convoluted, though.
Agree; my point is that is totally useless to use the web player if all that i do runs locally; but if it would work then i would be ok; but sadly this approach is not feasible on a project :(
Thanks for the reply anyway; hopefully someone else has another approach?
Your answer

Follow this Question
Related Questions
Debugging "SIGSEGV" error? 2 Answers
Bunch of errors when build unity in xCode 4 Answers
Append prompt gone, only replace 0 Answers
EXEC_BAD_ACCESS question 2 Answers
Unable to deploy to ipod 2nd Gen 1 Answer