Book Image

Augmented Reality Game Development

By : Micheal Lanham
Book Image

Augmented Reality Game Development

By: Micheal Lanham

Overview of this book

The heyday of location-based augmented reality games is upon us. They have been around for a few years, but the release of Pokémon Go was a gamechanger that catalyzed the market and led to a massive surge in demand. Now is the time for novice and experienced developers alike to turn their good ideas into augmented reality (AR) mobile games and meet this demand! If you are keen to develop virtual reality games with the latest Unity 5 toolkit, then this is the book for you. The genre of location-based AR games introduces a new platform and technical challenges, but this book will help simplify those challenges and show how to maximize your game audience. This book will take you on a journey through building a location-based AR game that addresses the core technical concepts: GIS fundamentals, mobile device GPS, mapping, map textures in Unity, mobile device camera, camera textures in Unity, accessing location-based services, and other useful Unity tips. The technical material also discusses what is necessary for further development to create a multiplayer version of the game. At the end, you will be presented with troubleshooting techniques in case you get into trouble and need a little help.
Table of Contents (17 chapters)
Augmented Reality Game Development
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Getting started with Unity


Unity is a great platform to start learning game development or even shipping a commercial game. It is the choice of game engine for many of the popular games in the Android or iOS app stores. So, what makes Unity such a great platform to develop games on? The following is a short list of things that make Unity such a compelling platform to develop games on:

  • It is free to get started: There is a ton of free assets or code you can use to build games. We will look at a number of free assets in this book.
  • Incredibly easy to use: You could likely build a complete game in Unity without writing even one line of code. Fortunately, you will learn some scripting and how to write code in this book.
  • Entirely cross platform: With Unity, you can develop on or for any environment that suits you. Of course, certain platforms, such as mobile, still have limitations and we will cover that as well.
  • Outstanding community: Unity has a hardcore base of developers who are eager to share experiences and help others. We will be sure to showcase many of the great community resources.
  • Asset Store: The Unity Asset Store can be an invaluable tool to build your first game or even your seventh commercial title. We will show you the deals and what to avoid.

Creating the game project

Let's get started by creating our sample game project Foody GO; we will also take this opportunity to build and deploy this starting project to your mobile device:

  1. Launch Unity and start a new project named FoodyGO. Make sure that 3D is enabled and disable Unity analytics. Of course, you will want to save your project in an easy-to-find folder, such as Games, just as shown in the following sample screenshot:

  2. Click on the Create project button and wait for Unity to open.
  3. In the Hierarchy window (top-left corner), you will see a scene named Untitled. Beneath that, there will be the Main Camera and Directional Light attached. Here is the screenshot of what you will see:

  4. First thing you will want to do is rename the scene and save it. So, go to File | Save Scene As...
  5. A save dialog will open, allowing you to choose where to save the scene. Just choose the default Assets folder and name your scene Splash. Then, click on Save.
  6. The title of the scene should now read Splash. Notice that there is also a new Splash scene object in the project Assets folder.
  7. Now let's adjust the Unity editor layout to match how our mobile game will run. From the menu, select Window | Layouts | Tall. Then, undock the Game tab from the main window by selecting and clicking the mouse while dragging the tab over. Then, resize the window so both the scene and game windows are roughly of the same width.
  8. Save the layout by opening the menu to Window | Layouts | Save Layout. Name your layout Tall_SidebySide and click on Save. This will allow you to quickly return to this layout later.
  9. Select the Main Camera by double-clicking on it, in either the Hierarchy window or Scene window. Notice how the Scene window will focus on the Main Camera object, and the Inspector window will display all the properties. This is what the Unity editor window should look like now:

    Editor layout for mobile development

  10. Before we go further, let's take a look at each of the main windows we will be working with in Unity:

    • Scene window: This window will allow you to view and interact with the game objects in the scene.
    • Game window: This is the players' view of the scene rendered by the main camera.
    • Hierarchy window: This shows a tree view of the game objects in the scene or scenes. In most cases, you will select or add items to the scene in this window.
    • Project window: It provides a view of and a quick way to access the assets in your project. Not much is in our project now, but we will quickly add some new assets in the coming chapters.
    • Inspector window: This view allows you to inspect and alter settings on game objects.
  11. Click on the Play button located at the top middle of Unity editor. The game will start playing, but nothing will happen because we only have a camera and a light. So let's add a simple Splash screen.
  12. In the Hierarchy window, select the scene. From the menu, select Game Object | UI | Panel to add a Canvas and Panel to the scene.
  13. Double-click on the Panel object in the Hierarchy window. This will focus the Scene window on the panel. In the Scene window, switch the view to 2D by clicking the button at the top of the window. This is what you should see now:

    Editor window with UI focused on in Scene window

  14. The panel in the scene window is a 2D UI element that allows us to render text or other content to the player. By default, the panel centers itself to the main view of the camera when it is added to the scene. This is why we see the semitransparent panel cover the entire Game window. Since we don't want a transparent background to the splash screen, let's change the color.
  15. Select the Panel in the Hierarchy window. Then, click on the white box beside the Color property in the Inspector window to open the Color settings. You will see the following dialog:

  16. Enter FFFFFFFF in the Hex Color field and then close the dialog. Notice how the background of the Game window is now opaque white.
  17. From the menu, select Game Object | UI | Text. In the Inspector window, set the properties of the Text to match the screen extract, as follows:

  18. Run the game by clicking on the Play button. Not much happens, but we now have a splash screen for our game. Don't worry, later in the book, we will add some pizazz to this screen. For now though, let's get this game deployed to your device.

