Mixing Unity generated code with Objective-C in iOS? - iphone

Is it possible to mix iOS code and interface elements with Unity generated iOS code?
For example if I am working with a game developer who is developing a game in Unity, could I take his xCode project (generated by Unity), and add interface elements which I code myself using Objective-C & Interface Builder etc?
From what I can see this isn't possible as everything is created via Unity.... but hopefully I am wrong...
Thanks!

You can even use 3rd party libraries in XCode and integrate them in the build process. After fiddling around with the right settings I wrote a blog entry about this:
iPhone & Unity3D: Integrating 3rd Party Static Libraries in Unity3D Generated XCode Projects

You should be able to generate Native plug ins to interact with the Unity code. You would need to write a wrapper though. Read more at: http://unity3d.com/support/documentation/Manual/Plugins.html
Read the part at iOS :)

I came across this general guide to working with Unity native plugins in OSX which was useful and is probably where you need to be looking for your answer, as Zophiel said
https://blog.reigndesign.com/blog/unity-native-plugins-os-x

You can just design a view and button to trigger the unity to run or stop, but models in unity can't be controlled using Obj-C, although unity has import to Xcode, it only import the start code, game scripts depending on the link libraries which couldn't be modified.

I think you can do it as the same way I probably has been working with Objective-C without any changes. For Unity's code generator preserves the native codes under Classes.
And furthermore there is an another way to do this which is called "Plug-in".
But I hope the developers in Unity find a better way seamlessly combined with Xcode as staffs in Apple usually does.
Combining IB and Unity's integrated editor would be better and more welcomed in future.

Possible yes. Advisable for beginner or intermediate level Devs? Probably not. The Unity project is generated and regenerated every time you push a build. Now I believe that if you use Append when you do builds that it should keep existing changes to the Xcode project... but 'should' is the operative word there. You may need to implement some sort of build system like Jeeves to keep the headaches to a minimum if you are trying to do this on a large project in which you for see a constant stream of updates from both the Unity side and the Xcode side.
Now if you're integrating code that is in it's own files and doesn't overlap or rewrite the code Unity has generated, then the Append feature is really going to work for you, but if you're deleting, altering, or adding code to any of the files that Unity generated then definitely use SVN or some other form of source control and snap shot before and after every new Unity recompile / Xcode generation.
Also, take a look in the Unity Asset store. Whatever functionality you are trying to home brew in Xcode can definitely be written in C# on Unity. Someone else may have already conquered the problem you're trying to solve and placed it in the asset store for $5.
Hope that helps.

Related

Augmented Reality Desktop Application using Unity

Can we create an augmented reality desktop application using unity which can convert all images from a school textbook into 3D objects. ? If yes, then what will be the procedure and what other tools do we need. ? It is our final year project and we really need help in this.
If watermark will not be an issue than you can use Vuforia library.
https://developer.vuforia.com/
It has nice unity integration and you can archive what you are up to in almost no time :). But it is not supporting desktop build out of the box, but below you have alternative libraries that do:
http://artoolkit.org/download-artoolkit-sdk#unity
http://www.easyar.com/view/download.html
I can't say how good they are because I have never used them.
You can try artoolkit, stable and simple. Easyar is good but a little young.
I recommend using ARToolKit. You can target OSX, Windows and Linux if you need to. Also using the Unity plugin it should be easy for you to get started.
And if you decide to go on mobile later it also has support for iOS and Android.
http://artoolkit.org/download-artoolkit-sdk
(Scroll down for Unity version)
Edit:
They also have an active forum where you can ask questions and find help if you have the need:
http://artoolkit.org/community/forums/
Best

Xcode hook up with Unity

