Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

expand Unity apps with UIKit

Discussion in 'iOS and tvOS' started by rapidrunner, Jul 30, 2010.

  1. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    Hi All

    Question of the day: can i just use Unity to make the 3d part of the game (to avoid to deal with OGL), and implement the logic and the UI via UIKit on a different UIview?

    I am asking since I am planning to write an app heavily based on my existing OBJ-c code; and in an attack of lazyness, is easier to port the graphic using Unity, instead than writing the OGL part for the graphic, and re-use the code already written.

    You could say "why don't you write it all in Unity"; and the answer is just that i am more comfortable to have code written in obj-c instead than using scripting in Unity (for the majority of the time i prefer C#, but this is a phone only project, and other people on the team do not wanna spend time with Unity).

    So i am concerned if there is an easy way to create a project with unity and build it; and then go from there; keeping the obj-c code and the graphical implementation separated (like view-viewcontroller-model; to be nice with the Apple guidelines for the store submission).

    So to summarize:

    -put models, make animations, make scripts for behaviors, particle effects and so on in unity

    -build and tweak the Unity project in Xcode to add the UI using UIKit, and use classes made in OBJ-c to interact with the game

    Any suggestion is welcome, since would be something more than what i know now :D
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    That will be hard to impossible actually.

    Unity is not some kind of view that you just hook in and are happy. Its also no "ogl part", its a complete selfcontained environment, the xcode part is only to setup the application handler and tell it to run, the rest happens within the engine

    You can call out to the objc side and overlay views, thats no problem though. But going the otherway round or thinking of having a tight bidirectional communication will require quite some work that will not needfully work.
     
  3. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    that's a hit....i was hoping that the engine would run like an engine on pc; where you have your nice view and you can overlay another view , set the alpha and add the rest of the UI on top of it :(

    Guess that gotta switch approach for this project to a pure OGL app then :(

    Having support for Unity running in a view would be nice thou (hint hint *wink *wink); i can run Irrlicht in a view, so was hoping to do the same with Unity

    Thanks Dreamora
     
  4. Murcho

    Murcho

    Joined:
    Mar 2, 2009
    Posts:
    309
    You can, I have UIKit working perfectly over the top of Unity's rendering window. When I say perfectly it works fine now, however there was a long road to get there. Unity has not made it easy to do, and seeing as their GUI system brings these devices to a grinding halt, I don't understand why they didn't take full advantage of the iPhone's UIKit framework on the iPhone.

    I will say I don't rely on Unity->Objective C communication every frame, just for a messenger system for general menu elements.
     
  5. bigdaddio

    bigdaddio

    Joined:
    May 18, 2009
    Posts:
    220
    Any Examples? Does this require Unity pro?
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    In unity iphone 1.x, yes it reasonable requires unity iphone pro (which requires unity pro to buy at all)

    with unity iphone 3, both iphone liceses can be expanded through native C functions.
     
  7. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    I tried some quick attempts, and the results were not as expected....maybe an example would be useful :)

    If is too much to ask then i will continue with the OGL approach, putting Unity aside.

    Guess that i gotta write a post in the whislist for U4 :) but probably the objective is to keep Unity and Xcode separated (marketing purposes? who knows, is none of my business after all)
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    has nothing to do with seperate but unity is a self contained engine, you can't hook it in or alike.
    you start it, pause it and end it, thats basically it.

    Unity also has no UI Kit support and will never have.


    What you are looking to do is not hard but you need to know your way with UIKit and you must read the advanced iphone docs on Plugins :)

    that or buy the enhancement pack to have a collection of samples (that was one if not my primary reason to buy it originally to have something to learn from and expand upon. by now I know a hell a lot more about uikit and developing native applications straight in xcode etc naturally but it was a great start)
     
  9. bigdaddio

    bigdaddio

    Joined:
    May 18, 2009
    Posts:
    220
    @Dreamora you answer my questions everywhere, I think I will just email them to you directly ;)

    When do we get beta of Unity 3, or is that also only for Unity Pro users?

    I really find it diffucult to understand why I need Unity3D Pro in order to buy Unity iPhone Pro. Are they connected?
     
  10. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    There is no beta of unity 3 unless you preorder unity 3 pro / unity android 3 pro / unity iphone 3 / unity iphone 3 pro

    users of the free unity 3 must wait until it is released.
     
  11. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    Breaking down:

    Unity: the core

    Unity iphone: the extra add on that let you compile iOS apps using xcode and iPhone SDK

    When you get the indie you use the indie version of unity; but if you wanna go pro, you need the pro license of unity, since the pro version of the unity iphone is an add-on

    Kinda like when you buy a game and they come up with an expansion that requires the original to work....same concept ;)
     
  12. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    Isn't the release date close now? Summer is almost gone ;)

    and now that you mention it....with U3 means that i gotta upgrade my U2 iphone license to U3 iphone? I hope that we will get some upgrade price :)
     
  13. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Summer means nothing. Last year summer was at Unite 2009 .. can't recall when that was exactly, somewhen late sept early oct though so that should give you an idea.
    I don't expect it till sept if not oct as a release with the current version would lead to a lot of pressure on UT to bring out 3.0.1 optimally the very same day as there are some issues right now that at least prevent me from using it for production use.


    And yes if you bought Unity iPhone 1.x earlier than march or so when preorder started you need to upgrade.

    iPhone basic to unity iphone 3 is $100 now, $150 after release.

    iPhone Advanced to unity iphone 3 pro is $500 now, $750 after release (and as with iphone advanced it means that you naturally must own unity 3 pro for desktop too, which is also $500 now, $750 after release. you can enter your U2-xxxx license on the store to see the costs etc)
     
  14. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    Wow, the prices are really different from when i bought Unity2 :) at that time was 200 dollars for the indie version (now free) and 300 for the iphone indie ; and the pro version was 1500 :)

    Guess that soon i will also get the pro version :D

    BTW where do i get the link for the beta of U3? I've upgraded the iphone version right now

    Sorry for the OT :)
     
  15. bigdaddio

    bigdaddio

    Joined:
    May 18, 2009
    Posts:
    220
    Hey I just got the beta. It said as a pre order customer I get the beta. Weird and cool. It came in an email.
     
  16. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    it will take some days++ to get the mail with the link. unsure how long it is now as it gets shorter and shorter, originally it was in the weeks range :)
     
  17. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    Hw come, i've purchased it and you didn't and you have got the email with the beta before me? :)
     
  18. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    if he got the mail he bought it otherwise he would not get one
     
  19. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    From his question about Unity pro I would assume that he is a new user that has not even got Unity yet ; maybe i am wrong :)
     
  20. bigdaddio

    bigdaddio

    Joined:
    May 18, 2009
    Posts:
    220
    I have unity for iPhone. I guess Unity junior. I can see now why they charge for Unity and Unity iPhone since they are now integrated.

    Yes I am a new unity user. I have a U3 serial. Apparently if you have a U# serial you are on the list.
     
  21. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    its not "and"

    Unity and Unity Pro are the core licenses.

    Any other platform is an addon to either of these, where the Pro addons (like iPhone Pro / Android Pro) are addons available exclusively to Unity Pro
     
  22. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    By Unity junior you mean Unity iphone 1.7 indie?

    They always charged for Unity and Unity iphone; only recently the indie version became free; but you still have to pay for the Unity iphone/android/wii/etc (is not like they are integrated; the iphone version won't work if you do not have regular Unity).

    Welcome then; if you have a U3 serial it means that you bought U3 pro, (or upgraded your Unity iphone like i did) i assume; I was just curious to know how did you got a beta license when you didn't even know exactly how Unity and Unity iphone works; and now i get that you bought Unity 3 pro :)

    Anyway enough OT here; let's get back to the original topic :)
     
  23. bigdaddio

    bigdaddio

    Joined:
    May 18, 2009
    Posts:
    220
    Back OT I have been using a different engine and it allowed me to extend it via C++, now that I have the beta I will have to give it a go. See how it's done in Unity.

    I really yea REALLY like the editor, and using a semi real world language for scripting, like JS or even better C#.
     
  24. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Unity in U3 for both licenses, in Unity iPhone 1.x for advanced only, does it through the DLLImport mechanism which allows you to hook up extern "C" functions from mm files in your project.

    the Unity iPhone 1.x / Unity iPhone 3 advanced docs on plugins show more about it, the 1.x one also have an example linked, unsure if thats also the case in 3, didn't check the docs that much.
     
  25. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    <OT>

    Unity indie does not allow C++ code; that was a big feature for me but sadly is not supported in the free version, so no plugins or external classes

    </OT>
     
  26. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944

    Dreamora, when you talk about Unity 1.x are you talking about the first version of Unity iphone that runs on Unity 2.5 core?

    Sorry but with all these versions and names i am always wondering why don't you call everything that is in the same "release period" with a name :) (eg Unity 2.0, Unity 2.5 and Unity iphone for 2.5; Unity 3 and Unity iphone for V3 and so on)

    Anyway; this means that you can write external classes and hook them up to U3? I was sure that this is a pro feature only....

    Now in case of UIKit; you are telling me that i should write a mm (that is a c++ implementation file used in an obj-c application) file as wrapper for implementing UIKit in Unity? This looks terribly cumbersome and over-complex....takes less than 50 lines to do the same but in OGL ES and without adding any extra code other than the standard obj-c code in the SDK :)

    Please correct me if i got it wrong....I still don't see the light at the end of the tunnel about how to make these 2 guys to coexist and behave happily together (like the song from the turtles....no, not the ninja turtles!)
     
  27. bigdaddio

    bigdaddio

    Joined:
    May 18, 2009
    Posts:
    220
    I thought that unity 3 iPhone even indie will support plugins. We'll see.
     
  28. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    thats correct in the U3 incarnation, unity iphone and unity iphone pro support plugins.


    and there is no Unity iPhone 1.x that runs on the 2.5 core. Unity iPhone 1.x bases on Unity 2.1 actually.
    With Unity 3 the consistent naming and versioning is back at least :)
     
  29. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944

    AAAAh, now i get it :D so the version that i bought yesterday is Unity iphone 3 :D

    And is a good thing that it supports plugins, even if i cannot use them in the core version thou, but one problem at time :)

    Now i am still unclear about how to resolve the original problem *or maybe i should change this post title to something more related to what we are talking LOL)
     
  30. jimmay

    jimmay

    Joined:
    Sep 23, 2010
    Posts:
    28

    Hmm, well I don't know if this is what you wanted to do but adding a UIKit over Unity is pretty easy. Unity has to call into Objective C to allocate the EAGLView and also to create the window. That gives you all of the opportunity you need to do this. The only thing I had to do was:

    A) Add a new UIViewController class to the objective-C project.
    B) Add controls to my view controller
    C) Add some code to OpenEAGL_UnityCallback in AppController.mm

    The code looks like this:
    Code (csharp):
    1. int OpenEAGL_UnityCallback(UIWindow** window, int* screenWidth, int* screenHeight)
    2. {
    3.     CGRect rect = [[UIScreen mainScreen] bounds];
    4.    
    5.     // Create a full-screen window
    6.     _window = [[UIWindow alloc] initWithFrame:rect];
    7.  
    8.     // This loads your view controller (I named mine MainUIViewController)
    9.     UIViewController *uiViewController = [[UIViewController alloc] initWithNibName:@"MainUIViewController" bundle:nil];
    10.     EAGLView* view = [[EAGLView alloc] initWithFrame:rect];
    11.  
    12.     // Add the openGL view first and then the UIView so that Unity renders behind UIKit
    13.     [_window addSubview:view];
    14.     [_window addSubview:uiViewController.view];
    15.    
    16.    etc...
    17.  
    So, you don't really need plugin support to do this part, however, in order to pass data back and forth between the UIKit code and Unity script, you will need plugin support.
     
  31. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    thanks for the reply Jimmay

    Indeed i was wondering how Unity would initialize the OGL framework, and seems that it does it in the normal way (EAGL is the "canvas" where OGL content is rendered; and it can sit in a UIView; whoever has some experience with OGL ES coding on the iphone knows how it works); i tried that approach and it didn't ended up well.

    The problem is that would be considered as static graphic, due the fact that,, if i put for example a health counter in a nice view with customized foo and bars; then i cannot get it updated, because there is no communication between the UIKit controls, the view and Unity (unless there is a plugin, that would be a viewcontroller for Unity that dialogue with the vc for the UIKit view on top of the EAGLview).

    Maybe i should write a plugin for the pro version and sell it; if the Unity guys are not interested in giving this functionality (not sure how many would use it thou; but at least would make me happy :p)

    Don't get me wrong, i like the UI interpretation that Unity gives, but it is really limiting the possibilities and takes much more work, compared to use standard UIKit components and re-skin them (if you know how to work with obj-c and UIKit...otherwise your approach is much faster to learn)