Creating a Unity Game for Windows 8

Source: Internet
Author: User
Tags building windows

Original address: Http://www.davebost.com/2013/08/30/creating-a-unity-game-for-windows-8

The recent release of Unity 4.2 brings with it full-support for deploying Unity games to both Windows 8 and Windows Phone. Unity 4.2 is a powerful game development tool, comes in a free version and a Pro edition. The great news, comes along with the release of 4.2 are the ability to deploy your games to the Windows Store and Windo WS Phone Store free of charge! The Unity Windows Store add-on is included in both, the free version of Unity and Unity Pro.

To celebrate this announcement, Unity and Microsoft has teamed up to sponsor a Windows Build competition with over $100,0 XX in PRIZES!!!

To get your well on your-potentially winning a piece of that $100,000 prize pool, I ' m going to walk you through the Steps to build a Unity game for Windows 8.

Sign up with the APP Builder for access to additional resources, training and help building your Windows 8 game.

Let's start simple

The purpose of this article are show you the steps to build your game for Windows 8. Not how to build the next Temple Run 2–unfortunately. Let's start simple.

First download and install Unity. Unity comes in a free version and a Pro edition. The Pro Edition provides more advanced game development capabilities. However, you can create some amazing games with the free version and I know several people who has done just that.

Once Unity is installed, open Unity and select File | New Project. Select a project location and choose not to import any packages at this time.

You should now has a blank canvas to create your masterpiece. Fortunately for us, we masterpiece shouldn ' t take us longer than ten minutes to create.

In the Hierarchy window, select the Create dropdown and select Cube.

In the Inspector window, change the scale and Rotation values to the following:

Your Cube should look like the following. Slightly bigger than the default, turned to the left and tilted downwards.

If you click on the Game tab, you can see what your Cube would look like during runtime. Unfortunately, it ' s a little dull and a little dark. Let ' s add some lighting. In the Hierarchywindow, select Create | Directionallight.

It doesn ' t matter where the directional is placed, what does matter is the angle it's "shining" at. The directional light gives your the effect of a light shining from above at a specific angle that would highlight and Gener ATE shadows on the objects below.

You can switch to the Game window to see how your cube looks or even click the play button to see what your cube looks lik e When the your game is running. Although our cube was lit nice and its still pretty boring. Let's add some animation to our cube.

To add a animation effect, we need to write some code. Unity supports your custom code to being written in JavaScript, Boo, or C #. At this time, JavaScript and Boo scripts won ' t pass the Windows 8 Store certification. In addition, you can ' t access C # classes from JavaScript and Boo, but you should is able to access JavaScript and Boo from C#. With all of this in mind, we ' ll select C # as our script language of choice.

To create the C # script, select your Cube object in the Hierarchy window, and in theInspector window, SC Roll all the Component and click the Add button and select New Script. Feel the name of the the script but is sure to select CSharpas the language. Click Create and Add. The would create a new Script object and place it in your Assets folder in the Project window. Also, with the Cube object selected in yourHierarchy window, you should see the script attached (checked) in the Inspector window.

To edit the script, you can double-click the script in your Assets folder (in the Projectwindow) or Doub Le-click the script name in the Inspector window. The Update () method is called for every ' Tick ' of game time.  Essentially for every frame of your game. In theUpdate () method, use the transform. Rotate () method to apply our animation.

You can control the speed of rotation through the multiplication value. The larger the value, the faster the rotation.

Save the script and switch back to Unity. To test your work of art, click the Play button. Congratulations, you have a spinning cube!

Click the play button again to stop the game from running. It ' s important to stop before making any more changes to your project.

If you ' re really adventurous, we could add a little more pizazz to our cube. In the Project window, right-click the Assets folder and select Import Package | Particles.

In the importing package window, leave everything selected and click the Import button. In the Project window, open the Smoke folder (Assets/standard assets/particles/smoke). Drag and drop Fluffy smoke onto the Cube in the Hierarchy window. Now, navigate to the Fire folder in the Project window and drag and drop Flame onto the Cube in TheHierarchy window.

Now when do you press Play should see a SPINNING CUBE of fire!!!

Click the Play button to stop your–spinning CUBE of fire! –and return to the Unity editor. At here, save your changes by selecting File | Save Scene (or ctrl-s). Now we ' re ready to deploy our game to Windows 8.

Building for Windows 8

Open the File menu and select Build Settings. With Unity 4.2, we are now having the ability to export our games to Windows 8 and Windows Phone. In the Build Settings windows, select Windows Store Apps and click the Switch Platform button. If your Scene isn ' t already listed in the Scenes in the Build list, click Add Current button.

Unity has the ability export your game into the following Visual Studio project types:

    • Direct 3d/c++
    • Direct 3d/c#
    • Xaml/c++
    • xaml/c#

