The ApplicationManager code

Inside the Chapter6Downloads.zip file, you will find the ApplicationManager.cs file. Of course, you can always copy and paste that into Visual Studio; again, I highly recommend that you type it yourself.

Here, we will go through each section and walk through the entire file.

First up, we have the Using statements. We have added a few: HoloToolkit.Unity, HoloToolkit.Unity.SpatialMapping, and HoloToolkit.Unity.InputModule. As I had mentioned previously, both SpatialMapping and InputManager are singletons and could not be accessed without these statements:

Here is where we make our own singleton out of the application manager. HoloToolkit.Unity has a declaration of Singleton instead of having to create one ourselves.

Of course, we have our input interfaces here, IInputClickHandler and ISpeechHandler:

Next up, we have our variable declarations. We have five references to objects where we want to control whether they are enabled or disabled, and the three bool that I am using as simple switches for this application:

Here is our start event and our first call to another singleton object--note InputManager.Instance as a sign of that.

Here, we are setting the InputManager to a modal mode so that when the user finishes scanning the room they can airtap or say done to move to the next part:

Speaking of parts, here we have our Update function, which is called by every frame. Here, we have an if statement looking at the spatialMapSet bool, which defaults to false:

If the statement becomes true (which happens after the user airtaps or says done), the Skeeball machine is set to active. Now, if this is the first time we have been through this part of the code, another If statement happens to check whether it needs to initialize Skeeball machine's position.

By default, the answer is yes, and so it gets the position of the camera and sets the Skeeball machine there and then moved it to 3.0f or 3 meters in front of and down 1.25f.

Once we are done positioning the Skeeball machine, we will set the toInit to false so that we are not continually positioning it.

If spatialMapSet is not true, the skeeBallMachine stays disabled:

If the skeeBallMachinePlacementSet is true, then turn all of your sounds on; otherwise, they should be off. This is set when the user places the machine on the spatial map:

Here, we have our illustrious input interface implementation.

If OnInputClicked gets called, it calls the SetSpatialMap function, as follows. If the word done is recognized, the exact same thing happens. However, it is a slightly different version of that function. You will note that eventData is passed to the function and then to the SetSpatialMap(); this event data is the word that the Keyword Manager recognized:

The SetSpatialMap function sets spatialMapSet to true. Then, we turn off drawing the spatial map mesh and remove the ModalInputHandler with a pop.

The second version of the function calls the first if the word that was recognized is done:

That is all there is for us to do to our application manager currently. It is simple right now. It will become a bit more complex as the rest of the chapters come to pass.

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

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