This workshop will show you how to:

Final

Open Gauges - Noise Gauge with Stand by vsigno is licensed under Creative Commons Attribution.

To complete this workshop you will need

To build on iOS

Hardware

Additional resources

Unity is a powerful cross-platform Game Engine System. While it was originally developed as a general-purpose engine to create videogames, in the last 15 years Unity has become widely used also outside the gaming industry and it is now an effective tool to develop high-quality architectural and urban visualisations and virtual tours, advanced simulations using machine learning, real-time exhibitions and art installations, to cite some.

Depending on the type of application intended to develop, the use of Unity requires a diverse set of skills that goes beyond the programming ones. Nevertheless, thanks to the flexibility of the system, and an extremely active community, it is possible to access an incredible number of tutorials, plug-ins, extensions and ready-made projects and assets that make the system accessible and the learning curve less steep compare to other similar software systems.

Unity can be installed on Windows, macOS and Linux, and it can be used to create applications for PC, Mac, Web, Mobile systems, VR headsets and Consoles.

The easiest way to install Unity, and to manage multiple projects, is through the UnityHub

Unity Hub installs screen

Once UnityHub is installed, log in with your student account and activate the licence.

During the module, we will use the version Unity 2022.3 LTS.

The Recommended Release is the most recent one. It is generally safe to install latest minor release (i.e. 2022.3.xxf1). In case a previous version is needed, it is possible to download it from the download archive

Unity Hub installs screen archive

Platforms

Before beginning the installation process, we need to select the platforms we intend to use for compiling our applications. Any additional platform can be added also at a later stage.

Choose the Platform

While it is possible to use Visual Studio as Dev tool, we recommend using VSCode as it is a lighter and faster solution, and fully supported in Unity on Windows and macOS.

Depending on your operative system, install the following platforms:

Select also the mobile platform that you intend to use:

Setting up the Dev environment

Once Unity is installed we can set up the Dev tool, VSCode.
First of all, we need to install the VSCode Unity Extension and .NET SDK 7.0.11. VSCode will tell us if .NET SDK is missing or not.

VSCode Unity Extension

New Project

Create a New project using Unity Hub, be sure to use the right Unity version if multiple installations are present. Unity provides different Templates that helps to setup the interface and install the essential packages. In this example select 3D Core template. Give a name to the project and set its location

Choose the Unity Template

It will take a couple of minutes to create the project and you should see this interface when is done... Welcome to Unity!

Unity interface

Let's finish the setup of the DEV environment:

package manager visual studio editor

Open Edit -> Preferences (on MacOS, Unity -> Settings) and in External Tools control that Visual Studio Code is selected in External Script Editor

Setup the External tool

If you installed correctly the Android SDK and NDK, on the same screen you should see their location paths.

To test if VSCode is installed correctly, create a new C# Script from Assets - > Create -> C# Script

Create a new C# script

Give the name myScript or keep the default name and double click on it. VScode should open automatically.

After few seconds the project will be loaded and IntelliSense will be ready to use

VSCode Extension

The purpose of this section is to introduce you to the basics of Unity Editor interface and the main concepts used by the game engine.

Open the Unity project. The layout of the Unity Editor can be customised using the default templates from the top-right dropdown menu, or personalised by dragging the tabs around the screen. This is just one of the suggested layouts

Branch the repo

Scene view and Game view

This is the interactive window of your project. The Scene view is used to manipulate objects and view them from various angles. A selected object will appear highlighted and with the 3 axis gizmo apply to it. Next to the Scene view is the Game view. The Game view displays the main camera view (if present). In this view you can preview your application.

Hierarchy window

The Hierarchy is where you organize all the elements that are part of the Scene. These elements are called GameObjects. If you add a GameObject to your project in Scene view, it will be listed in the Hierarchy. If you delete a GameObject from the Scene, it will no longer be listed.

Project window

The Project window is where you can find all the files (assets) available for use in your project, whether you use them or not. The Project window works like a file explorer, organized in folders. You can drag assets directly from the Project window into the Scene view to add them to the Scene.

Inspector window

The Inspector is where you'll find and configure detailed information about all the components attached to the GameObjects. When you select a GameObject in Scene view or the Hierarchy, you'll see its components in the Inspector.

Console window

The console is used to control the status of the project. All errors in the scripts, or debug messages, will be logged here.

Toolbar

The Toolbar is always at the top of the Unity Editor interface. Use the toolbar buttons to select and adjust GameObjects, change your point of view in the Scene, and start and stop Play Mode.

Unity Scene