Which type you are export to are more of a personal choice. Choosing XAML does add a slight performance hits to your game, but it does give you the capability-take advantage of Ric H UI and GUI elements for your game as well as easily take advantage of handling some Windows 8 scenarios such as Extended Splash Screens and Snapped View.

For our purposes, we ' re going to select xaml/c# as our build type.

Unity gives us the capability to define the required artwork for a Windows 8 app. Click onPlayer Settings ... in the Build Settings dialog. In the Inspector window, you can specify elements such as logos, Wide logo, Small logo, Splash screen, etc. If your game requires additional capabilities such as Internet Client connectivity or location, where can specify these in T He Player Settings as well. These settings is translated over to the Visual Studio Project's Package manifest file (package.appxmanifest).

Once you ' ve completed setting your Player Settings and you ' re-ready to build your game, open the build Settings W Indow again (File | Build Settings), verify your scene is listed and the xaml/c# type is selected, and click the Build button.

If This was the first time you were building your game, Unity would prompt you to a build location. For my project, I created a ' export/win8 ' folder structure in my Unity project directory and selected the ' Win8 ' folder as My build directory.

Once The build is complete, open the generated solution file (. SLN) in Visual Studio.

If you ' re a Windows 8 C # Developer, this solution should look very familiar. Your Unity Game and all of its assets is compiled and stored in the Data folder. Everything else is the Windows 8 application code that would host the Unity game. This structure preserves your Windows 8 application specific code from any changes made in Unity. When do changes to your Unity game and re-export the build, those changes would only overwrite the contents in the data folder. Everything else is preserved.

A look Inside the Code

If you open the App.Xaml.cs file, you can examine how the Unity player is integrated to this xaml/c# applicatio N.

At the beginning of the APP class declaration, there is the class variables declared:

Private Winrtbridge.winrtbridge _bridge;
Private Appcallbacks appcallbacks;

Winrtbridge is a unity Internal-only class that provides Unity the integration between the managed and unmanaged World. It is not a intended to being used by developers.

Appcallbacks is a very important class. This class provides the developer ' s bridge between the Windows 8 application and your Unity game. The Appcallbacks class is used to initialize your Unity game at start-up time as well as handle events between the Windows 8 Application and your Unity game. More details can is found in the documentation for Appcallbacks.

In the mainpage.xaml file, the Unity player was hosted in a swapchainbackgroundpanelcontrol. This controlled was initialized and loaded in the OnLaunched () event defined inApp.xaml.cs.

Other than those custom elements required to Unity, this is the just a standard XAML Windows 8 application. The Unity documentation does contain several samples on what to integrate your Unity game with your Windows 8 application. Included in those samples, was theXAMLUnityConnectionV4 sample that shows what to integrate event-handling between Unity and Your Windows application. This is necessary to handle events such as the user Switching your game to snapped view as well as any GUI related events Triggered by XAML this need to being sent to Unity. Another sample worth noting is the metrosettingsmenuv1sample, shows how to integrate the use of the Settings menu in W Indows 8 with your Unity game.

At here, you can test your game as a Windows 8 app by clicking the Run button (or hitting F5) in Visual Stu Dio.

Note: Your app may fail deployment because of ...

Error:DEP0700:Registration of the app failed. Windows cannot install Mywindows8game because the package requires architecture ARM, but this computer have Archite Cture x64 (0X80073CF3).

The Unity exported project contains a build configuration definition for ARM, x64 and x86. Your most likely isn't developing on a ARM based machine, therefore your need to change the current building configuration T O Test your game on your development machine. To does this, open the Build menu in Visual Studio and select Configuration Manager. In theConfiguration Manager window, select appropriate architecture under Active solution Platform.

Close the Configuration Manager window and re-run your application by clicking theRun button (or F5).

congratulations! You ' ve built a Unity game for Windows 8!

Here's my completed project in-case you missed a step along the "the"
Firecube.zip.

Bringing It Home

There is some additional elements you'll need to being aware of to get your Unity game through the Windows Store Certificati On process. Much of this guidance are available from the Building Windows games with Unity event held last spring. Here experts from unity and Microsoft share insight, guidance and lessons learned to bring your Unity games to Windows 8 a nd Windows Phone.

Jodon Karlik, of Codingjar, have an invaluable session on the lessons he learned when building Fling theory for the Windows Store. These lessons include implementing an Extended Splash screens, conditional compiling, Ad integration and handling snapped V Iew. Also recommended is the session from Vladimir Kolesnikov on differentiate:integrate your game with Windows 8 Platform Fea Tures, which delves into topics such as contracts, notifications and live title integration. Also, be sure to read through the Windows Store andwindows Phone sections of the Unity documentation for all the latest in Support and capabilities.

The last step was to the your game using Visual Studio and to follow the publishing guidance.

The time is right-success in the Windows 8 Store. Unity provides every budding and professional game developer the high quality tools to build amazing games. With the latest release of Unity 4.2 your now has the power to bring those games to the Windows Store and Windows Phone St Ore.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.