Project setup

In this section, we will walk through the details of the starter project and accompanying components before extending it across the network. If you haven't already, clone or download the repository for this book from https://github.com/PacktPublishing/Microsoft-HoloLens-By-Example. The project we will be working on is located in the Starter folder within the Chapter8/Starter directory. Once cloned, launch Unity and load the Unity project. Once loaded, you should see the familiar setup and components we have been using throughout this book:

To help you get acquainted with the project so that you can confidently navigate around, we will spend the rest of this section walking through the scene components and project files:

  • MainCamera: Something you will be familiar with now, this is our Holographic camera.
  • AppManager: This GameObject comprises of the component related to managing the game, including some related to user interaction. When you inspect it, you will see the AppManager, TeamManager, GazeManager, AnchorSyncManager, and InputManager (script) components. AppManager is responsible for orchestrating the game state. TeamManager is responsible for keeping track of the teams (where each user will have their own team) and associated players (here, referring to the virtual characters, aka the members of the squad). GazeManager, which you are no doubt familiar with now, is responsible for tracking the user's gaze and is used by the Cursor to update its position and orientation. The AnchorSyncManager is something we will be working with quite a bit and is responsible for exporting and importing the class WorldAnchor. We will cover this further as we move ahead. Finally, we have InputManager, a simple script to listen out for the tap gesture, and notify its observers when detected. 
  • Cursor: The visual representation of the user's gaze--something we've used extensively throughout this book.
  • SpatialMapping: Something you will also be familiar with, with the addition of the PlaySpaceManager script that is responsible for coordinating the construction of planes from the observed surfaces and notifying interesting parties (AppManager) when a sufficient horizontal surface area has been found.
  •  NetworkManager: This GameObject comprises of the components responsible for networking discovery and communication. We will return to this shortly to describe how it works in detail.
  • TapIndicator: This is a simple visual element to show that the user has tapped when moving their squad around the floor.

Also noteworthy are the following prefabs:

  • Bullet: This is the prefab used as a bullet. It's simple a cube with a Rigidbody and Collider attached, along with a script to manage its own state, and it notifies a Player GameObject if a collision occurs.
  • PlayerS and PlayerC: These are the squad members that the user controls. PlayerS will be used by the user who assumes the role of the server, and PlayerC will be the client. Here, there's a subtle difference in texture, but it can easily be swapped out with different models.

Unlike the earlier chapters where we built up some classes from scratch, because we won't be introducing any new concepts related to HoloLens here, we will instead be making amendments to the existing scripts (places annotated a // TODO comment).

We will start at the bottom, implementing the networking component starting with discovery, connectivity, and then coordination.

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

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