Augmented Reality with Unity AR Foundation

Book description

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

Product information

  • Title: Augmented Reality with Unity AR Foundation
  • Author(s): Jonathan Linowes
  • Release date: August 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781838982591