Top Banner
Porting Unity games to Windows*
24
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Porting unity games to windows - London Unity User Group

Porting Unity games to Windows*

Page 2: Porting unity games to windows - London Unity User Group

Porting…

Store

Lifecycle

Splash Screen

Settings

Networking

Platform APIs

GPU

Memory

Input

Layout/Screen

Hardware

Live Tiles

Notifications

Sharing

Voice (WP only)

Light-up

Page 3: Porting unity games to windows - London Unity User Group

Porting recommendations

1. Prepare your game for x-platform

2. Port your logic

3. Port or replace your plugins

4. Platform specific optimizations

& configuration

5. Implement Light-up

6. Optimize performance

Page 4: Porting unity games to windows - London Unity User Group

Preparing for x-platform

Feature Detection

Dynamic screen size/resolution

Portable Scripts (with platform defines)

Plugins

Page 5: Porting unity games to windows - London Unity User Group

Unity Run-time on Windows Store and

Windows Phone Apps

Page 6: Porting unity games to windows - London Unity User Group

Compile & run-time differences

Compiler: Mono Run-time: Mono

Compiler: Mono Run-time: .NET for WP

Compiler: .NET Run-time: .NET Core + WinRT

Universal apps (WP 8.1, Win8 & 8.1 )

Windows Phone 8 Unity Editor

Page 7: Porting unity games to windows - London Unity User Group

.NET CLR (Desktop)

Mono and.NET Core differences…

Mono is a subset of .NET Framework

Mono

.NET Core

Trouble!!

These classes exist in Mono but are not available to Unity in Windows Store and Phone!!

.NET Core is a subset of .NET Framework

Page 8: Porting unity games to windows - London Unity User Group

What is missing?

Namespace Example classes Workaround

System.Collections Hashtable, ArrayList, List Use WinRTLegacy (from Unity)

System.IO File, StreamReader, TextReader Write using Windows.Storage

System.Xml XmlDocument, XmlElement Use WinRTLegacy for basic coverage

System.Reflection Write using equivalent WinRT APIs

System.Security.Cryptography SHA1, TripleDES Use WinRTLegacy for basic coverage

System.Net Socket, NetworkStream Use WinRT networking APIs

System.Threading Thread WinRT is async, use Task, use coroutines

System.Runtime.Serialisation BinaryWriter No direct binary support. Use alternate methods

Page 9: Porting unity games to windows - London Unity User Group

Conditional Compilation on Windows/Universal

Use .NET Core (default)C# compiled using MS Compiler

Can call Windows Runtime APIs from inline scripts

C# types are not visible to JS classes

.NET Core partially C# scripts in ( Plugins || Standard Assets) use Mono Compiler, can’t

reference Windows Run-time

C# types compiled w/ Mono are visible to JS scripts

None Uses Mono compiler for everything, no inline calls to WinRT types

Page 10: Porting unity games to windows - London Unity User Group

Windows Store

Keyboard

Mouse

Touch

Accelerometer/Gyro

Camera

Microphone

Controller

Windows Phone

Touch

Accelerometer or Gyro

Camera

Microphone

Back Button

Input

Page 11: Porting unity games to windows - London Unity User Group

Capabilities (Windows Phone)

Developers must declare

hardware or software capabilities

in the app’s manifest

Users get presented the required

capabilities upon install

Page 12: Porting unity games to windows - London Unity User Group

Capabilities (Windows)

Developers must declare

hardware or software

capabilities in the app’s

manifest

Users get presented the

required capabilities upon

install

Page 13: Porting unity games to windows - London Unity User Group

Tips and Tricks

Page 14: Porting unity games to windows - London Unity User Group

Back button ( Windows Phone )

Windows Phone: App pops the back stack or dismisses modal UI if back button is pressed

App exits when back button is pressed from ‘home’ page and no modal

UI is visible

Unity Handles back button (natively) and maps it to KeyCode.Escape

Exits the app if back button pressed and Application.Quit is called ( )

Page 15: Porting unity games to windows - London Unity User Group

Back button

//Unity does this for you automatically

<phone:PhoneApplicationPageBackKeyPress="PhoneApplicationPage_BackKeyPress" >

private void PhoneApplicationPage_BackKeyPress(object sender, CancelEventArgs e)

{

e.Cancel = UnityApp.BackButtonPressed();

}

//IN your unity code, handle back button, you should quit, go back or dismiss modal UI

void Update {

if (Input.GetKeyDown(KeyCode.Escape)){

Application.Quit();

} }

Page 16: Porting unity games to windows - London Unity User Group

Keyboard (Phone & Windows, Unity 4.5+ )

Seamless keyboard support via GUI

Programmatic access via TouchScreenKeyboard classOn Windows, set keyboard.area is not supported

Setting keyboard.active after instantiate is not required anymore

Page 17: Porting unity games to windows - London Unity User Group

Memory (Windows Phone)

Memory Limits

http://msdn.microsoft.com/en-us/library/windows/apps/jj681682(v=vs.105).aspx

App type 512 MB 1-GB phones 2-GB phones

Windows Phone 8.0 180 MB 380 MB 780 MB

Silverlight 8.1 and Windows Runtime 8.1

185 MB 390 MB 825 MB

App type Platform

ID_FUNCCAP_EXTEND_MEM Gets you the 180 MB and 380MB WP8

ID_REQ_MEMORY_300 Opts out of lower memory devices WP8

minDeviceMemory Appx similar for ID_REQ_MEMORY WP81, Appx

Manifest settings

Page 18: Porting unity games to windows - London Unity User Group

Memory Tips (Windows Phone)

Test on low-end devices

Use the Unity profiler

Compress textures to DXT1 or DXT5

Reduce Audio Memory Usage

‘Stream from disc’ instead of ‘Compressed in memory’

Page 19: Porting unity games to windows - London Unity User Group

Memory, useful APIs (Windows Phone)

DeviceStatus.DeviceTotalMemory

DeviceStatus.ApplicationCurrentMemoryUsage

DeviceStatus.ApplicationPeakMemoryUsage

Page 20: Porting unity games to windows - London Unity User Group

Asset bundles

Can’t be explicitly downloaded

Useful to support multiple resolutions

Useful to chunk features (e.g. tutorial)

Page 21: Porting unity games to windows - London Unity User Group

Audio ( Phone)

If you hear “crackles” on debug builds, try master

Test on devices, emulator will not be representative

To maximize memory, stream from disk

Look at media codecs for Windows Phone http://msdn.microsoft.com/en-

us/library/windows/apps/ff462087(v=vs.105).aspx

Page 22: Porting unity games to windows - London Unity User Group

Handling Screen Size Changes

UnityEngine.WSA.Application.windowSizeChanged += WindowSizeChanged;

public static void WindowSizeChanged(int width, int height)

{

if(width <= 500) {

GameController.SP.paused();

}

else {

GameController.SP.unpaused();

}

}

Page 23: Porting unity games to windows - London Unity User Group

Summary

Different run-times Editor is Mono

Device is .NET

A fairly typical hardware port Pay attention to

Memory on Windows Phone 8

Back button

Input on Windows

Page 24: Porting unity games to windows - London Unity User Group

©2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.