Unity 2020 Virtual Reality Projects
上QQ阅读APP看书,第一时间看更新

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 settings include GPU rendering settings, scripting compiler configuration, and optimizations.

In Unity, the word "player" is used in several contexts. There's the end user "player" of your game, the camera rig as a "first-person player," and the hand controller, which is sometimes referred to as the "player controller," But in Project Settings, "Player" refers to the program deployed on the target host platform that plays your Unity project, such as a media player that plays videos or a music player that plays MP3 files. Player Settings configures the deployed Unity player for the specific target hardware and system software.

It is a good idea to get familiar with these settings as soon as possible. With each new project, for example, you should set Company Name (defaults to DefaultCompany) and Project Name (defaults to the name provided when you created the project in Unity Hub). Android projects require a Package Name (for example, com.[companyname].[projectname]).

I will provide the details of the settings required per platform/device in the corresponding topics later in this chapter. We will adjust them occasionally in the projects throughout this book. Some settings are required for any build to be run. Others are only needed to be configured when you're preparing to publish to a store. These settings are organized into panels, including Icons, Resolution And Presentation, and perhaps the most important catch-all (modestly named), Other Settings. Explanations can be found in the Unity Manual at https://docs.unity3d.com/Manual/class-PlayerSettings.html.

Building, running, and testing your VR project

Depending on your target device, you may have a few more things to set up before you can build and run. These will be addressed in the device-specific topics that follow in this chapter. Then, when you're ready, simply chooseFile | Build And Run(or use theBuild And Runbutton in theBuild Settingsbox).

You may need to complete the setup of your project, according to the appropriate section later in this chapter, before completing the Build And Run steps in this topic.
I strongly recommend that you frequently test your VR scenes in a VR headset during development with Build And Run. Quick development and iteration using the Editor's Play mode is great for rapid development. But just because something seems to work in the Editor does not guarantee it will work in a build. Continue to build, run, and test frequently throughout development and especially after you've implemented any new feature in your project before you say it's "done."

The scene or scenes you can build are specified in the Build Setting dialog box's Scenes in Build list, as shown in the following screenshot. To add the current open scene, pressAdd Open Scenes. Alternatively, you can drag and drop a scene from theProjectAssets folder into the list. In multi-scene projects, the first one in the list will be the initial default scene that's loaded when your application starts; other scenes can be loaded via C# scripts by callingSceneManager.LoadScene (for scripting examples, see https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html):

When it's time to Build And Run, you'll be prompted to specify a folder for the build files. I recommend a folder namedBuilds/ in the root of your project.

If you're using Git for revision control, you can list the build folder in your .gitignorefile ( /Builds/) so that its content is not committed to your repository.

The following screenshot shows the built app running in VR with the default laser raycast hands:

The rest of this chapter will continue to set up Unity and your development system software for the specific platform and device you plan to target. Please skip to the specific section that is relevant to you.