Teasure hunting, all the steps and explanations

Tutorial: Inclusive treasure hunting with and without vision! ***All the steps and explanations***

What do I need ?

              • a PC

              • a compatible smartphone (list available in the table at this link https://developers.google.com/ar/discover/supported-devices) and usb cable to send a file to the smartphone (otherwise bluetooth works but is longer)

              • a set of softwares to install, as explained step by step in the tutorial: Unity, Android Build Support, ARCore package for Unity, JDK, SDK Android (Android studio)

              • a audio file, MP3 for example, which will be the sound of your treasure (it can be a sound of sonar, a beep or a music).

              • Warning ! At your first use, you need the internet to create and connect to a Unity account to enable features

What does it do when it's over?

You will be able to scan flat surfaces (for example the floor), and touch the screen of your smartphone to put a virtual object: the treasure. This treasure makes noise, in 3D, which allows to find it.

Install Unity

We will now install Unity, which allows to create video games and applications.

Download Unity

Unity asks to install an installer (called Unity hub). It will be used to select the version of Unity to download.

Go to the Unity website on the https://unity3d.com/get-unity/download download page and click on "Select your version of Unity + download" (bottom left in the illustration)

Select the "Personal" version if you meet the criteria (mainly, you do not want to sell or make a profit with what you will achieve with it, nor that you would use it as part of your business) by clicking on "Try Personal" visible at the bottom right of illustration.

On the next page (illustration), check the box to accept the "Personal" conditions of use visible at the top of the illustration (the sentence starts with "by clicking,") and then click on the download button "Download Unity Hub "visible at the bottom of the image.

The download should start, save the file on your computer when it has offered you, by clicking on "Save File" if asked as shown in the illustration

Download on your PC

Open the downloaded file and accept the application to make changes on your device if prompted. The Unity installation wizard is open (illustration), you can click on "I accept" if the terms of use sound suitable to you, to start the installation of Unity Hub.

You will choose where to install Unity Hub. If the proposed installation location is ok for you, click on "Install".

Wait for the end of the loading bar. On the end of installation, verify that "Launch Unity Hub" is checked and press "Close".

If there is a security alert, uncheck everything and click on "Allow access".

Install on your PC

When Unity Hub opens, click on "Add" at the top right once you clicked on "Installs" in the left menu.

Choose a version: Unity 2018 ou 2017 ( on the image, Unity2018.4.0f1) ánd click on "Next".

You will now choose exactly what you will download. As shown in the illustration, I download Android Build Support which allows to create applications for Android smartphone and tablet later. Personally, I also install Vuforia that I use in other projects (tutorials to come).

Click on "Done" at the bottom of the screen.


Accept the software to make changes to your device if asked.

You can see the installation bar fills up in blue at the top, then says "Installing"

Wait for the end of the installation.

This step finished, you can close.

Launch Unity

Now you have to start Unity (by selecting it in your start menu or by clicking on the shortcut on your Windows desktop). The Unity icon is visible on the illustration.

Warning ! At your first use, you need the internet to connect to a Unity account (and create one if you do not have one by clicking on "create one") as requested (illustration). The next uses do not require connection, except if you want to download a Unity element (for example, a 3D element to decorate your world in the Assets Store).

Then select your Unity license (like Unity Personal if you meet the conditions) and click on "Next".

In the next step, select why you chose the previously selected license if it is requested, for example because it is not used in the professional framework at the bottom (as in the illustration) and then click on "Next".


Once activated, you can use Unity!

Prepare the necessary (the "video game" scene)

Part 1: Create an empty scene and understand the organization of the windows of the software


Create a new Unity project

Open Unity and create a new project.

To do this, open Unity by double-clicking the Unity shortcut on the desktop or opening Unity via the Windows Start menu. Unity can take a little while to open, it's perfectly normal. Once Unity is open, click on "New" (which means "New" in French) at the top right

Open Unity and create a new project.

You can call it "Chasse au tresor" (do not put any accent nor special character) in the Project name field. Then click on "Create project" to create the project at the bottom right.

The project opens with a new scene and several windows (illustration) .

Arrange and understand Unity windows

This passage is a question of personal preferences. Here is how I personally organize the Unity windows, which I will use later. Here's how: Go to the top right of your unity window and click on "Layout" then select "2 by 3", as shown in the illustration.

You can then drag-and-drop to position the "Project" tab under the "Hierarchy" tab. Then, drag and drop the "Project" tab under the "Hierarchy" tab. You can then save this tab layout in Unity by clicking on the same menu but choosing "Save Layout".


So you have (illustration) on the left, at the top the tab indicated as "Scene", and the tab indicated as "Game" below. In the middle is the "Hierachy" tab at the top and "Project" just below. On the right is the "Inspector" tab.

The "Scene" tab allows you to see the scene (often 3D) loaded into Unity and the objects in it. The scenes are environments where the game is going on. This can correspond to different levels in a game for example. For the moment, it is a new scene and it is almost empty (only a camera and a light as visible in the "Hierarchy" tab).

The "Hierarchy" tab allows you to see which objects ("Game objects" in the scene loaded in Unity and their organization). Here, we see that in the scene loaded at the opening (called "SampleScene") contains the necessary elements: a main camera ("Main Camera") and a directional light ("Directional Light") . A camera can create an image when you start a video game. The directional light allows to put the light (otherwise the camera will see only black).

What the camera sees is displayed in the "Game" tab.

The "Project" tab shows all the elements of the project, whether or not they are in the scene. There are even other scenes when there are several.

The "Inspector" tab allows you to have the information (to "inspect") on what you have selected, for example in the "Hierarchy" tab.

Part 2 : Laumch ARCore

ARCore is a package, i.e. a set of features that already exists and that we do not need to redo. We will now install a set of augmented reality features already existing: the ARCore package.

Only if you have Unity2019 installed: You have two more items to install. Go to Unity, in the menu at the top click on the Windows tab then on Package Manager: Window> Package Manager. Wait for the packages (list on the left of the window that opens) to load, and select "Multiplayer HLAPI" and "XR Legacy Input Helper." ". If you do not find them, you do not have Unity 2019, you can move on.

In all cases: We will download the ARCore SDK.

The SDK? That means 'Software Development Kit', and if you mix up a lot of letters that means that's all you need to do your own computer programs (here, all you need to do augmented reality with ARCore).

To get started, go to https://github.com/google-ar/arcore-unity-sdk/releases and scroll down to find the download file called arcore-unity-sdk-V1.9.0.unitypackage

Click on this link to download the file and save the file on your computer

Now that the package is downloaded, we will import it into the Unity project:

Go to the top menu in Unity and click on Assets, then Import Package, then click on Custom Package. In the window that opens, find and select the package you have just downloaded and click to open.

On the window that opens, verifythat everything is checked and click import at the bottom right (illustration), then wait for the import to finish.

Once the import is complete, go to the "Project" tab, in "Assets" click on the "GoogleARCore" folder, then on "Examples", "HelloAR" and finally "Scenes". In this folder there is an element (a scene) called HelloAR (illustration). Double click on it to open it.

An almost empty scene (illustration) is open.

Part 3 : Add a basic audio « treasure »

The idea is to make a treasure (to find by the player) that makes a sound louder and louder when we get closer, and a sound in the left ear that the object is on the left and so on.

We will create a first model of treasure (ie a cube that makes noise), it will be improve after making a first smartphone application.


Go to the menu at the top of Unity on "GameObject", then "3D Object", then select "Cube". This should look like the illustration.

In the "Hierarchy" window, right click on the cube, select "Audio" and then "Audio Source" (Figure 1). This adds this element to your cube, as shown in the "Inspector" window (Figure 2). An audio source makes it possible to make a audio object.

It is now necessary to copy the sound that will be attributed to the treasure (cube) in the project. To do this, open the folder on your computer with the sound you want to associate with the cube (for example, music on your computer). Once on this open folder, do a drag-and-drop: click on the sound file, click and drag the mouse while clicking to release it once your mouse is on the "Assets" folder in the "Project" window

By having selected "Audio source" of the cube in the "Hierarchy" window, we can see in the inspector an "Audio clip" field. Click on the circle to the right of the field, a window opens to choose a sound. Choose the sound that you will attribute to the treasure by double clicking on it (illustration).

Move the "Spatial blend" slider to the right so that the sound is a 3D sound as in the illustration (the 2D sound is a surround sound)

For the sound to loop, check the "Loop" box.

Now, let's define this object (cube + sound) as our treasure model. This is called a prefab. To do this, click on "cube" the "Hierarchy" window, and drag and drop on "Assets" in the "Project" window. Your cube appears in "Project" (illustration). You can delete the cube in the "Hierarchy".

In "Hierarchy", select "Example Controller". In "Inspector", click on the circle to the right of the "Andy plane prefab" field and select the "Cube" prefab by double clicking on it in the window that opens (illustration).

Save your scene in Unity by going to the Unity menu "File" "Save". There is "just" to do the application on Smartphone!

Create the smartphone app:

Install the necessary to make Android smartphone application


But, why does not it already work directly on a smartphone?

We can make the metaphor between different operating systems (Windows, Android), with climates (Windows = tropical climate, Android = temperate climate). Your program on Unity is a plant, so tropical. Put it on the temperate climate of Android, it will not work. So there are two solutions: make a transplant on a foot that supports temperate climates (this is what we do in this part). The other way (that we avoid here) is to make a greenhouse to make the plant believes that we are under tropical climate, i.e. to believe that we are under Windows when we are under Android (this is the principle of the virtual machine).


Let's go back to our application: we will make sure that our application-plant is adapted to Android, while we are not at all on Android because we are on Windows. We will already prepare the ground to have a foot on which to graft our Windows version. And then we will pack the grafted plant to be able to send it to our Android-Temperate Zone.

.

Part 1: Install the JDK

The first step is to install the JDK on your computer, which means 'Java Development Kit', and if we mix lots of letters it means that it's all that we need to make its own computer programs using Java, and Android is based on Java. So the JDK is the compost, we will be able to put our base for the graft just after.

For this go to https://www.oracle.com/technetwork/java/javase/downloads/index.html, and click on the square with marked Java, and "jdk" shown below (illustration).

On the next page, scroll down to see the download links for Windows.

Click on "Accept License Agreement" to accept the license if it suits you, then click the Windows link ending with ".exe"

Save the file to your computer (illustration) then open this file.

If you are asked if you want this file to make changes to your computer, click "Yes" or "Accept". Click on "Next" on the window that opens to install the JDK (illustration).

The next page asks you if you want to change the location of the installation. If the location suits you, click on "Next".

Wait for the end of the loading bar.

You can then press "Close" to close the installation wizard. Good news, the potting soil is ready!

Part 2: Install the Android SDK (Android studio)

Another SDK? It always means 'Software Development Kit', and if you mix up a lot of letters it means that it's all you need to do your own computer programs (here, everything you need to run Android) .

We have the soil (the JDK), now we will need the base to transplant your plan. So we will install Android Studio.


Go to the https://developer.android.com/studio page and go down to the "Android Studio Download" section, and click on the link ending by ".exe" on the Windows line.

If you agree with the terms of use, check the "I have read and agree with the above terms and conditions" box, then press "DOWNLOAD ANDROID STUDIO FOR WINDOWS"

Then save the file to your computer

Once the file is saved, go to the folder where the file is downloaded and double click on it to launch the installer. If you are asked if you want this file to make changes to your computer, click "Yes" or "Accept".

On the first page of the installation wizard, click "Next".

In the "Choose Components" window, keep selected Android Studio, the second point is not mandatory. Then click on "Next".

The next page asks you if you want to change the location of the installation. If the location suits you, click on "Next".

In the next window, click on "Install".

Wait for the end of the installation, which you can follow through the progress bar (illustration).

Finally, uncheck "Start Android Studio" and click on "Finish".

Part 3: Configure Unity

We will now tell Unity where Android SDK Tools is installed just before.

You have to go to Unity, Edit menu at the top, then click on "Preferences"

In the window that opens, go to "External tool" and in the "Android" section, click on "Browse" and navigate to the folder where the Android SDK was installed, then click on "Select folder".

You can close the window.

Let's go back to the metaphor of the plant. We have our original plant (our project Unity), our soil (the JDK), our plant for the transplant (the Android SDK). Now, we will do the transplant and pack it for transportation. In practice, we will create the installation file of the Android application (build), to download it on the smartphone and install the application.


In Unity, open with your treasure hunt project open as well, go to the "Files" menu and select "Build Settings".


In the window that opens, you have four things to do: (1) select "Android" from the menu on the left, and (2) Press "Add open scene" at the top right, then click on "Switch Platform" At the bottom (illustration). (3) Wait until the "Switch Platform" is finished, this operation is used to create the installation file of an application (apk file). Finally, (4) click on "Player settings".

In "Player settings", we will define the necessary information for the application. You can put your name or the name of your institutions (instead of "Default Company"), the name of the application as it will be on the smartphone is to indicate just below, do not put any accent or special characters . You can choose a project image for the application icon on your smartphone in the "Default Icon" line

Scroll down to see "Other settings" section "identification". The "Package Name" line must be modified: it must be personalized and unique for each application. Choose a name, for example "Com.MyName.ChasseAuTresor". For "Minimum API Level", choose from which version of Android the application will work. ARCore that we use runs from Android 7.0 Nougat (API level 24), that's what to select. For "Target API level", choose "Automatic (highest installed)"

Scroll down and click on XR settings, then check the "ARCore supported" box

Put the app on the smartphone

Part 1: Create the application installation file

We will now create the installation file, then put on your smartphone.

Back in the "Build Settings" window, click on "Build". Choose where to save the apk file and its name, for example AppTresor.apk.

Wait until the progress bar is finished, it may take several minutes.

Part 2: Prepare your smartphone by installing ARCore

First, install via Google play the application "ARCore of Google" on your smartphone.


Once this is done, send the file of your application (AppTresor.apk) to your smartphone, via USB cable or Bluetooth, and once downloaded open it on the smartphone. Follow the instructions to install it: it's done!

Part 3: Use

Launch your "Treasure Hunt" application on your smartphone: you should find the application on the menu of your smartphone.

Once launched, direct the camera at the ground or a flat surface to see a mesh appear (indicating that the application has detected the surface). Touch the screen where there is mesh, and the "treasure" appears where you touched the screen.

Use headphones or headphones. The sound is as if the smartphone was the head: tilt the smartphone is equivalent to turning the head, approaching or moving the smartphone makes the sound more or less strong.


Having a "real" treasure

The Asset Store

In order to have cooler elements than cubes, there are some elements ready to download, free or not, which are called assets. We will be able to download these assets on the Asset Store.

In Unity, go to Window, and select "Asset Store".

In the window that opens, look in the search bar at the top "treasure" and press "enter".

Click on "pricing" at the bottom right, then move the circle on the right on the left to the slider to keep only free objects

Click on an object that you like, for example "Treasure Set- Free Chest".

On the pop-up that opens, press "Download"

Log in to your Unity account (the one used for installation) if requested, and press "Import" once the download is complete, then click on "Import" again in the window that opens.

Click on the "Scene" tab to return to it.

In the "Project" tab, select the folder you just imported, here "ChestFree" and find the treasure prefab, here "Chest_open"

Drag and drop this prefab into the "Hierarchy" tab

If you want to add coins to the treasure with ChestFree, find the item "corners" a little lower, drag to "chest_open" in the "Hierarchy" tab. Still in "Hierarchy", click on "corners" below "chest_open" then in the tab on the right "Inspector", put the Positon, and the Rotation to 0 everywhere, and Scale to 1 everywhere.

To be sure that your object will be in the right direction, in the "Hierarchy" tab, right-click and select "Create Empty". This will create an "empty" object, probably called "GameObject".


Drag your treasure object "chest_open" onto this "GameObject". "chest_open" appears below "GameObject".

Now, we have to redo as with the cube: we add an audio-source with a sound, then we transform the object into prefab, and we remove it from the "hierarchy", and finally defines it as the prefab to use in Controller example.


Go to the Files menu and click Save As to save the scene under a new name, so you will not lose the first version.

Generate a new installation file (apk), and reinstall it on your smartphone.

It is finished!