My first attempt with integrating Kinect and Unity with out of the box solution named KinectVR didn’t go well. So I decided to look for another alternative, and found a [similar project based on OpenKinect][2] library (libfreenect). But of course it didn’t compile on my system, which caused me doubt my workspace. The real feeling that was annoying me is that there are so many things I don’t understand how they work in Unity. For example the C# scripting and how things are related and triggered. I was afraid they might be practicing witchcraft, A.K.A [Convention over Configuration][3] like Rails. This drove me to do Unity [tutorial Roll-a-Ball][4] which I have to say was very good and fun. It was also a great method to clean start my workspace.
Getting started with Unity in Linux
- Download the [latest compiled version][5] of Unity for Linux
In theory you might be able to build Unity from source, but I didn’t find a guide for it.
Go to the last post in the thread, and you will see a link like this one: “http://beta.unity3d.com/download/45784aaa9968/public_download.html”
Download the “Platform-Agnostic Self-Extracting Shell Script”, I got a file named ‘unity-editor-installer-5.4.2f2+20161111.sh’
- Install Unity:
1 | chmod +x unity-editor-installer-5.4.2f2+20161111.sh |
Next, edit the desktop files and adjust the path to where you install Unity:
$HOME/.local/share/applications/unity-monodevelop.desktop
$HOME/.local/share/applications/unity-editor.desktop
For example $HOME/.local/share/applications/unity-monodevelop.desktop
:
1 | [Desktop Entry] |
You should be able to find Unity where you find all your other applications. If you want to start Unity from command line, call it directly: ~/Unity/Editor/Unity
or add it to your PATH (out of scope for this guide).
- Run and configure Unity
Start Unity Editor from your application menu or from the command line. To verify that everything is in order, create a new project, like showed in [Roll-a-Ball tutorial][6]. Create a script in the project, like demonstrated in the next tutorial of [Roll-a-Ball][7], and try to open it.
If for some reason it doesn’t open, configure Unity to use unity-monodevelop manually, by going in the menu to: Edit -> Prefrences -> External Tools
Then click on the drop list of External Script Editor
and select browse
. Enter ~/Unity/MonoDevelop/bin/monodevelop
, or wherever you installed Unity. Now its possible to use other editor or globally installed MonoDevelop with package manager, but Unity people configured it to work with Unity well, for example auto-complete C# and nice help quick search. Trust me, I prefer using VIM, and I’m working on making it happen but we are getting started here, right?
- Version Control it
I think that any modern project must have version control, as its the only way we can collaborate and effectively debug issues. My personal favorite version control system is Git, but the following changes easily can be adjusted for any other system. Unity by default stores configurations and other 3d data in binary form. This maybe improve performance on large projects but its a critical blow to version control, as it takes a lot of storage and impossible to version it. So in any project you start working with, you have to do the following:
- [Make everything in text][9]
Editor → Project Settings → Editor → Asset Serialization Mode: Force Text
- Ignore temporary and other not to be version controlled files in [
.gitignore
][10]:
1 | =============== |
- [Smart merge things][11]
Add the following text to your .git/config or .gitconfig file:
1 | [merge] |
Adjust the cmd setting above to the correct path of Unity.
Getting started with OpenKinect
- Compile from source
The OpenKinect library comes with very useful tools and wrappers, and if your OS provides the library, it probably doesn’t come will all the tools and wrappers. In our case we will need the C# wrapper, and for development it would be nice to use fakenect a simulator of Kinect.
- OpenCV - optional (if want python wrapper too)
My favorite language is Monty Python, so I prefer having Python wrapper just in case, we are getting started here, right? Python wrapper example require import of cv library, however it was deprecated from latest major version (3) of OpenCV. The problem is that OpenCV 2 is not available in Pip or in your package manager (probably), so we have to [build it ourselves][12][13]:
1 | # Install requirements(maybe you don't need everthing, or maybe you need more?): |
You can verify this works with running: python -c "import cv;print cv.__file__"
- Configure and Build libfreenect
The process is pretty [straight forward][8]:
1 |
Follow the instructions of [Fetch & Build][9] 2. Test and verify
Example Unity project with OpenKinect
Running the built project for Linux: mono my_project.x86_64
[2]: [3]: https://en.wikipedia.org/wiki/Convention_over_configuration [4]: https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial [5]: https://forum.unity3d.com/threads/unity-on-linux-release-notes-and-known-issues.350256/ [6]: https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial/setting-game?playlist=17141 [7]: https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial/moving-player?playlist=17141 [8]: https://openkinect.org/wiki/Getting_Started#Manual_Build_on_Linux# [9]: https://docs.unity3d.com/Manual/class-EditorManager.html [10]: https://unity3d.com/learn/tutorials/topics/production/mastering-unity-project-folder-structure-version-control-systems [11]: https://docs.unity3d.com/Manual/SmartMerge.html [12]: http://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html [13]: http://docs.opencv.org/3.1.0/dd/dd5/tutorial_py_setup_in_fedora.html