Building and deploying the game

Now that we have the foundations of our game and a simple splash screen let's deploy it to your device. Nothing confirms your progress as a game developer other than seeing your game run outside the Unity editor. Follow the section that is specific to your device to complete the build and deployment.

Building and deploying to Android

As long as you have followed the steps for installation in the previous sections of this chapter, deploying your game to Android should be simple. If you do encounter any deployment issues, refer to Chapter 10, Troubleshooting. Follow the next steps to build and deploy to your Android device:

  1. From the menu, select Edit | Preferences. This will open the preferences dialog.
  2. Select the External Tools tab. Change or set the location of your Android SDK Path and Java JDK Path to the installation paths we made a note of when installing. Close the dialog when you are finished. The subsequent sample screenshot shows where you need to enter those paths:

  3. Select Edit | Project Settings | Player from the menu. Select the Android Settings tab and then click on Other Settings at the bottom of the panel. Set the Bundle Identifier to com.packt.FoodyGO as shown in the following screenshot:

  4. Make sure that your Android device is connected by the USB. Refer to the Connecting to your Android Device section earlier in this chapter if you are unsure.
  5. Open the Build Settings by selecting from the menu File | Build Settings. On the Build Settings dialog, click on the Add Open Scenes button to add the Splash scene. Ensure that you select the Android build from the list of build types. When you are all set and ready, click on the Build and Run button. This is how the Build Settings dialog should look like:

  6. A file save dialog will open the project's root folder. Create a folder called Build while you still have the dialog box opened. Open the new Build folder and save your build as com.packt.FoodyGO. The name should match the name we used for the build identifier earlier. Then, click on Save to start the build.
  7. Since this is the first build of the project, Unity will reimport all the project assets and other modules, which may take a few minutes. Subsequent builds should take less time, but if you change platform outputs, everything will need to be reimported.
  8. After the build completes, open your device. You will likely see the Unity screen loading and then the splash screen. Congratulations, you have deployed the game to your device.

Building and deploying to iOS

Assuming you followed the previous section, Setting up for iOS development, you should be able to already build and deploy the game to your device. Just follow the build and deployment steps again in that page to deploy the game to your device. Download the sample project for the chapter and deploy that to your iOS device.