Hi i am new bee in Unity but i have 1 year experience in Xcode, I am doing an app in Unity for iPhone but getting bit confuse on how can i hook-up Xcode with Unity, I want to Facebook sharing, Twitter Sharing and also iOS native Email sharing(Using Mail Composer) in Unity but i don't get any help ful solution to do task in Unity, I only get Plugins which i need to Purchase first. So i want to do this task in Xcode it reduce and time and money and rest of work on Unity so is this possible that we can Communicate between Xcode and Unity? If Possible then kindly share some knowledge and links with me so that i can do this task ASAP.
Thanks in Advance.
You can start write your own plugin to complete the communication between Unity3D and iOS.
From iOS to Unity, You can just use UnitySendMessage, which is enough in most of time. You can also try to use a event and delegate in Unity Script to handle more complex situation.
From Unity to iOS, you need to implement plugin yourself. First of all, use a .cs file to declare the external method. And then implement the native code in a .mm file in Xcode and "extern C" them to the Unity. Then you can call the .cs method and get a native function called. You need a Unity Pro license to use the plugin feature.
For UnitySendMessage and Unity plugin, visit Unity Doc-Building Plugins for iOS. You can find an example in the doc called Bonjour Browser Sample. It is a very good starting point for you. If you have 1 year experience with Xcode, I think it will be easy for you.
For use delegate and event in Unity, visit Prime31's Unity Tip video.
Check out Niklas's free unity iOS plugin.
http://forum.unity3d.com/threads/122681-Free-facebook-Plugin-for-Unity-iOS
It doesn't work out of the box anymore, but with a few changes and updates you can get it working.
If you already have xCode experience then hopefully the extra work should be trivial since the Facebook SDK docs are pretty good.

How to use 3D models in Xcode (iPhone)? [duplicate]