Unity Projects are organized into scenes. Scenes are containers for everything in the experience you are creating. Every Unity project must have at least one scene, but there is no limit to how many scenes it can have. A new project generally has a SampleScene saved in Assets->Scenes with two GameObjects: Main Camera and Directional Light.

Unity Scene

The navigation inside the scene is similar to other 3D modelling software:

Unity Packages

The Unity Package is another important feature to learn. Packages are used to add various enhancements to the project: for example, XR Plugin, FBX Exporter, but also 3D models, textures, sounds, ready-made scenes etc. The packages can be accessed and managed from Window -> Package Manager.

Unity Package Manager

From Package Manager it is possible to see the packages that are currently in the project (and update them if needed); the ones collected in the Unity Registry (e.g. Oculus integration); as well as the one downloaded from the Asset Store. In addition, it is possible to add packages that are stored locally or part of a Git repository.

Download the CE Studio Model. The file itself is a Unity package that contains a ready-made Unity Scene.

In Unity open the package using Assets -> Import Package -> Custom Package. A new window will show the files that will be imported

Unity Package import

Once imported, in the Project window go to the folder CE_Studios -> Prefab and drag and drop the object Environment in the Hierarchy window

Unity Package import

A new complete environment should be now visible in your scene. Remove, from the Hierarchy window the Directional Light as the Gallery model already contains one

CE Studios

Press the Play button from the Toolbar to enter in the Game window, however, nothing is really playing as the environment does not have any animation and the Main Camera does not have any controller attached. Exist the Play mode and save the scene

Camera Controllers

In order to explore the gallery scene, we need to control a camera. For doing so, we need to add a Character Controller. While it is possible to build a controller from scratch using few lines of code, Unity already provides, through the Asset Store a free asset for a First Person Character Controller and for a Third Person Character Controller that also provide multiple settings from the GUI

3rd person control

From the Asset Store webpage, select Add to My Assets for each controller. The two assets can be installed directly from the webpage. Otherwise, in Unity Editor, on the Package Manager window, change the view to My Assets. Both Starter Assets should be there, ready to be downloaded and imported (if not, check the Last update time and press the refresh button).

Package manager input system

Download and import each of them (it could take some minutes to do so). Once imported, a new folder StarterAssets will be part of your Assets

Before importing the new camera, we need to remove the existing Main Camera from the Hierarchy window (right-click and delete) and to change the layer of the GameObjectsstair and wall to 0:Default:

Layer objects

Create a new empty GameObject in the Hierarchy window named Player. From the folder StarterAssets -> ThirdPersonController -> Prefab, drag and drop in the GameObjectPlayer the following Prefab:

Finally, expand the PlayArmature, inside the Player GameObject, from the Hierarchy window, you should have a GameObject named PlayerCameraRoot.
Now, select the GameObjectPlayerFollowCamera and in the Inspector window, under the component CinemachineVirtualCamera drag and drop the PlayerCameraRoot in the Follow field

Follow camera

Press Play on the Toolbar to explore the gallery: The mouse is used to rotate the camera and WASD control the character (spacebar to jump, shift to run)

Follow camera

In the same way, it is possible to import a First Person Character Controller. The prefabs to use are:

The PlayerCapsule GameObject will have the child PlayerCameraRoot to add in the Follow field of the PlayerFollowCamera. On the same component, CinemachineVirtualCamera set also the Body -> Shoulder Offset to 0,0,0

The Packages is just one of the ways to import new assets in Unity . Original file formats such as .fbx, .dae and .obj for 3D models, .jpg and .png for images, .wav and .mp3 for sounds etc. are natively supported by Unity. Other formats can be imported using additional plugins from the Assets Store or from the Unity community.

Sketchfab is a great service to share and download 3D models. Choose one model to add to the gallery and download the fbx format. For example, use our Noise Gauge

Download model screen Sketchfab

Create a new folder in the Project window and copy the model in there.
From the Inspector window we can change the importing settings of the assets (e.g. scale factor, animation, uv mapping). Select the Materials tab and change the Location field to Use External Materials (Legacy), in this way the materials will be extracted from the model in the same folder of the asset as Unity Materials, easier to modify them.

Material Legacy

In this example the 3D model did not have embedded texture and they have been added from the Inpector window (the colour map on the small square next to the Albedo, and the Normal map in the small square next to the Normal Map)

Texture apply

We can now drag the 3d model in the scene, change is position using the Transform component in the inspector window or directly the gizmo axis in the Scene window

Texture apply

PC & Mac Standalone

There are several settings and optimisation that can be added to the project, but for now let's build our first application. Open the Build Settings form File -> Build Settings, Add the open scene and control that PC, Mac & Linux Standalone is selected. Chose the Target Platform (e.g. Windows).

