Explore the world of augmented reality development with the latest features of Unity and step-by-step tutorial-style examples with easy-to-understand explanations

Key Features

  • Build functional and interactive augmented reality applications using the Unity 3D game engine
  • Learn to use Unity's XR and AR components, including AR Foundation and other standard Unity features
  • Implement common AR application user experiences needed to build engaging applications

Book Description

Augmented reality applications allow people to interact meaningfully with the real world through digitally enhanced content.

The book starts by helping you set up for AR development, installing the Unity 3D game engine, required packages, and other tools to develop for Android (ARCore) and/or iOS (ARKit) mobile devices. Then we jump right into the building and running AR scenes, learning about AR Foundation components, other Unity features, C# coding, troubleshooting, and testing. We create a framework for building AR applications that manages user interaction modes, user interface panels, and AR onboarding graphics that you will save as a template for reuse in other projects in this book. Using this framework, you will build multiple projects, starting with a virtual photo gallery that lets you place your favorite framed photos on your real-world walls, and interactively edit these virtual objects. Other projects include an educational image tracking app for exploring the solar system, and a fun selfie app to put masks and accessories on your face. The book provides practical advice and best practices that will have you up and running quickly.

By the end of this AR book, you will be able to build your own AR applications, engaging your users in new and innovative ways.

What you will learn

  • Discover Unity engine features for building AR applications and games
  • Get up to speed with Unity AR Foundation components and the Unity API
  • Build a variety of AR projects using best practices and important AR user experiences
  • Understand the core concepts of augmented reality technology and development for real-world projects
  • Set up your system for AR development and learn to improve your development workflow
  • Create an AR user framework with interaction modes and UI, saved as a template for new projects

Who this book is for

This augmented reality book is for game developers interested in adding AR capabilities to their games and apps. The book assumes beginner-level knowledge of Unity development and C# programming, familiarity with 3D graphics, and experience in using existing AR applications. Beginner-level experience in developing mobile applications will be helpful to get the most out of this AR Unity book.

