Configuring and building the Unity project

Unity supports many target platforms. Switching to a new target is easy as long as our plugins support it. We just need to set a few build configuration values, some of which are shared across multiple targets and some of which are platform-specific.

From the menu bar, select Preferences under Unity, which should bring up the Unity Preferences window. Click on the External Tools tab and set Android SDK Location to be the base path to your Android SDK installation. (We referred to this location as <android_sdk> in the Tegra Android Developer Pack section of Chapter 1, Preparing for the Mission.) Recent versions of Unity support API level 9 (Android 2.3) and newer versions, so you probably already have an appropriate API version installed with your Android SDK. Now, the window should look similar to the following screenshot:

Configuring and building the Unity project

Now, from the menu bar, select Build Settings under File. The Build Settings window should appear. Drag all of the sample scene files, such as Samples/OpenCVForUnitySample.unity and Samples/ComicFilterSample/ComicFilterSample.unity, from the Project pane to the Scenes In Build list in the Build Settings window. Ensure that OpenCVForUnitySample.unity is the first scene in the list. (Drag-and-drop list items to reorder them.) Also ensure that all the scenes' checkboxes are checked. Click on the Android platform and then the Switch Platform button. The window should now look like what is shown in the following screenshot:

Configuring and building the Unity project

Click on the Player Settings… button. A list of settings should appear in the Inspector pane of the Unity Editor. Fill out a Company Name, such as Nummist Media Corporation Limited, and a Product Name, such as Rollingball. Click on Resolution and Presentation to expand it and then, for Default Orientation, select Portrait. Click on Other Settings to expand it and then fill out a Bundle Identifier, such as com.nummist.rollingball.

Ensure that an Android device is plugged in and that USB debugging is enabled on the device. Go back to the Build Settings window and click on Build and Run. Specify a path for the build. It is good practice to separate the build path from the Unity project folder, just as you would normally separate builds from source code. Once the build begins, a progress bar should appear. Watch the Console pane of the Unity Editor to be sure that no build errors occur. When the build is finished, it is copied onto the Android device and then it runs.

Enjoy the OpenCV for Unity samples! If you like, browse their source code and scenes in the Unity Editor. Next, we have our own scene to build!