Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Unity 2020 Virtual Reality Projects - Third Edition

You're reading from  Unity 2020 Virtual Reality Projects - Third Edition

Product type Book
Published in Jul 2020
Publisher Packt
ISBN-13 9781839217333
Pages 592 pages
Edition 3rd Edition
Languages
Author (1):
Jonathan Linowes Jonathan Linowes
Profile icon Jonathan Linowes

Table of Contents (15) Chapters

Preface 1. Virtually Everything for Everyone 2. Understanding Unity, Content, and Scale 3. Setting Up Your Project for VR 4. Using Gaze-Based Control 5. Interacting with Your Hands 6. Canvasing the World Space UI 7. Teleporting, Locomotion, and Comfort 8. Lighting, Rendering, Realism 9. Playing with Physics and Fire 10. Exploring Interactive Spaces 11. Using All 360 Degrees 12. Animation and VR Storytelling 13. Optimizing for Performance and Comfort 14. Other Books You May Enjoy
Setting Up Your Project for VR

Yeah well, this is cool and everything, but where's my VR? I WANT MY VR! Hold on, kid, we're getting there.

In this chapter, we are going to set up our system and configure our project so that it can be run with a virtual reality head-mounted display (HMD). This chapter is very nuts and bolts. Although Unity aims to provide a unified platform for create once, build many, you are still going to need to do some system setup, project configuration, and maybe even include object components specifically for your target devices. After the first couple of topics in this chapter, you can jump to the section(s) that address your specific target devices.

In this chapter, we will cover the following topics:

  • Using the Unity XR platform
  • Managing virtual reality plugins for your platform
  • Installing the XR Interaction Toolkit package
  • Creating...

Technical requirements

To implement the projects and exercises in this chapter, you will need the following:

  • A PC or Mac capable of running Unity 2019.4 LTS or later, along with an internet connection to download files.
  • A VR headset supported by the Unity XR platform.

Introducing the Unity XR platform

