22 Dec 2012

Automagic Unity Android Java gadget OF DOOM!

Ok maybe not that dramatic, but pretty handy if you’re working with Unity Android and doing some Java plugin work.

I hadn’t really touched Unity Android specific code since setting up automatic testing of it, so a few months back I wanted to remedy that by diving in head-first with an obvious not-hello-world sort of project.

For christmas of 2011, my awesome parents had bought me a IOIO board1. I wanted to push some more boundaries of mine and do some hacking which couldn’t all be contained in an email attachment and the IOIO seemed a great start for that.

In short, the IOIO board is a small, inexpensive IO board with a USB interface and Android drivers – allowing you to connect your Android phone to it and control its 48 IO ports from software running on that phone.

Obviously I had to write that software as a Unity project and I hope I’ll get some more time to polish up the last bits of the soft- and hardware for it soonish and tell you some more about it.

Anywho, that’s enough background. Long story short, I obviously started out (after consulting the Unity documentation on how to work with the Java interface with Unity Android which I would need to access the IOIO driver) by doing some editor scripting to reduce my iteration time on the Java I needed. Wisely I predicted that my Java would be so terribly rusty that I would need a significant number of iterations.

Basically what I wanted was to get rid of the multiple steps needed for compiling, signing and assembling a Java plugin. Initially I just hacked together a perl script to reduce those steps to one line of shell execution, but that still meant more context switching than I wanted.

So I leveled up the hack by having a Unity asset post processor automatically execute the perl script whenever a Java file got imported in the plugins directory – re-routing any output from it to the Unity console.

That was really awesome. I would make a change in my Java, save it, switch to Unity and see all my horrible compiler errors right there in the console. And as this was my only Android project, I was quite happy with my hack – proceeding to kill my compiler errors and build my IOIO project.

Some friends had been poking me about cleaning up and generalising the hack a bit more and luck would have it that in my christmas vacation I spent a lot of time being sick. So I used some time here and there to clean up the Unity Android plugin builder and yesterday I pushed it to github – without any project specific bits, without perl and somewhat more user friendly.

Check it out and let me know what you think. If anything is broken or you’d like to request a change or addition, please use the github issues feature:

1 The IOIO board

Unity Protocol Buffers
Behave 2.7
Behave 2.6
Trusted Gear
Mad Mash Versioning
Behave 2.5
Behave 2.4
The Engine Wars: Numbers
GDC 14: The Quest For Fun
Moving in Unity
Behave 2.3
Unity and .net assemblies
Behave 2.2
Behave 2.1
Behave 2.0
Unity Hacks: Dual sticks
Unity Hacks: Cameras
Unity Hacks: Touch gestures
Unite 13 video "Unity Hacks" available
The implicit local network interface
Talks and progress
Five years of Unity expertise looking for contracts
Automagic Unity Android Java gadget OF DOOM!
Invading Planet from your couch
Mountain Lion and laggy bluetooth and duct-tape
Unite 12 video and new videos section available
Asia Bootcamp videos now available
Path is now MIT licensed
Behave 1.4 released
So I've been a bit busy lately
Behave 1.3 released
IGDA Unity SIG slides
Second Unity IGDA SIG this evening: Scene construction and AI
First IGDA Unity SIG this evening
Alternative licensing available
Pathfinding in two lines
Path 2 released
Assembling and assimilating
Path 2 intro screencast
Path 2 beta release for GGJ
AIgameDev master class video now online
Expanding beta
Behave AIgameDev master class public stream
Behave master class on open AIgameDev stream tomorrow
Interview with AIGameDev
New video: From tree to code
Issue tracking on github Behave release project
IT University Copenhagen Unity course completed
IT University Copenhagen Unity course files Thursday
CPH IT University Unity course files
Behave 1.2 released
Video: Behave - starting from scratch
Behave runtime documentation updated
Behave 1.1 released
FAFF cleanup: Sketch
Building a menu of delegates and enums
Pick me! Pick me!
Optimising coroutine yielding in C#
Downloading the hydra
New license of Path: GPL
GUI drag-drop
Logging an entire GameObject
I bet you can't type an A!
Where did that component go?
New and improved: Behave 1.0 released
Behave 0.3b and unity 2.5
Behave 0.3b hotfix
Path tutorial video available
Path 1.0 launched!
Continued community tutorials
Community tutorial
New tutorial
First tutorial available
Behave 0.3b
unite '08 open-mic session
Behave 0.2b
Behave 0.1b
Behave pre-release
Path beta 0.3b
Path beta 0.2b
Path beta 0.1b
Path pre-release