Getting Started with Bridge for Unity - Part 2

We’re continuing the series on Bridge development with Unity.
Last time Bridge For Unity - Part 1 we talked about the Mixed Reality sample.

This time we’re going to get started from a blank project, add all the GoogleVR bits, add BridgeEngine, then we’ll scan a physical space, pull that scan back into Unity, and dress it up.  This will get you experience mixing the real world with the digital.

new project

Okay let’s open up Unity, create a new project, and let’s call it “Awesome”.  Because we’re going to make it awesome.

Open up Build Settings, and we’ll pre-emptively switch to the “iOS” platform, Click “iOS” and “Switch Platform”. This will save us from importing all the assets a second time.

Now we’ve got our project ready, time to go find the BridgeEngine.unitypackage.
Double-click to open it.
Click “Import

Okay GoogleVR is missing, so click “Yes, Download

Setting Up GoogleVR

Open the Player Settings, go to “Other Settings” or “XR Settings” in the latest Unity releases, and look under “Virtual Reality SDKs” and add “Cardboard

We have to set up a few things to make the GoogleVR controller system work.
Look in “Assets/GoogleVR/Prefabs/UI” and add the GvrEventSystem prefab to your project

And now for a very important step… Add a “GvrPointerPhysicsRaycaster” component to the “GvrEventSystem” gameobject.  This does the actual work of ray casting to objects in your scene.

Finally add the GvrReticlePointer to your Main Camera.  This is the GoogleVR basic pointer that works even if you haven’t connected the bridge controller.

And that’s it for GoogleVR stuff.
Lets save our scene as “Main”

Setting Up BridgeEngine

Now let’s add the Bridge Engine components.

Open up the project folder “Assets/BridgeEngine”
Drag in the BridgeEngineMain prefab.

There’s not much to see here yet, so click on BridgeEngineMain, look at the Inspector and click “Rebuild @BridgeEngineScene

Voila, we have a starting scene as if we scanned it in ourselves.  More on that later…

Let’s move the main camera to a more useful starting position, Y=1  Z=-2
This is just for us to try things with the simulator. Your real world coordinates are exactly 1-1 with wherever you scanned.

Okay let’s place something in our environment.

Look in “Assets/BridgeExample/Models”

Drag and drop the “CarvedSideTable” to our scene
Add a “Mesh Collider” component to the table.
And turn on “Convex” so it’s a simple convex hull collider.

That’s it, save again.

Build and Scan

Let’s prepare to build on device.
Check out the last tutorial for the whole build and setup process.

Alright, put the iPhone into the Bridge Headset, plugin the sensor, and let’s scan.

Once we’re done scanning, we jump into the Unity scene we set up.  However you’ll notice that the CarvedSideTable isn’t in a useful starting location.  The scene we scanned is entirely different than the stock scene we started with.  For this tutorial, we’re actually going to take advantage of this fresh scan.

Using the BridgeEngineScene Folder

We can grab the BridgeEngineScene using iTunes.

Let’s plug in.  Click on the iPhone, and in the left column open File Sharing, select Awesome, and copy out the BridgeEngineScene to the desktop.

Switch back to Unity, and look at the BridgeEngineMain gameobject.
Look in the Inspector, and click to “Remove Imported BridgeEngineScene
Then click to “Import BridgeEngineScene folder...” and select the BridgEngineScene folder on the desktop.

Great, now we’ve got our scanned scene in our environment.  We can now place the CarvedSideTable exactly where we want it.

Build and Run, replace the project.

Load the scene.  Poof, exact 1 to 1 alignment.

Shopping for Assets

Okay great, the table is in the right spot,  but....  it’s not quite awesome yet.  Let’s go shopping on the Asset Store.  Search for “Party Streamers” there’s a “Confetti VFX”.  Let’s buy and install that.

Now I want some explosion sounds. Maybe search “Fireworks Sounds” ah, here’s some free sound effects called “Free Fireworks - Fire FX - Nova Sound”, that looks promising.  Let’s grab that too.

Now here’s the plan, we’re going to rig up a particle cannon on the CarvedSideTable. When we hover the pointer over the table and pull the trigger, Boom!  Play the sound and particle emitters.

Creating ClickBoom

Okay, activating something is going to take a bit of scripting. Create a Scripts folder for our project under Assets. Then create a new script called ClickBoom.  And open it up in the editor.

Okay, we start off wanting some common stuff from System.Collections, and UnityEngine.EventSystems

For ClickBoom to work, we require a Collider to tell if the pointer is hovering over the table.

Then a public slot for a triggerSound,
And add an array of particle emitters we want to play.

Add a holder for the audioSource.
And a bool for tracking when the pointer is hovering over the table.

Now on startup, we add an “AudioSource” that plays a sound coming from the table.

Then we add a couple EventTriggers that watch for PointerEnter and PointerExit, which basically  sets the hovering bool to true whenever the pointer is hovering over the table.

And we add a button event listener on the BridgeEngine onControllerButtonEvent.

The OnButtonEvent watches for the primary button down, and if we’re hovering, plays the sound and all the particle emitters.

Setting up ClickBoom

Right, let’s go back to Unity, and add the ClickBoom script to our CarvedSideTable.

Browse to the “Free_Fireworks” folder. And let’s use the “Deep Fireworks - Nova Sound” for our Trigger Sound.

Now add the particle cannon to our scene, look under:
Luke Peek/VFX/Confetti/Prefabs/Cannon with Ribbon.  
I’ll use “Confetti Cannon Ribbon - Shapes” here.
You’ll have to mess around, adjusting the Particle Emitter to a good speed and size that fits a room.

I turned offLooping” and “Play On Wake”, because we’ll play it with our script.

Click back to the CarvedSideTable, and add all the emitters to the ClickBoom “Emitters” array.

Hit “Play” in the simulator, and test that it all  works. 

Okay, now Build and Run.

For this tutorial I wanted to introduce grabbing materials from the AssetStore, I have no affiliation with Luke Peek nor Nova Sound, so apologies if you’d rather not buy the “Confetti VFX” though I think his kit is pretty awesome.  You can always create any old particle system you like and hook that up instead.

This is a production by Aaron Hilton of Steampunk Digital.   Thanks goes to Occipital for their collaboration and sponsorship of this video. If this is your first exposure to Bridge, you can grab a headset at: