Universal Windows Platform Apps and Unity3D

If you’re interested in games, or anything to do with all this talk about 3D and Windows 10, it will be of great advantage to your good self to know about Unity3D. Unity3D has been around for quite some time now, and it’s behind many great games—both 2D and 3D—that are available on app stores for many platforms. Unity3D is not to be taken lightly, and can be found at https://unity3d.com/, from where you can install the latest version. For this article, I’ll be using version 5.4.2f2 personal, which I’ll use to demonstrate how to create a new project for a 3D game, how you can add a simple object to our 3D world. Then, I’ll talk about how build a UWP application from this project.

The personal version, which I mentioned, offers everything you’ll need to get started as a hobbyist game’s developer; Unity comes packed with many great assets out of the box to help you. What’s an asset? An asset is anything from a piece of music to 3D models, particles systems, and lots more. To give you an idea of what’s available, Unity has an assets store where you can buy or download free assets to use in your projects. You can access the store from within the Unity application, which you’ll need to do to add assets to your projects. However, if you want to browse what the assets store as to offer, you can find it here.

Note: I’ll also be using Visual Studio 2015 Update 3, and I’m building the projects on Windows 10 Version 10.0.14393.

Creating the Project

It’ll take a while to install Unity, and you’ll need to set up an account; but, once you have, start it up and click New Project. You’ll see a window that looks like this…

Unity01
Figure 1: The new project window

Create the project, and you’ll be presented with a view that looks something like…

Unity02
Figure 2: The project created and open in Unity

The first time you see this, it can be quite daunting with all the options and panels. I’ll give a brief description here, but for the sake of this article, I will keep it brief and move swiftly on to adding an asset to our 3D scene and building the output as a UWP application.

In the centre panel, which is currently showing ‘Scene,’ is one of three tabs. We can see an icon of a camera and what we might call a ‘sun.’ The Camera represents the user’s point of view, and the sun indicates a Directional Light that will be used to light our scene. And when I say scene, I mean very much that it is a scene for you to play out your game’s events and story; and the camera is how the player will see that.

Unity03
Figure 3: The Camera and Directional Light

Go ahead and click the camera in the scene. You’ll be presented with a view that looks like this…

Unity04
Figure 4: Our scene with the camera selected

Firstly, you’ll notice that the ‘Main Camera’ is highlighted in the panel to the left of the view. This panel, titled Hierarchy, lists all the objects we currently have placed in our scene. In the bottom-right of our view, you can see the Camera Preview, which shows us exactly what our camera sees. If you select the Game tab at the top of our view, you’ll be presented with a similar view that fills the whole area. Now that we know a little about what we’re looking at, let’s go ahead and add something to our scene.

Adding an Asset

To add something to our scene, right-click the Hierarchy or click the create button at the top; then, select an object of your choice. I’m going to go with a Tree.

Unity05
Figure 5: Adding an object to our scene

And, after we’ve added the object to our scene, in this case a tree…

Unity06
Figure 6: The tree added to the scene

If you don’t have your tree selected, and the Inspector tab on the far-right panel isn’t selected, please do so now. In Figure 6, we can see you have many options available to you once you’ve selected the tree. I want to bring your attention to the Position, Rotation, and Scale options we can see at the top. Go ahead and try changing some of these values; note what happens to the tree in our scene. You also can do the same for the Camera, or any object in our scene because this is one of the simplest ways we can control the positioning. Now, with the tree in our scene, switch the main view area over to the Game tab.

Unity07
Figure 7: How our scene looks from the camera

Yes, I know, the tree looks quite out of place, but you’re seeing it without building more to our scene such as a surface and so forth. It’ll take quite some time to make it look in-place. Before we continue, why not try changing the Y position of the camera, so it moves higher, creating a better view of our tree. You also could add more objects to build out your scene a little more.

However, we now have a scene, albeit a view simple one. Let’s move on to building this application as a UWP app.

Building the UWP Application

Before we go on to building our application, we need to save our scene. From within the file menu, save the scene; then, open the Build Settings window again from the file menu. You’ll be presented with the following…

Unity08
Figure 8: The opened Build Settings window

If you can’t see your scene listed in the Scenes In Build list, simply click the Add Open Scenes button below the list to add it. Once that’s done, change the platform to Window Store by selecting it in the List and clicking Switch Platform; then, set the SDK to Universal 10.

Note: If this is the first time you’ve run Unity, you may find the Windows Store platform at the bottom; it may require you to download a module before it will be usable. You will see a link to download this if you select the platform. Also, if you do need to install this module, Unity will likely require a restart after installation.

If you’re good to go, click Build. It will ask you to select a folder to place the output in; I created a folder in my Unity project directory named ‘UWPBuild’. Once you’ve selected your folder, sit back and allow Unity the necessary time to build the project for you.

The Built Project

When Unity has completed the build process, it will open your project’s directory for you. Inside that directory, navigate to the UWPBuild folder we created for the output, and you’ll see something like this…

Unity09
Figure 9: The output from our Windows Store build

And, look, we have a Visual Studio Solution ready for us! I’ve opened my project in Visual Studio, which gives me a view from my Solution Explorer that you can see in Figure 10.

Unity10
Figure 10: The build output from Unity open in Visual Studio 2015

All that remains now is to build your project in VS and run it. My build options are set to Debug, x86 on the local machine. Here’s what my UWP app looks like when running, defaulted to full screen…

Unity11
Figure 11: The finished project

Final Words

This was a very simple example of how to get started with Unity and UWP that didn’t even scratch the surface of what is possible. If you followed along with my previous article on starting a UWP app with Cortana, you now could start a game using Cortana. And, perhaps do something with the data Cortana gives you when starting that game.

Also, keep in mind Unity already has a lot of stuff in it that is targeted at Windows 10 Holographic. If you already own a Microsoft HoloLense, there are many possibilities for a lot of fun once you bring Unity into the equation.

If you have any questions on this article, you can always find me on Twitter @GLanata.

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read