Documentation from Unity 4.2 contains too small info about WinRT plugins. Let’s fix this by this tutorial.
1) Create empty unity project:2) Create folders in Assets – Plugins and Metro (under Plugins).3) We will try to call plugin function from empty GameObject. Create it:4) And create C# script:5) Then bind it to empty GameObject (by drag&dropping script to Inspector window).6) Now check, that everything is ok:7) Play scene and notice log message from console:8) Now it’s time to create Windows 8 Runtime plugin. Create new Windows Store apps library. I recommend to do it in unity project folder:9) Configure paths for output:10) And check that everything is ok – compile project and check Assets/Plugins/Metro folder from Unity:
11) Now add additional project (windows class library) to this solution – Stub dll that runs under unity editor. 12) Stub contains only design time functions, but can share most of our plugin code. To reference original plugin.cs, unload project and edit .csproj file manually:13) Reference our original plugin.cs file in stub project. 14) Notice the icon of plugin.cs in Stub project.15) Next step is make some changes of project properties. Make assembly name and default namespace same as WinRTPlugin project and change target framework to version 3.5. 16) Also point output dir to Assets/Plugins17) Delete reference to Microsoft.CSharp assembly:18) Close plugin.cs editor tab and doubleclick plugin.cs from Stub project, and surround references from Windows Runtime using NETFX_CORE condition.19) Now, build Stub project and check that output dll placed to Assets/Plugins.20) It’s time to call our plugin function. Edit your unity script and add plugin instance & function call:21) Open plugin.cs from WinRTPlugin project and add some windows 8 functions:22) Build you project from Unity:23) Open your unity solution from Visual Studio and check that it references WinRTPlugin.dll:24) Run your app and check that everything is ok:
You can download sample code from here http://sdrv.ms/18LcwIo