Build

Before building the project, we can change the name of the application, the icon to show and if it will run full screen or in a window, from the Player Settings... and, if needed, change the quality of the built from the left side menu Quality (default setting for standalone is Ultra)

Build

Back in the Build Setting window, press Add Open Scenes and then Press Build and select a folder

Build for Mobile [OPTIONAL]

The Third Camera Controller supports mobile inputs out-of-the-box. From the Project window search and add (drag and drop) to the Player GameObject the UI_Canvas_StarterAssetsInputs_Joysticks and UI_EventSystem prefabs:

Find the prefab

PlayArmature

Mobile input

Build Android

Open the Build Settings form File -> Build Settings and select Android as a new platform and then Switch Platform

All the default settings will be fine for now. The quality of the project is automatically set to Medium, due to the performance of the mobile system.
Press the Build button to build the project and create an apk file that can be moved to an Android Phone to be installed

Build iOS

Open the Build Settings form File -> Build Settings and select iOS as a new platform and then Switch Platform

All the default settings will be fine for now. The quality of the project is automatically set to Medium, due to the performance of the mobile system.
To build a Unity App on iOS we need to have Apple Developer Team ID. It is possible to get a Free iOS Developer Account to test our App this guide will describe in detail the steps to follow to add your Apple ID to Xcode:

Xcode -> Preferences -> Accounts -> Apple IDs, in the lower-left corner, click the Add button (+)

In the sheet that appears, choose Apple ID, then click Continue.

In the next sheet, enter your Apple ID, click Next, enter your password, then click Next.

If successful, the Apple ID appears in the column on the left and the teams that the Apple ID belong to appear on the right. The table displays the team name and your program role. If you are an individual who doesn't belong to the Apple Developer Program, your team name is your first and last name appended by "Personal Team" in parentheses—for example, "Mei Chen (Personal Team)".

It is possible to add your Apple Developer Team ID in Unity to authorize your app during the build Unity -> Preferences -> External Tools under Xcode Default SettingsSigning Team id (check also Automatically Sign). This step is useful if you are building iOS apps on Windows.

Mobile input

A Unity scene can grow easily and faster in terms of complexity due to the number of digital models, materials, textures, scripts. While a powerful system can easily cope with these elements (within a certain limit), outdated systems, mobile devices and VR headsets could provide an annoying and even unpleasant experience for the user.

There are several ways to optimise a Unity scene. One of the most effective, which also has a great impact on the quality and performance of the entire application, is to limit the number of real-time lights and shadows and prefer, if possible, to bake the light in the textures of the digital models. This process is particularly important in VR.

It is possible to create a lightmap also from external 3D modelling software, like Blender, however, last releases of Unity the lightmapping system has become easy to use and extremely effective (especially if a discrete Nvidia GPU with more than 4GB is available).

Baked lights work just on static objects (for obvious reasons), which are objects that do not move or the user does not interact with. To define a GameObject as static:

Lightmap empty

Select lights

We are now ready to set up and generate the lightmaps. Open the Lighting panel from Window -> Rendering -> Lighting.
The first step is to create a New Lighting Settings and to disable the Auto Generate if active.

The important parameters to setup are:

Lightmap panel

Press Generate Lighting to start the process. On fast GPU and medium-size scenes, it could take less than 10⁄5 minutes. On larger scenes, or using the Progressive CPU, it could take also several hours.

In the Scene view we can see Unity computing the lightmaps in real-time

Lightmap panel

Press Play to explore the gallery in a more realistic environment with softer shadows. If Generate Lighting button was used, the lightmaps will be automatically saved in a new folder named after the Scene. This folder will be created in the same directory as the scene file itself.
As high-resolution lightmaps could reach considerable large file size, it is possible to compress them directly in Unity:

Lightmap panel

Lightmap panel

The final result of the gallery, ready to be enriched with real time data installations

Final

The use of a version control system in Unity is optional, but highly recommended for collaborative projects, but also to keep a regular backup of the Unity project itself and to share the project over different systems. In this example, we are going to use GitHub and GitHub Desktop as interface.

The easiest way to create a new GitHub repository is from the GitHub website

First repository

In GitHub DesktopFile -> Clone a repository and search for the repository just created and the local path to clone the repository.

First repository

It is possible to create a new Unity project directly in the cloned repository, or we can move the one that we just created in it (close Unity before moving the project).

To upload the project, we need to push the first commit from GitHub Desktop to the cloud repository.

First commit

We can now clone the repository on other systems. In the case of a collaborative project, it is possible to create a branch for each team member. In GitHub Desktop select the Current branch and give a name to the new one

Branch the repo