Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Unity 自4.2版起即開始正式支援 Windows Store App 及 Windows Phone 8,而且這兩個 add-ons 不但在 Unity Pro 上是免費的,同時在free version 的 Unity 上也是內建的免費功能!
========================= 分隔線 =========================
以下我即以 free version 的 Unity,一步一步建制一個簡單 Windows Store App 讓大家參考。
首先在 Unity 中新增專案,不要匯入任何的packages。
先在 Hierarchy 中建立一個 Cube,
然後在 Inspector 中改變其 Rotation 及 Scale 如以下:
現在這個 Cube 看起來是黑黑的一團,所以我們加點光給它: 到 Hierarchy 中建立一個 Directional Light:
接下來我們寫一行 C# code 讓這個 Cube 會轉。先到 Hierarchy 中選擇 Cube 物件後,在其 Inspector 畫面中往下拉,選 Add Component –> New Script –> CSharp 後,按下 Create and Add:
這時在 Project 中的 Assets 中會出現剛建立好的 C# script:
雙點這個 script 會開啟 MonoDevelop 來編輯, 在 Update() 方法中加一行:
// Update is called once per frame
void Update () {
transform.Rotate(Vector3.up, Time.fixedDeltaTime * 200.0f);
}
存檔後回到 Unity,按下上方的 Play 符號就會看到 Cube 旋轉的樣子。
接下來我們想在旋轉的 Cube 上新增一些花樣: 至 Project 的 Assets 中按右鍵: Import Packages –> Particles, 然後直接按 import
完成後點開 Assets –> Standard Assets –> Particles,然後選擇 Smoke,把 Fluffy Smoke 拖拉到 Hierarchy 下,就會看到 Cube 在冒煙。
如以上步驟,再選擇 Fire 後,把 Flame 拖拉到 Hierarchy 下,就會看到 Cube 冒出火來;你也可以 Play 看看效果。
接下來,要把它建制成 Windows Store App了!
在 File –> Build Settings…中,選擇 Windows Store App –> XAML C# Solution,然後 Build And Run 後即可。
建制完畢後會在資料夾中看到完整的 Windows Store App solution:
我們以 Visual Studio 2012 開啟 .sln 檔,若直接編譯的話會看到以下錯誤:
錯誤訊息為:
Error: DEP0700: Registration of the app failed. Windows cannot install package “你的專案名” because the package requires architecture ARM, but this computer has architecture x64 (0x80073cf3).
其原因是 Unity 預設將它的 package 包成可在 ARM, x86 及 x64 不同平台執行的版本,而您的 Visual Studio 顯然並不是在 ARM 機器上跑的,所以會產生這個錯誤。
解決方法是,至 Visual Studio 的 Build –> Configuration Manager 中選擇 x86 即可。
這是順利執行之後的預設 splash screen:
跑起來的樣子如下
延伸閱讀: 繼 Unity 之後,Cocos2d-x 也正式支援 Windows 8 及 Windows Phone App 了!
Comments
Anonymous
October 01, 2013
有點好奇能不能在Visual Studio裡面設計主選單操作介面呢Anonymous
October 01, 2013
可以的喔,因為Unity porting出來的是一個完整的 Visual Studio solution。以我這個小sample為例,是porting 成C#/XAML solution,所以所有的XAML元件(Button, TextBlock, AppBar, etc.)都可以在上面實作。Anonymous
January 06, 2014
Unity不能使用windows store app的js開發嗎?Anonymous
January 07, 2014
不能,Unity除了可使用C# 之外,是使用所謂的 UnityScript/Boo。這部份在4.3版之後也支援了 (雖然我沒實測過): unity3d.com/.../unity-4.3
