Assisted discovery with spatial sound 

So far, we have allowed two or more users to share a space by sharing a single WorldAnchor; this allows everyone to see the hologram in the same place, but there is a slight issue we need to address. The placement of a hologram may not be obvious to the user who hasn't placed it. Currently, we just tell that user the hologram has been placed; of course, given this is a collaborative tool, we can assume the user who placed the hologram will explicitly or implicitly indicate where the hologram is placed, but assumptions are a sure path to a poor user experience.
What are our options? We can do either of the following:

  • Show a visual element to indicate the direction of the hologram if the hologram is out of view
  • Make a sound in the location of the hologram

In this section, as implied by the heading, we will tackle this challenge using spatial sound. But it's worth taking some time to briefly introduce spatial sound and acknowledge its importance for creating an immersive experiences.

Spatial sound provides the ability to simulate sound in a 3D environment, adjusting how the sound is perceived by the source direction and distance, complementing the holograms and making them seem more believable. Some common use cases for spatial sound include the following:

  • Increasing discoverability of holograms: just as we propose to do here, use spatial clues to help the user locate a hologram.
  • Audio haptics: an example here is using it as feedback to acknowledge a user action, such as selecting a hologram. 
  • Increasing immersion: it seems too obvious to highlight but we experience our world through all of our senses. Including more of these is going to more effectively immerse the user into the experience. 

By now, hopefully, you're convinced how important spatial sound is in creating a immersive MR experience and here we are just scratching the surface. With that being said, let's put the theory into practice.

Our approach will consist of a proxy, placing it in the location of the placed hologram before playing the sound. This will help the user locate a hologram they havn't placed.

Let's start by creating a proxy. This proxy will have an AudioSource attached when an object is placed (either by the user or by the shared WorldAnchor). We will relocate this proxy to where the object was placed the hologram and play a sound effect to indicate it has been placed. In the Unity Editor, create a new empty GameObject using the menu item GameObject | Create Empty and give it the self describing name PlacementSoundEffect. With the new empty GameObject selected, navigate over to the Inspector panel and click on the Add Component button. Type and select AudioSource and make the following changes: 

  • Check Spatialize 
  • Uncheck Play on Awake 
  • Drag the dial of Spatial Blend all the way to the right (3D) 

You might find that your AudioSource is missing Spatialize. This is disabled by default; follow these steps to enable it: 

  • Open the Audio project settings via the menu Edit | Project Settings | Audio 
  • Set Spatializer Plugin to MS HRTF Spatializer 

With our AudioSource now configured, let's assign the AudioClip. Within the Project panel, enter Placed into the search field. Once visible, click and drag onto the AudioSource--AudioClip field of PlacementSoundEffect. We are now ready to make some sound; open SceneManager in Visual Studio and make the following changes.

First we will add a public variable gain a reference to our audio proxy: 

    public GameObject placementSoundEffect; 

Next, we will create a helper method that will be responsible for playing the sound: 

 private void PlayPlacementSoundEffect(Vector3 position)
{
if (placementSoundEffect)
{
placementSoundEffect.transform.position = position;
placementSoundEffect.GetComponent<AudioSource>().Play();
}
}

Our method takes in the position of where we want the sound to be located and calls Play on the attached AudioSource of our audio proxy. 

There are three places where the object, potentially, gets placed; for each path we will make a call to PlayPlacementSoundEffect. The first method we will amend is the delegate handling object placement called by the PlacementManager. Locate PlacementManager_OnObjectPlaced and make the following amendments: 

 private void PlacementManager_OnObjectPlaced(BaseBlenderGameObject bgo)
{
...
...
PlayPlacementSoundEffect(bgo.transform.position);
}

Our last two methods are when a Blender object is created or updated as each of these could contain a WorldAnchor. Make the following amendments to both:

 private void BSM_OnBlenderGameObjectCreated(BaseBlenderGameObject bgo)
{
if (bgo.IsAnchored)
{
SceneStatus.Instance.SetText("");

if (bgo.GetComponent<WorldAnchor>())
{
if (PlacementManager.Instance.RemoveObjectForPlacement(bgo.name))
{
SceneStatus.Instance.SetText("Blender object placed", MEDIUM);
PlayPlacementSoundEffect(bgo.transform.position);
}
}
}
else
{
SceneStatus.Instance.SetText("Blender object ready for placementnAir-
tap on a suitable surface to place", MEDIUM);
PlacementManager.Instance.AddObjectForPlacement(bgo);
}
}
 private void BSM_OnBlenderGameObjectUpdated(BaseBlenderGameObject bgo)
{
SceneStatus.Instance.SetText("");

if (bgo.IsAnchored)
{
if (PlacementManager.Instance.RemoveObjectForPlacement(bgo.name))
{
SceneStatus.Instance.SetText("Blender object placed", MEDIUM);
PlayPlacementSoundEffect(bgo.transform.position);
}
}
}

It's that simple. Congratulations! This now concludes this example. As usual, build and deploy to the device to marvel at your hard work and, once finished, we will wrap up with a quick summary of what you've covered in this chapter. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.111.9