Table of Contents

  1. Augmented Reality with Unity AR Foundation
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
  6. Section 1 – Getting Started with Augmented Reality
  7. Chapter 1: Setting Up for AR Development
    1. Technical requirements
    2. Defining Augmented Reality
    3. Getting started with Unity
    4. Installing Unity Hub
    5. Installing a Unity Editor
    6. Creating and managing Unity projects
    7. Introducing the Unity Editor interface
    8. Basics of using the Unity Editor
    9. Organizing your project assets
    10. Preparing your project for AR development
    11. Installing XR plugins for AR devices
    12. Installing the AR Foundation package
    13. Choosing an input handler
    14. Adding support for the Universal Render Pipeline
    15. Setting up for mobile development
    16. Setting up for Android/ARCore development
    17. Setting up for iOS/ARKit development
    18. Developing for wearable AR glasses
    19. Building and running a test scene
    20. Summary
  8. Chapter 2: Your First AR Scene
    1. Technical requirements
    2. Exploring the AR Foundation example projects from Unity
    3. Building and running the Samples project
    4. Exporting the sample assets for reuse
    5. Building the SimpleAR scene in your own project
    6. Creating a new project
    7. Importing the Sample assets into your own project
    8. Starting a new, basic AR scene
    9. Using AR Session
    10. Using AR Session Origin
    11. Using the AR Camera
    12. Adding Plane and Point Cloud managers
    13. Adding AR Raycast Manager
    14. Adding Light Estimation
    15. Building and running the scene
    16. Placing an object on a plane
    17. Setting up a PlaceObject input action
    18. Introducing Unity C# programming and the MonoBehaviour class
    19. Writing the PlaceObjectOnPlane script
    20. Building and running the scene
    21. Refactoring your script
    22. Creating a prefab for placing
    23. Understanding GameObjects and Transforms
    24. Finding a 3D model
    25. Completing the scene
    26. Summary
  9. Chapter 3: Improving the Developer Workflow
    1. Technical requirements
    2. Troubleshooting with log messages
    3. Using Debug.Log
    4. Using the Console with a mobile device
    5. Simulating a Console window in your app
    6. Debugging with a debugger
    7. Debugging on a remote device
    8. Testing with an editor remote tool
    9. Simulating with Unity MARS
    10. Capturing with the MARS Companion app
    11. Summary
  10. Section 2 – A Reusable AR User Framework
  11. Chapter 4: Creating an AR User Framework
    1. Technical requirements
    2. Understanding AR interaction flow
    3. Installing prerequisite assets
    4. TextMeshPro
    5. DOTween
    6. Serialized Dictionary Lite
    7. Other prerequisite assets
    8. Starting with a new scene
    9. Creating the UI canvas and panels
    10. Creating the screen space canvas
    11. Adding an app title
    12. Creating the UI panels
    13. Creating the UI controller
    14. Creating a Singleton class script
    15. Writing the UIController script
    16. Fading the UI panels
    17. Creating an Interaction Controller mode
    18. Creating the interaction mode hierarchy
    19. Writing the Interaction Controller
    20. Creating the interaction modes behavior
    21. The StartupMode script
    22. The ScanMode script
    23. The MainMode script
    24. The NonARMode script
    25. Testing it out
    26. Using the Unity onboarding UX assets
    27. Introducing the onboarding assets
    28. Preparing the Unity AR onboarding assets
    29. Installing dependency packages
    30. Importing the OnboardingUX package
    31. Writing the AnimatedPrompt script
    32. Integrating the onboarding graphics
    33. Creating a scene template for new scenes
    34. Summary
  12. Chapter 5: Using the AR User Framework
    1. Technical requirements
    2. Planning the project
    3. Starting with the ARFramework scene template
    4. Adding a main menu
    5. Adding PlaceObject-mode with instructional UI
    6. Creating the PlaceObject UI panel
    7. Creating the PlaceObject mode
    8. Wiring the menu buttons
    9. Performing a Building and Run
    10. Hiding tracked objects when not needed
    11. Advanced onboarding issues
    12. Making an AR-optional project
    13. Determining whether the device supports a specific AR feature
    14. Adding localization
    15. Summary
  13. Section 3 – Building More AR Projects
  14. Chapter 6: Gallery: Building an AR App
    1. Technical requirements
    2. Specifying the Art Gallery project UX
    3. Project objectives
    4. Use cases
    5. UX design
    6. User stories
    7. Getting started
    8. Collecting image data
    9. Importing photos to use
    10. Adding image data to the scene
    11. Obtaining the pixel dimensions of an image
    12. Loading the pictures list at runtime
    13. Creating a framed photo prefab
    14. Creating the prefab hierarchy
    15. Writing a FramedPhoto script
    16. Scaling the picture's shape
    17. Hanging a virtual photo on your wall
    18. Detecting vertical planes
    19. Creating the AddPicture UI panel
    20. Writing the initial AddPictureMode script
    21. Creating the AddPicture Mode object
    22. Creating a main menu Add button
    23. Build And Run
    24. Completing the AddPictureMode script
    25. Showing tracked planes in AddPicture mode
    26. Selecting an image to use
    27. Creating the SelectImage mode
    28. Creating the Select Image UI panel
    29. Creating an Image Button prefab
    30. Writing an ImageButtons script
    31. Reroute the Add button
    32. Adjusting for image aspect ratio
    33. Summary
  15. Chapter 7: Gallery: Editing Virtual Objects
    1. Technical requirements
    2. Creating an Edit mode
    3. Creating an edit menu UI
    4. Creating EditPicture mode
    5. Selecting a picture to edit
    6. Defining a SelectObject input action
    7. Replacing the MainMode script
    8. Selecting an object from Main-mode
    9. Wiring the Done edit button
    10. Highlighting the selected picture
    11. Selecting an object from Edit mode
    12. Avoiding intersecting objects
    13. Deleting a picture
    14. Replacing the picture's image
    15. Replacing the frame
    16. Interacting to edit a picture
    17. Ensuring FramedPhoto objects receive Input Action messages
    18. Adding the interaction components
    19. Using our finger to move the picture
    20. Pinching to resize the picture
    21. Summary
  16. Chapter 8: Planets: Tracking Images
    1. Technical requirements
    2. Understanding AR image tracking
    3. Specifying the Planets project
    4. User experience flow
    5. Preparing the planet cards
    6. Collecting planet textures and data
    7. Getting started
    8. Tracking reference images
    9. Adding AR Tracked Image Manager
    10. Creating a reference image library
    11. Configuring the user interaction modes and UI
    12. Scanning for reference images
    13. Build and run
    14. Creating and instantiating a virtual Earth prefab
    15. Creating the generic Planet Prefab
    16. Understanding equirectangular images
    17. Creating the Earth prefab
    18. Adding planet metadata
    19. Animating the planet's rotation
    20. Building the app's Main-mode
    21. Writing the PlanetsMainMode script
    22. Expanding the project with multiple planets
    23. Adding the planet card image to the Reference Image Library
    24. Creating the planet prefab
    25. Responding to detected images
    26. Making a responsive UI
    27. Creating the Main-mode UI
    28. Pointing the camera to show information
    29. Displaying information details
    30. Summary
  17. Chapter 9: Selfies: Making Funny Faces
    1. Technical requirements
    2. Understanding face tracking
    3. Face tracking versus face identification
    4. Tracking a face with AR Foundation
    5. Getting started
    6. Creating a new scene using the ARFramework template
    7. Setting up iOS ARKit for face tracking
    8. Importing assets used in this project
    9. Configuring a new AR scene for face tracking
    10. Setting the AR camera for selfies
    11. Adding an AR Face Manager component
    12. Prompting the user to find a face, or not
    13. Build and run
    14. Tracking the face pose with 3D heads
    15. Making a Mr. Plastic Head prefab
    16. Making a Mr. Facet Head prefab
    17. Building the Main mode and menu
    18. Creating a changeable face prefab
    19. Writing a main mode controller script
    20. Creating scrollable main menu buttons
    21. Adding a reset face button
    22. Attaching 3D Accessories
    23. Wearing a hat
    24. Sporting cool sunglasses
    25. Updating the scripts for accessories
    26. Adding accessories to the main menu
    27. Making dynamic face meshes with a variety of materials
    28. Exploring AR Default Face
    29. Creating face materials
    30. Adding a face mesh visualizer to the changeable face prefab
    31. Controlling the face material
    32. Adding face materials to the main menu
    33. Using eye tracking (ARKit)
    34. Attaching stickers to face regions (ARCore)
    35. Creating the sticker prefabs
    36. Managing attachments' positions
    37. Adding region attachments to the main menu
    38. ARCore-only UI buttons
    39. Tracking expressive face blend shapes (ARKit)
    40. Summary
    41. Why subscribe?
  18. Other Books You May Enjoy
    1. Packt is searching for authors like you