Use c++ Code in Unity3D - unity3d

I am using unity3D for the first time to develop a game.I have written a code in c++ using Opencv and the code consist on many files.Now I want to apply the result computed by c++ code to a 3D character.
How i can use my c++ code in unity.Please help me.Remember I am using OpenCV Libraries in my c++ Code.
Thanks!!

You need to write a DLL file and use it within Unity. There is many examples on how to do so.
http://docs.unity3d.com/Manual/Plugins.html
If you have some money you can also purchase the Unity source code that is written in c++ though that seems a bit overkill.

did some googlefu...
C++ is not a scripting language, and can only be used with Unity in the form of plug-ins (in the Pro version). C# is closer in syntax to C++ than Javascript is.
http://answers.unity3d.com/questions/12809/can-i-use-c-as-a-scripting-lanques-for-unity.html
(couldn't find anything that contradicted that)
although these might be of interest:
https://gamedev.stackexchange.com/questions/82518/is-it-possible-to-use-c-with-unity-instead-of-c
http://blogs.unity3d.com/2014/05/20/the-future-of-scripting-in-unity/

Related

Finding built-in Unity scripts

If one would like to look into the core files of the Unity Engine, e.g: I've tried using the unity in-built "Fog" effect, but would like to see how it works on a deeper level (code). Is this something one can find, or is it encrypted in some way?
You can try to take a look at Unofficial unity decompiled repo to check if there are sources you're looking for. It's a decompiled verison so there is no guarantee that it's the actual code. Also big part of Unity's sources is written in C++ and C# scripts just call this Unity's native C++ part, so it's really incomplete.
The other option is that some of big companies, Unity's partners which have highest support level, have access to official source code. So may be you're able to find someone with access to sources.

Can F# be used with Unity (game engine)?

I'm getting into Unity, and wondering if I can use F# instead of C#, simply because I prefer the syntax. I'm guessing not, since the environment it runs on is very different, but maybe there's something that will cross-compile code or something else I'm not thinking of.
I can't help but get the impression that the other answers were written by people who do not really know what they are talking about.
This is what you need to do to use F# in a Unity project:
Create an F# project that compiles into a dll. Have it build into the assets folder of a Unity project.
Add references to UnityEngine.dll and/or UnityEditor.dll. Change the reference properties so the dlls aren't copied to the build folder.
Of course you can't create new F# classes from within the Unity editor this way, but you can assign the ones you wrote in F#.
Currently you need to enable the (experimental) support for .NET-version 4.5. Alternatively you can download an older version of the FSharp.Core.dll that supports .NET 3.5. (see here).
I can't guarantee that you won't run into trouble because of compatibility issues with the FSharp.Core.dll, but that's just a guess since I haven't tested it myself.
I had success doing this sometime back by following this Github project: https://github.com/eriksvedang/FSharp-Unity, which I believe is roughly the same as Lars Kokemohr's answer above. I haven't tested it in more recent versions of Unity/Mono however.
Yes you can use F# as first class language as C# in unity.
Here is an article about it link
an excellent blog for One who want to use F# in unity
if you want to use F# as second class which I recommend.
let me show how to do it.
Usually what I do is to create Game Domain in F# in .net standard
2.0 library project build it.
Make unity API Compatibility level .net standard 2.0 then
Import library project dll in asset/plugins in Unity
Here is an explanation on how to do it automatically after each build : link
You will get this error, here is the solution
Having said that I recommend not to do any serious work in unity with F# because you won't be able to cross compile to other platforms.
Unity uses IL2cpp and it don't work with F#.
In simple words unity don't support F# and if you are having issues like bugs in Il2cpp unity will not fix it because they don't support F#
There is no easy way to do this but if you REALLY want to make it happen I believe you could use something like fs2cs:
https://github.com/hsharpsoftware/fs2cs
In theory you could write a script that calls fs2cs on all of your Unity C# files. Integrating this with Unity itself would be the more challenging part, but in theory you can trigger fs2cs transpilation on save of your file and Unity can use the transpiled C# file.
Only Boo, C#, and UnityScript are officially supported!

Can protobuf-csharp-port work on webplayer?

We can't call any dll on webplayer, but protobuf-csharp-port uses dll extensions, so seems that it doesn't work on webplayer. Anyone who can solve this problem?
In fact, you can use dlls in the webplayer as long as they contain pure managed c# code. You can't use native dlls written in c++ for example.
These dlls shouldn't use any kind of reflection as it is an excluded sub-assembly in unity webplayer.
I don't know if protobuf-csharp-port matches these constraints but if you are looking for a nice protocol buffer implementation, you can have a look at protobuf-net which is a very nice one, written in pure c#. There is a specific unity-compatible build in the distribution. You can even compile your protobuf serializers in a custom dll so no reflection is used to be webplayer compliant.

C++ static library to be used in XCode

This is probably not a simple question so I am not looking for a definite answer but just some pointers to get me in the right direction.
I have absolutely no experience with C/C++ but have good knowledge of Objective-C. I also don't know much about different compilers and architectures so please be nice if I am talking stupid :)
I have some MatLab code that needs to be ported to Objective-C to run on an iPhone application. My first tentative path to get this done would be to check if MatLab can export the code as a static C/C++ library that I can call from within my Objective-C code.
This seems to be the case but I am not entirely sure what to do next, and what things I need to keep in mind when compiling the library on the MatLab side (i.e. architecture, compatibility, PC vs Mac, etc).
I have been provided with a .DLL and .LIB files which I believe are Windows compiled so they will not be useful for me, is this correct? From working with previous static libraries I can see they all have a .a extension - what do I need to do to get one that is compatible with the iPhone architecture?
And once I get the library compiled, how to I import and use it within my project? Will I just be able to call the public methods directly from within my code?
What else do I need to know or be aware of?
Any help is very much appreciated!
Thanks,
Rog
Static libraries contain binary code tailored for some specific operating system and platform. That means that it will use the OS to internally acquire memory (if it uses dynamic memory) or to perform any other OS specific operation (logging, output).
Even if the generated code was completely OS-agnostic (basic math could be implemented without OS support), the platform is completely different, matlab will generate code for an intel platform and the iPhone runs in an ARM architecture, with a different instruction set calling conventions...
Unless matlab is able to generate static libraries for the iPhone or at the very least for an ARM platform and make it OS-agnostic, you are out of luck.

Can I code for iPhone in Vala?

I'm coding a game for iphone in ooc language (a new language that compiles to c) using OpenGL. It's really going well, and ooc is a language I really like. Now I've just found out about Vala and I don't get very well what it means that it relies on GLib and GObject. I've read in another question that Vala depends on GTK, but I don't think it does.
The question is: What I'm doing with ooc, could I do the same with Vala? Can I code in vala an OpenGL game for IPhone? And can be vala code used from c?
Thanks.
Vala's object orientation is implemented using the GObject library, which is part of GLib. It is possible to use Vala without objects, and therefore not requiring GLib, but there's not much point to that.
In any case, to access a C library from Vala, somebody needs to have written a VAPI binding (see Google) for that library. There probably isn't one for Apple APIs, so you'd have to write it yourself - if that's even allowed by the Apple license agreement.
You can find old version of native vala compiler and libgee for iOS in this repo: cydia.radare.org (valac version is 0.15, it is very old). UPD: valac 0.34.4 was added, which is relatively new.
It is possible to compile GLib for iOS, so having vala code compiled should not be a problem. The real difficulty here comes with the bindings as already mentioned, I doubt that someone already has VAPIs for iOS.