Creating a Unity Game for Windows 8
原地址: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 that comes in a free version and a Pro edition. The great news that comes along with the release of 4.2 is the ability to deploy your games to the Windows Store and Windows 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 have teamed up to sponsor a Windows Build Competition with over $100,000 in prizes!!!
To get you well on your way to 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.
Let’s start simple
The purpose of this article is show you the steps to build your game for Windows 8. Not how to build the next Temple Run 2 – unfortunately. With that in mind, 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 have 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 have a blank canvas to create your masterpiece. Fortunately for us, our masterpiece shouldn’t take us longer than 10 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 will look like during runtime. Unfortunately, it’s a little dull and a little dark. Let’s add some lighting. In the Hierarchywindow, select Create | Directional Light.
![]()
It doesn’t matter where the directional light is placed, what does matter is the angle it’s “shining” at. The Directional Light gives you the effect of a light shining from above at a specific angle that will highlight and generate 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 like when your game is running. Although our cube is lit nice, its still pretty boring. Let’s add some animation to our cube.
To add an animation effect, we need to write some code. Unity supports your custom code to be 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 be able to access JavaScript and Boo from C#. With all of that 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, scroll all the way down and click the Add Component button and select New Script. Feel free to change the name of the script but be sure to select CSharpas the language. Click Create and Add. The will 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 double-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 you press Play you should see a SPINNING CUBE OF FIRE!!!
![]()
Click the Play button to stop your – SPINNING CUBE OF FIRE! – and return back to the Unity editor. At this point, 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 now have 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 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 export to is more of a personal choice. Choosing XAML does add a slight performance hit to your game, but it does give you the capability to take advantage of rich 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 Logo, Wide logo, Small logo, Splash screen, etc. If your game requires additional capabilities such as Internet Client connectivity or Location, you can specify these in the Player Settings as well. These settings are 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 window again (File | Build Settings), verify your scene is listed and the XAML/C# type is selected, and click the Build button.
If this is the first time you are building your game, Unity will prompt you for 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 are compiled and stored in the Data folder. Everything else is the Windows 8 application code that will host the Unity game. This structure preserves your Windows 8 application specific code from any changes made in Unity. When you make changes to your Unity game and re-export the build, those changes will 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 into this XAML/C# application.
At the beginning of the App class declaration, there are two 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 intended to be 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 be found in the Documentation for AppCallbacks.
In the MainPage.xaml file, the Unity player is hosted in a SwapChainBackgroundPanelcontrol. This controlled is initialized and loaded in the OnLaunched() event defined inApp.xaml.cs.
Other than those custom elements required by Unity, this is just a standard XAML Windows 8 application. The Unity documentation does contain several samples on how to integrate your Unity game with your Windows 8 application. Included in those samples, is theXAMLUnityConnectionV4 sample that shows how 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 that need to be sent to Unity. Another sample worth noting is the MetroSettingsMenuV1sample that shows how to integrate the use of the Settings menu in Windows 8 with your Unity game.
At this point, you can test your game as a Windows 8 app by clicking the Run button (or hitting F5) in Visual Studio.
Note: Your app may fail deployment because of…
Error: DEP0700: Registration of the app failed. Windows cannot install package MyWindows8Game because the package requires architecture ARM, but this computer has architecture x64 (0x80073cf3).
The Unity exported project contains a build configuration definition for ARM, x64 and x86. Your most likely not developing on an ARM based machine, therefore you need to change the current building configuration to test your game on your development machine. To do 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 is my completed project in-case you missed a step along the way:
FireCube.zip.
Bringing it Home
There are some additional elements you’ll need to be aware of to get your Unity game through the Windows Store certification process. Much of this guidance is 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 and Windows Phone.
Jodon Karlik, of CodingJar, has an invaluable session on the lessons he learned when building Fling Theory for the Windows Store. These lessons include implementing an Extended Splash Screen, conditional compiling, Ad integration and handling snapped view. Also recommended is the session from Vladimir Kolesnikov on Differentiate: Integrate your game with Windows 8 Platform Features, 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 is to package up your game using Visual Studio and to follow the publishing guidance.
The time is right for 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 you now have the power to bring those games to the Windows Store and Windows Phone Store.
Creating a Unity Game for Windows 8的更多相关文章
- Unity for Windows: III–Publishing your unity game to Windows Phone Store
原地址:http://digitalerr0r.wordpress.com/2013/08/27/unity-for-windows-iiipublishing-to-windows-phone-st ...
- Unity for Windows: II – Publishing Unity games to Windows Store
原地址:http://digitalerr0r.wordpress.com/2013/08/27/unity-for-windows-ii-publishing-to-windows-8/ Windo ...
- Unity中调用Windows窗口句柄以及根据需求设置并且解决扩展屏窗体显示错乱/位置错误的Bug
问题背景: 现在在搞PC端应用开发,我们开发中需要调用系统的窗口以及需要最大化最小化,缩放窗口拖拽窗口,以及设置窗口位置,去边框等功能 解决根据: 使用user32.dll解决 具体功能: Unity ...
- Unity安装(Windows版)
Unity下载助手 Unity下载助手是一个小型可执行程序(大小约为1 MB),它允许您选择要下载和安装的Unity Editor的那些组件. 如果你不知道要安装,保留默认选择,单击继续 ,然后按照安 ...
- unity 实现调用Windows窗口/对话框交互
Unity调用Window窗口 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分 ...
- Unity 3D调用Windows打开、保存窗口、文件浏览器
Unity调用Window窗口 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分 ...
- Unity引用System.Windows.Forms遇到的一些坑
这两天在做一个unity打开文件选择框的功能.网上找到两种方法, 第一种是调用win32打开对话框,这个挺好,但是有个致命的问题,没办法多选!!!多选的话返回的是根目录的路径,文件名返回不了,找了半天 ...
- Unity中调用Windows窗口选择文件
1.OpenFileName数据接收类,如下: using UnityEngine; using System.Collections; using System; using System.Runt ...
- (译)【Unity教程】使用Unity开发Windows Phone上的横版跑酷游戏
译者注: 目前移动设备的跨平台游戏开发引擎基本都是采用Cocos2d-x或者Unity.一般而言2d用cocos2d-x 3d用unity,但是对于Windows Phone开发者, cocos2d- ...
随机推荐
- 【最小点覆盖】POJ3041-Asteroids
[题目大意] 在n*n的网格上有n个点,每次删除一行或者一列,问至少要删除几次才能删除完全部的这些店? [思路] 在国庆最后一天到来前,把二分图的三个基本情况[最小点覆盖][DAG图的最小路径覆盖]和 ...
- [CF115E]Linear Kingdom Races
[CF115E]Linear Kingdom Races 题目大意: 有\(n(n\le10^5)\)个物品,编号为\(1\sim n\).选取第\(i\)个物品需要\(c_i\)的代价.另外有\(m ...
- HDU 1287 MC挖矿世界 set bfs
MC挖矿世界 题目连接: http://acm.uestc.edu.cn/#/problem/show/1287 Description 银牌爷和柱神开始玩MC啦,但是怪物实在是太多了,于是银牌爷决定 ...
- 典型案例收集-使用OpenVPN连通多个机房内网(iptables+静态路由)
说明: 1.这个方案是我最初实现的方案,目的在于OpenVPN连通后使其能访问各自的子网,实现互通. 2.主要以iptables为主,这个是关键点,并且这种方式配置iptables十分复杂,最后加入了 ...
- Windows UWP开发系列 – RelativePanel
RelativePanel是在Windows 10 UWP程序中引入的一种新的布局面板,它是通过附加属性设置元素间的位置关系来对实现布局的.一个简单的示例如下: <RelativePanel&g ...
- SpringMvc(1) --Eclipse搭建web项目
http://blog.csdn.net/uucai http://blog.csdn.net/uucai/article/details/21258575
- SharePoint Server 2013 Offline Installation (without Internet)
转自:http://social.msdn.microsoft.com/Forums/sharepoint/zh-CN/08f90e0f-1f52-4eba-9f6e-4dd635ffaadc/sha ...
- Linux C/C++开发工具
1. vim + ctags + taglist + cscope + cppcomplete + global 2.emacs+插件 可以查看 http://blog.163.com/yu_hong ...
- Lua中的元表和元方法
Lua中每个值都可具有元表. 元表是普通的Lua表,定义了原始值在某些特定操作下的行为.你可通过在值的原表中设置特定的字段来改变作用于该值的操作的某些行为特征.例如,当数字值作为加法的操作数时,Lua ...
- 《C++反汇编与逆向分析技术揭秘》之十——析构函数
局部对象 当对象所在作用域结束之后,销毁栈空间,此时析构函数被调用. 举例: 函数返回时自动调用析构函数: 堆对象 调用析构代理函数来处理析构函数: 为什么使用析构代理函数来调用析构函数?考虑到如果d ...