Presentation is loading. Please wait.

Presentation is loading. Please wait.

Native Integration Module #3 of 6.

Similar presentations


Presentation on theme: "Native Integration Module #3 of 6."— Presentation transcript:

1 Native Integration Module #3 of 6

2 Windows integration

3 The communication chain
XAML host (.exe) 1 Unity will listen to native events UnityPlayer provides callbacks and/or hooks You use Unity plugins to communicate to platform using WinRT APIs SwapChain for Unity Your Unity game (UnityPlayer.dll) 2 3 Platform services…

4 UnityApp (Phone) public static void BeginInvoke(Action action); Invokes a delegate on application thread, for calling script from UI thread public static void BeginInvoke(ActionWithArg action, object arg); Invokes a delegate on application thread, for calling script from UI thread public static bool BackButtonPressed(); Notifies Unity of BackButtonPress public static void Obscure(bool isLocked); Pauses Unity app thread public static void UnObscure(); public static void Quit(); Note: to call to XAML UI thread use Dispatcher.BeginInvoke ()

5 AppCallbacks (WinRT) void InvokeOnAppThread(AppCallbackItem item, bool waitUntilDone) Invokes a delegate on application thread, useful when you want to call your script function from UI thread. void InvokeOnUIThread(AppCallbackItem item, bool waitUntilDone) Invokes a delegate on UI thread, useful when you want to invoke something XAML specific API from your scripts. bool RunningOnAppThread() Returns true, if you're currently running in application thread. bool RunningOnUIThread() Returns true, if you're currently running in UI thread. bool UnityPause(int pause) Pauses Unity if you pass 1, unpauses if you pass 0, useful if you want to temporary freeze your game, for ex., when your game is snapped.

6 UnityEngine.WSA (Windows/Universal)
Tile Toast Launcher LicenseInformation* * In UnityEngine.Windows namespace

7 Writing a plugin

8 Run-time reminder… Can’t inline platform code Mono compiler
.NET for WP Plugins .NET compiler .NET for Win Store Can inline platform code Plugins

9 Writing a plugin

10 Writing a plugin One solution, 3 projects Same Assembly Name,
Same namespaces Different preprocessor directives Make sure the directives are set at Configuration= All Configurations, Platform = All Platforms Shared codebases (via linked files) Different ‘target’ directories in Unity

11 Platform dependent compilation in Unity*
Pre-processor define Description UNITY_EDITOR Define for calling Unity Editor scripts from your game code. UNITY_WP8 Platform define for Windows Phone 8. UNITY_METRO and UNITY_METRO_8_1 Platform define for Windows Store Apps (additionally NETFX_CORE is defined when compiling C# files against .NET Core). UNITY_WP_8_1 Platform define for Windows Phone 8.1, using Universal app model UNITY_WINRT Equivalent to UNITY_WP8 |UNITY_METRO *You must define the pre-processors manually in your plugins; these are auto-defined only in Unity

12 Unity Plugins folders Editor Assets\Plugins Windows Phone 8
Target platform Folder Editor Assets\Plugins Windows Phone 8 Assets\Plugins\WP8 Windows Phone 8.1 (Universal) Assets\Plugins\WindowsPhone8.1 Windows 8 Assets\Plugins\Metro or Assets\Plugins\Metro\Win80 Windows 8.1 Assets\Plugins\Metro or Assets\Plugins\Metro\Win81

13 The easy way: Free plugins from
Store Essentials Ads Azure (Soon) Store Essentials Ads Azure $400+ plugins for free at

14 Using 3rd party plugins

15 Bridges Expose interface Set Interface from native code Benefits: Avoid reference to .NET assembly types

16 Bridge

17 Consuming 3rd party plugins
If you have plugins that are shipping as source code (such as NGUI), then the compiler will catch most issues for you. If you have plugins that ship as a binary that are not designed for Windows, you will likely get errors at run-time when you try to load them or use them. A good way to check if a plug-in is compatible with Windows Phone or Windows Store is to run it through the

18 Porting run-times (Summary)
Unity Editor Windows Phone (SL 8.0, SL 8.1) Windows Store 8.x & Phone 8.1 Compiles with Mono .NET Core At run-time Silverlight for Windows Phone .NET and WinRT Pre-processors UNITY_EDITOR UNITY_WP_8 UNITY_WP_8_1 UNITY_METRO Plugins directory \Plugins \Plugins\WP8 \Plugins\Metro Plugin strategy Binaries & Code Binaries

19


Download ppt "Native Integration Module #3 of 6."

Similar presentations


Ads by Google