Unity's XR platform aims to provide the tools necessary to achieve the core principle of the Unity engine – "Build once, deploy anywhere" – for VR and AR projects so that you can target any number of different platforms and devices with a single version of your content. In the past, VR developers have been plagued by incompatible device-specific, vendor-specific, platform-specific SDKs and toolkits. Various other "solutions," both open source and proprietary, have had serious shortcomings and limited support. The XR platform architecture has a technology stack that enables direct integrations of multi-platform deep integration, new features, and optimization. The XR tech stack is shown in the following diagram, which has been taken from the Unity Manual's XR Plug-in Framework page (https://docs.unity3d.com/Manual/XRPluginArchitecture.html):

At the bottom of the stack...

Choosing your target VR platforms and toolkits

While much of your development will focus on the artwork, behaviors of game objects, and interactive game mechanics of your application, from the very beginning of your project, you should also identifywhich platforms and devices you are targeting. In ordinary Unity projects, it's often sufficient to simply choose the Build Settings target platform (for example, Android or Windows) and then configure Player Settings for build runtime options. But for VR, there's more. You need to manage the VR plugins you will need and use additional toolkit(s) for developing the project. Generally, your Unity VR project will need to include the following:

  • Select a Target Platform for your builds (for example, Android versus Standalone/Windows).
  • Install an XR Plugin that drives the VR devices.
  • Within your scene, you will include a VR-enabled camera rig for tracking head and hand locations in 3D space...

Enabling virtual reality for your platform

    The Diorama scene we created in the previous chapter was a 3D scene using the Unity default Main Camera. As we saw, when you pressed Play in the Unity Editor, you had the scene running in the Game window on your 2D computer monitor. We will now enable the project and scene so that it runs in virtual reality. These first couple of tasks are similar, regardless of which device you are targeting:

    • Setting the target platform for your project builds
    • Installing the XR plugin for our device
    • Installing the XRI package
    • Creating a VR enabled XR Rig camera rig

    We'll take care of these details now. After doing this, you'll need to set up your Unity project and development system software, depending on your specific target. This will include completing the following tasks, which we'll cover on a case-by-case basis in the rest of this chapter:

    • Ensuring...

Building and running your project

    It's always a good idea to actually build and run your project as early as possible in your VR development projects. A good first time to try is once things are set up. Then, you can continue to iterate the develop, build, run, and test cycle frequently throughout development. I'll remind you of this as we develop our projects.

    So far, you have set the target platform for your build, for example, as standalone Windows or Android. You've installed the XR packages and SDK required for your device. Finally, you've set up an XR camera rig in the scene using the XR Interaction Toolkit. Before you can build, you may also need to configure additional player settings.

    Configuring the player settings

    There are a wide variety of Player Settings you may need to configure, depending on your target platform.These control the runtime player that is deployed on the target platform and runs your Unity project. These...

Building for SteamVR

    This section describes how to set up and build your VR project so that it runs on a SteamVR supported VR device. VR applications that run on SteamVR are built using the OpenVR plugin. It can drive a variety of models of VR, including HTC Vive, Valve Index, Oculus Rift, and Windows MR devices; that is, basically all the major PC-based six degrees of freedom (6-DOF) VR rigs with trackable hand controllers.

    Before you get started, ensure you have your VR device connected to the PC and that you're running the SteamVR runtime. This may include installing the Lighthouse base stations for the HTC and Valve devices that require it. If you're running SteamVR for an Oculus Rift, you also need to be running the Oculus desktop app. Likewise, if you're running SteamVR for immersive Windows Mixed Reality (WMR), you need to be running the Mixed Reality Portal. Test that you can see and interact with the SteamVR Home in the headset.

    Setting...

Building for Oculus Rift

    This section describes how to set up and build your VR project on an Oculus Rift desktop VR device. Using a Rift requires the Oculus Windows app to be running, and in Unity, you'll build with the Oculus SDK. (Alternatively, you can build for OpenVR and run your Oculus in SteamVR, in which case, follow the instructions in the previous section instead).

    Using the Oculus SDK is required if you plan to publish on the Oculus Store or use any of the many advanced Oculus Integration platform features, including avatars, in-app-purchases (IAP), achievements, and more. See https://developer.oculus.com/platform/ for a list of features that are part of the Oculus platform solutions.

    Before getting started, be sure you have your Rift connected to a PC (or a Quest connected with an Oculus Link cable) and that you're able to see and interact within the Oculus Home environment.

    Setting up for Oculus desktop

    To target...

Building for Immersive WindowsMR

    This section describes how to set up and build your VR project so that it runs on a Windows Mixed Reality (WMR) immersive VR headset. This allows it to be run on Windows 10. You can choose to target Standalone / Windows in Build Settings or Universal Windows Platform for development. (Alternatively, you can build for OpenVR and run your WMR device in SteamVR, in which case, follow the instructions in that section instead). However, to publish to the Windows Store, you must build to target Universal Windows Platform.

    Microsoft's 3D media Mixed Reality strategy is used to support a spectrum of devices and applications, from virtual reality to augmented reality. This book and our projects are about VR. At the other end of this spectrum is the Microsoft HoloLens wearable AR device. Developing for MR requires that you're using a Windows 10 PC and have Visual Studio installed. At the time of writing, the minimum requirement...

Building for Oculus Quest

    This section describes how to set up and build your VR project on an Oculus mobile VR device, including Quest. Internally, these devices run Android, so developing from Unity has a lot in common with developing for any Android device. For VR, you set XR Plugin to Oculus and configure your project so that it builds and runs on the mobile VR device.

    Before we begin, ensure your device is in Developer Mode, as follows:

    1. Open the Oculus companion app on the phone connected to the device.
    2. Go to the Settings menu (lower-right corner).
    3. Select the device (for example, Oculus Quest).
    4. Select More Settings | Developer Mode and switch it on, as shown in the following screenshot:

    Next, we'll make sure you can build from Unity for a target Android platform.

    Installing the Android tools

    To develop VR apps that will run on Oculus Go and Oculus Quest...

Building for Google Cardboard

    This section describes how to set up and build your VR project for Google Cardboard on a mobile phone, including Android smartphones and Apple iPhones (iOS). With this, you set up XR Plugin for Google Cardboard and configure your project so that it builds and runs on the mobile VR device.

    Smartphone-based virtual reality is not as popular as it was when the previous editions of this book were written. Google no longer supports Daydream and has now open sourced the Cardboard SDK (https://github.com/googlevr/cardboard) as a baseline starter VR platform. Similarly, Oculus has dropped support for GearVR in its ecosystem. Nonetheless, Cardboard lives on, in both Android and iOS, as a fun and educational low-end VR display. The scene is displayed on the phone screen with separate left and right eye views that provide 3D stereographic viewing using a low-cost cardboard or plastic goggles with Fresnel lenses. Tracking is limited to three degrees of...

Summary

    In this chapter, you set up your system for VR development and built your project for your target platform and devices using the Unity XR Platform features. We discussed the different levels of device integration software and then installed the plugins and packages that are appropriate for your target VR device. While we have summarized the steps, all of these details are well documented in the Unity Manual and on the device providers' sites, so I encourage you to look at the relevant up-to-date documentation as you get started. Be aware that things have changed as of Unity 2019.3+, so be sure you are looking at the documentation pertinent to the version of Unity you are using.

    At this point, you should be able to preview your VR scene in Unity Editor's Play mode. You should also be able to Build And Run your project and install and run it as a binary directly on your device.

    In the next chapter, we'll do more work on the Diorama scene and...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Unity 2020 Virtual Reality Projects - Third Edition
Published in: Jul 2020 Publisher: Packt ISBN-13: 9781839217333
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}