|
I'm about to start implementing some obj-c UI elements on top of Unity, and was wondering whether anyone had yet created a plugin to show a popover. I've got Unity pro, so I plan to implement this code as a plugin with methods to be called from within scripts in Unity. I'd greatly appreciate any code snippets.
(comments are locked)
|
|
Well without going into full detail, UIPopoverView is pretty straight forward. Here's a simple example. Header:
I'm assuming you understand the basics of the language so I won't bore you with the entire implementation:
The real work is going to be figuring out how to send information back and forth between your game and the view controller you put in the UIPopOverView. For example, for a simple toggle switch, you'll probably want to call a native code function that sets a bool on your view whenever it changes in game. Likewise, when the bool changes in native code you'll want to send a message back downwards to notify the game. For sending messages from Unity into the view controller, the pattern I use is to create the MyCustomPicker object on startup, and do a simple singleton style pattern. So outside the @implementation block do something like this:
Also, if you have a view controller with something like a "done" button (i.e. UIImagePickerController), that done button callback should call the -(void)dismissPopoverAnimated:(BOOL)animated function on your stored UIPopOverView. Forgive me, I don't really understand how initWithView is called, nor do I understand why it needs to be called since you are presenting the popover at a coordinate. Can you give any further details?
Nov 12 at 01:40 AM
brandonc
I now understand why you need a view to display the popover, but dont understand how to modify AppController to initialize it.
Nov 12 at 06:08 PM
brandonc
It's been a long time since I originally posted this question, and now that I've done this a bunch, I should give a tip on what I think the best way to do this is. To avoid mucking around in the AppController create a category on the AppController and put all of your code in there. To get the view controller which you'll put your popover in to you can call [[UIApplication sharedApplication].keyWindow rootViewController]. With older versions of unity, the EAGL view wasn't inside a view controller, so you needed to make a temp view controller to put your popover in. But now they've wrapped up everything inside a view controller, so you can get at it much more easily.
Aug 18 at 02:41 AM
ikeo
This answer is helpful. I would be really grateful if the implementation category class file for the AppController.m could be shared. I understand why making a category is good organization, and I understand that Unity content is now inside a view. I do not understand where to put the reference to [[UIApplication sharedApplication].keyWindow rootViewController]. I like a challenge as much as anyone, but after several days trying to put together the parts from above, I’m really hoping for the details to get a complete example. Many thanks!
Mar 04 at 06:58 PM
TedB
(comments are locked)
|
Unity Answers has moved to a new system, and some users may have trouble logging in.