Closed. This question needs to be more focused. It is not currently accepting answers.
Closed 3 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I want to display and rotate a single 3D model, preferably textured, on the iPhone. Doesn't have to zoom in and out, or have a background, or anything.
I have the following:
an iPhone
a MacBook
the iPhone SDK
Blender
My knowledge base:
I can make 3D models in various 3D programs (I'm most comfortable with 3D Studio Max, which I once took a course on, but I've used others)
General knowledge of procedural programming from years ago (QuickBasic - I'm old!)
Beginner's knowledge of object-oriented programming from going through simple Java and C# tutorials (Head Start C# book and my wife's intro to OOP course that used Java)
I have managed to display a 3D textured model and spin it using a tutorial in C# I got off the net (I didn't just copy and paste, I understand basically how it works) and the XNA game development library, using Visual Studio on Windows.
What I do not know:
Much about Objective C
Anything about OpenGL or OpenGL ES, which the iPhone apparently uses
Anything about XCode
My main problem is that I don't know where to start! All the iPhone books I found seem to be about creating GUI applications, not OpenGL apps. I found an OpenGL book but I don't know how much, if any, applies to iPhone development. And I find the Objective C syntax somewhat confusing, with the weird nested method naming, things like "id" that don't make sense, and the scary thought that I have to do manual memory management.
Where is the best place to start? I couldn't find any tutorials for this sort of thing, but maybe my Google-Fu is weak. Or maybe I should start with learning Objective C? I know of books like Aaron Hillgrass', but I've also read that they are outdated and much of the sample code doesn't work on the iPhone SDK, plus it seems geared towards the Model-View-Controller paradigm which doesn't seem that suited for 3D apps.
Basically I'm confused about what my first steps should be.
Once again, if I may plug my own work, I have written a post about the things I've learned from developing an OpenGL ES application on the iPhone. That application, Molecules (referred to by frankodwyer), is open source and I have a writeup on some of the other tricky issues I ran into while developing it. The application generates 3-D models and lets you rotate and scale them with your fingers, which sounds close to your needs. You can download the code, compile it, and run it on your desktop in a matter of a few minutes. If you join the iPhone Developer Program, you can install it on your device.
When it comes to object loading, Bill Dudney is working on a Wavefront OBJ loader for the iPhone that might be able to take in your Blender files, should they be exportable in that format. I haven't done much texture work on the iPhone yet, but it sounds like his example has that working now.
Overall, I find that learning by example and by jumping into development of some small, targeted applications (that you may never release) are what works for me. Try tweaking the examples listed above and see what happens. You should be able to read through the Objective-C code in those examples and start to get a feel for what they're doing.
Even though Hillegass's book (the third edition just came out and is up-to-date) focuses on the Mac, the Cocoa fundamentals he teaches are still relevant for the iPhone. The MVC design pattern serves you just as well on the iPhone as the Mac. I actually deviated from that pattern in a few places within Molecules, and I regret that decision because those sections of the application became a mess. The book is an easy read and well worth your time.
You should probably start with some simpler iphone apps/tutorials, just to get your footing on obj-c and xcode etc.
For that, I recommend the pragmatic programmer's iphone book, which has enough information to get started (I started with no knowledge of xcode, obj-c, iphone or mac and got to a working app fairly fast, using mainly this). However I should add that I come from a fairly good background in C/C++ and Java.
For your particular project, perhaps take a look at this answer which refers to an open source 3D app that you can look at and get tips from.
This is an ancient thread and I am terribly late. But still I am going to post my 2 pence here.
A Sneak Preview
Before I get in to the beast, this is my setup.
I use
Blender to create 3D models. (You can use Maya or 3D Max, I
will tell you how to export the model for Blender, same works for 3D
Max and Maya).
Cocos3D game engine.
PVRGeoPOD blender extension from Imagination Technology to
convert blender model to format that Cocos3D understand. You can see
that the link downloads an installer file which in turns downloads
the entire SDK. I can't see an easy way to download the blender
extension alone.
So if you are not intending to use Cocos3D, you can skip this answer and run for your money.
Initial Setup
Install blender.
I am not going to embarrass you by going in to details.
Download Cocos3D..
When I type this, the current version is 0.7.2.
Download Cocos2D.
Cocos3D is written on top of popular Cocos2D, a popular 2D game
framework. Important think to note here is that, Cocos2D 2.x version
is already there and stable. But Cocos3D works with Cocos2d 1.x
version only.
When you unzip the source you downloaded you will find a README file
inside and it specifically says,
PLEASE NOTE THAT cocos3d 0.7.2 IS NOT COMPATIBLE WITH cocos2d 2.x. BE
SURE TO DOWNLOAD cocos2d 1.x FOR USE WITH cocos3d.(emphasis mine)
The README file clearly tells the installation procedure. After
installation, you will get a nice Cocos3D project template in XCode.
Add PVRGeoPOD extension to Blender.
This requires some explanation. When you run the PVRGeoPOD
installer, a screen shows what and what features need to be
installed. I only selected
PVRGeoPOD - To convert my models in my .blend file to .POD format that Cocos3D understands
PVRShaman - you can view the model inside .POD using this tool.
You can install other tools in the list, but I only used these two.
Now after the installation process (which may take some time), you
need to add the PVRGeoPOD AddOn to blender. You can find the
PVRGeoPOD.UserManual.PDF file in the just installed folder, which also contains below information.
Find Blender Add-On folder, you can open blender python console and run command bpy.utils.script_paths("addons") to see the
path to this folder.
Find the blender add-on files inside the PVRGeoPOD folder, in your installation path. When you see files like
libPVRGeoPOD.dylib and PVRGeoPODScript.py and 2 QTfiles, stop there as this is the location. Copy these 4 files and paste them in
blender add on folder.
Now open blender, choose Preferences, find Add-On tab, search and find PVRGeoPOD extension and enable it by clicking the
checkbox on the right.
Now Quit and restart blender, if needed, and select file->export and see if there is an option called PVRGeoPOD(.pod/.h/.cpp),
if yes,you are successful.
Now you can create models in blender, and export these
models as .POD files which Cocos3D understands.
If you are using other 3D designing tools like Maya, 3D Max, this
PVRGeoPOD extension can be added to them also. Just see the PDF I
mentioned above.
Using in project
Step by step procedure is given below.
Create your model in blender (.blend) and export it as .POD file.
When you export I normally select following options
Primitive Type - Indexed Triangle List
Material tab - Check Export Material Option
and rest I left it as default.
Create a new project in XCode, choose Cocos3D template.
Add the .POD files to your project. If yours a textured model, add
that texture to your project also.
The template project itself contains a HelloWorld.POD file, you
can replace that line with your .POD file so that your model will be
visible.
[self addContentFromPODFile: #"YourPODFileName.pod"];
Now you have your first 3D model visible in iOS device.
I'm having a play with iPhone development for a bit of fun and bought Beginning iPhone Development by Dave Mark and Jeff LaMarche (ISBN13: 978-1-4302-1626-1) and am enjoying working through the chapters. I have a Win32 Delphi background with a bit of .NET and so Objective C is very new to me.
One of the chapters is on OpenGL and Quartz which may be of interest to you. I've haven't got that far yet so I can't really comment on how useful it will be for yourself but the writing style is very accessible and it's paced well (for me anyway).
The initial chapters explain exactly how to get up an running with a good introduction to Xcode and InterfaceBuilder.
For anything on iOS 8 or later, the answer is SceneKit. SceneKit will render Collada (DAE) files. Any decent modelling package (eg Cheetah, Blender) should export a DAE file - it's a documented portable format in XML (though xCode compiles them into binary format to save space).

How to compile an OSX Cocoa framework from code in an iPhone project?

This question comes from this other one I asked earlier: Calling custom Objective-C from a pyobjc application?
I want to re-use a small part of the app logic from my iPhone app in its server-side component, which runs on OSX. Based on what I was told in the other question, it looks like I need to compile a "framework" for both iOS and OSX from this little piece of app logic.
If we assume that I am able to isolate all the code that is to be in this framework into a single .h/.m pair of files that has no other non-Cocoa dependencies, what would be the easiest way in XCode to build this framework for each architecture and avoid double-coding all this logic on the server?
I tried adding a new OSX framework build target to my iPhone project, but this doesn't get very far and XCode bails out pretty quickly with:
target specifies product type 'com.apple.product-type.framework', but there's no such product type for the 'iphonesimulator' platform
Any help much appreciated, as I am currently dupe-implementing to keep things moving forward, but this is pretty obviously becoming a huge waste of time and source of errors when the implementations become slightly out-of-sync.
Depends on what you used in your custom class. If you did not use anything from UIKit / AppKit then the class is probably going to live well on either platform, otherwise, you’d have to use target conditionals and include separate code specially written for both platforms.
You can have multiple targets in one Xcode project, their Base SDK set separately for the Mac / iDevices.
Adam's comment to my original question answers this question. Although still interested to see if there is a way to do it all from a single XCode project, the solution I have now is plenty good enough for what I wanted to achieve.

Game development on iPhone using Unity engine

Im very new to game development on the iPhone... And I have a question:
If I was to unity, how would that work... Would I use objective-c in unity? or is all of it like just click it, and add properties, no code (that may be a stupid question, but im just wondering)
And once your done with the unity app, does it automaticly complile an xcode file for you?
Im just wondering... Thanks
Unity provides it's own visual design environment, and scripting language support. The scripting is done with C#, Javascript, and Boo for all the platforms they support. You can test your apps on the iPhone.
You can download the trial on their website.
I have used Unity and worked with some of their people, here is what I can offer:
Unity is a visual editor and as mentioned by ManiacDev you can use C#, Javascript, and Boo.
You can do a lot without coding a line and it outputs a file for you to compile in xcode. That's pretty sweet. It is very much WYSIWYG - but for some that leaves a lot to be desired.
Examining this further:
If you did want to use your own Objective C classes and code and bring them into Unity this would require purchasing their Pro version. Personally - I wouldn't go the basic license for this one reason alone. If I want to use my own server or anything else I have already coded in other projects of course I would want to take advantage of the work I have already created and not rewrite more code in C# - for the iPhone this makes no sense at all considering the uniqueness of the device and the other possibilities that could be imagined when having full access to the SDK.
The other thing you might want to think about is that their logo will appear with the basic version - if you don't care and you want to use their tools - the basic version is a great entry point. I personally do not mind their logo at all but again not having the full SDK at my disposal is not a place I would like to be locked in when you want to see your full creative potential.
Hope this helps,
Matthew