Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

How does one create plugins for Windows Phone?

Discussion in 'Windows' started by dberroa, Aug 9, 2013.

  1. dberroa

    dberroa

    Joined:
    Dec 16, 2012
    Posts:
    146
    Is there a specific template we choose in Visual Studio? I am wondering how and what language we would have to write for plugins to work on Windows Phone. Detailed instructions or tutorials preferred.

    Thank you.
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,530
    Hello,

    You can write plugins in C# or C++ (whichever you prefer). The template for C++ is called "Windows Phone Runtime Component" and for C# it's called "Windows Phone Class Library".

    Finally, you have to put the compiled files under "<Unity project folder>/Plugins/WP8".

    We don't have any samples yet, but we're planning to upload one soon.
     
  3. asadsohail

    asadsohail

    Joined:
    Sep 13, 2012
    Posts:
    3

    Hi Tautvydas,

    Bro, I need assistance about unity interoperability with windows phone native code so that I can integrate LeadBolt Advertisment SDK in my Unity game by sending procedure calls from Unity. Please help in this regard I found no help anywhere.

    Thanks in advance.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,530
    What exactly are you having problems with? After you've compiled Windows Phone Runtime Component, just place it under Plugins/WP8 folder and you should be able to call those functions from your C# script.
     
  5. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    983
    I compile a .NET4.5 C# Windows Phone Class Library and put it in "Plugins/WP8", then compile a Editor C# .NET 3.5 plugin you can use with your scripts. Everything is fine until I build my test WP8 project from Unity.

    I get the error in the "Postprocessing Player" stage:
    I'm trying to understand why "Mono.Cecil" is being used to compile .NET4.5 stuff for WP8 ??
    Also I have done this same process for Window8 and everything works just fine, so why not on WP8??
     
  6. musikit

    musikit

    Joined:
    Jan 30, 2012
    Posts:
    160
    Does the same go for WinRT? do i create a new "Windows Runtime Component" and then just drop it in "<Unity project folder>/Plugins/WinRT"?
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,530
    You have to create "a fake" plugin for editor with same function names that don't have any references to Windows Phone context. You have to put it under "Plugins/" so when editor compiles it.

    Mono.Cecil isn't a compiler, it's a dependency checker.
     
  8. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    983
    I am, thats whats got me confused, I build a .NET 3.5 dll in the root "Plugins" folder. Then build a .NET 4.5 WP8 dll in "Plugins/WP8".... But for some reason Mono.Cecil is trying to take into account the "WP8 dll" when it shouldn't. (This same process works fine on Win8, just not WP8).

    Also the ".NET 3.5 dll" in the root "Plugins" folder is only referencing Win32 libs, not any WP8 stuff.
    .NET 3.5 dll: (System, System.Core, System.Data, System.Data.DataSetExtsions, System.Xml, System.Xml.Linq)
    .NET 4.5 WP8 dll: (.NET for Windows Phone, Microsoft Advertising SDK for Windows, Windows Phone)
     
  9. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    983
    @Tautvydas Zilys
    Does anything i'm doing look wrong? I'm pretty sure i'm doing as you said.
    If this looks likes something I should submit a bug report for I can do that. It just seems as though this should be working as im sure you have at least had some simple project working for testing in the past.

    My plugin is almost ready for release, and is why i'm so bummed out.
     
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,530
    Are both DLLs are named identically?
     
  11. minjun

    minjun

    Joined:
    Aug 21, 2013
    Posts:
    3
    Which kind of template should I use to create the "fake" plugin for editor? I use the Portable Class Library template in Visual studio 2012. MonoDevelop can use the .dll file, but the Unity Editor cannot load the class in the module...
     
  12. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,530
    By the way guys, make sure the fake DLL is no higher than .NET 3.5.

    @zezba: I looked at your case - Microsoft.Phone.Controls.Maps is WP7, not WP8 assembly. You can try copying the .dll to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.0, but I can't guarantee it will work.
     
  13. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    983
    If I do that I get the error:
    Yes both are named the same. I poorly named the native projects, but both projects default assembly and namespace are "Reign".
    "TestWP8\Native\Reign" is the WP8 project.
    "TestWP8\Native\ClassLibrary1" is the .NET 3.5 project.

    Because you have downloaded my project, i'm wondering if you get the same build error I did?
    Also any libs in the "Microsoft\Framework\WindowsPhone\v8.0" should be able to be used with my project. All those libs can be referenced and used in a WP8 project. I don't think it should matter if they derived from the WP7 as they are still WP8 supported APIs.
     
  14. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    983
    For the editor you must make a normal .NET 3.5 class library normally used for a desktop application.
    For the WP8 one, you must make a WP8 .NET 4.5 class library.
     
  15. minjun

    minjun

    Joined:
    Aug 21, 2013
    Posts:
    3
    Thank you! Let me have a try. :eek:
     
  16. Murthy_Dumadu

    Murthy_Dumadu

    Joined:
    May 17, 2013
    Posts:
    33
    Error building Player: Exception: Failed to run reference rewriter with command "--target="Temp/StagingArea\AddsCommunicator.dll" --framework="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.0" --platform="C:\Program Files (x86)\Windows Phone Kits\8.0\Windows MetaData\Windows.winmd" --support="Temp/StagingArea/WinRTLegacy.dll" --winmdrefs="" --system=Unity --dbg=pdb --alt=System.Net;System.Net.Sockets,System.Net;System.Xml.Serialization". [Temp/StagingArea\AddsCommunicator.dll]
    Catastrophic failure while running rrw: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'ImAdViewFromXAML, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
    at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
    at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
    at Unity.ReferenceRewriter.RewriteContext.RewriteResolver.Resolve(AssemblyNameReference name)
    at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
    at Unity.ReferenceRewriter.RewriteTypeReferences.Visit(TypeReference type)
    at Unity.ReferenceRewriter.ReferenceDispatcher.Visit(TypeReference type)
    at Unity.ReferenceRewriter.ReferenceDispatcher.DispatchFields(TypeDefinition type)
    at Unity.ReferenceRewriter.ReferenceDispatcher.Dispatch(TypeDefinition type)
    at Unity.ReferenceRewriter.ReferenceDispatcher.Dispatch()
    at Unity.ReferenceRewriter.ReferenceDispatcher.DispatchOn(ModuleDefinition module, IReferenceVisitor visitor)
    at Unity.ReferenceRewriter.RewriteTypeReferences.Run()
    at Unity.ReferenceRewriter.RewriteStep.Execute(RewriteContext context)
    at Unity.ReferenceRewriter.RewriteOperation.Execute(RewriteContext context)
    at Unity.ReferenceRewriter.Program.Main(String[] args)


    hiiii all and Tautvydas Zilys i am trying to implement that pluging after i am getting this error in runtime
     
  17. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,530
    The error message is pretty straightforward:

    It cannot find the DLL in which this type is defined.
     
  18. Murthy_Dumadu

    Murthy_Dumadu

    Joined:
    May 17, 2013
    Posts:
    33
    Hiii thanks for your reply this is what i have done please let me know my mistakes
    /***********windows phone 8 and unity 3d games ads integration and in app purchases******************/

    process
    step1) i made a class library project in visual studio by targeting .Net frame work to 4.5
    step2) add a existing or new xaml project which includes all the external calls(ads, in app calls)
    to the library project
    step3)then i builded the project to get the .dll file
    to get the dll
    1) first build the solution
    2) then build the xaml project
    3) then build the main library project

    now right click on library project--->>Open folder in file expander--->>then
    --->>goto bin--->>get the .dll as it will have the same name as library project

    step4 ) import this file into unity plugins/WP8 folder as i kept Plugins/WP8/UnityCommunicator

    step5) i created a dummy dll as UnityCommunicator only .Net targeting fw 3.5 en i kept under the plugins folder


    (if we place the 4.5 dll under plgins/WP8 folder en build the project it's giving the following error

    2)in editor there is no problem at all if i build the project i am getting the following error....

    please correct me....

    Error building Player: Exception: Failed to run reference rewriter with command "--target="Temp/StagingArea\AddsCommunicator.dll" --framework="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.0" --platform="C:\Program Files (x86)\Windows Phone Kits\8.0\Windows MetaData\Windows.winmd" --support="Temp/StagingArea/WinRTLegacy.dll" --winmdrefs="" --system=Unity --dbg=pdb --alt=System.Net;System.Net.Sockets,System.Net;System.Xml.Serialization". [Temp/StagingArea\AddsCommunicator.dll]
    Catastrophic failure while running rrw: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'ImAdViewFromXAML, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
    at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
    at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
    at Unity.ReferenceRewriter.RewriteContext.RewriteResolver.Resolve(AssemblyNameReference name)
    at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
    at Unity.ReferenceRewriter.RewriteTypeReferences.Visit(TypeReference type)
    at Unity.ReferenceRewriter.ReferenceDispatcher.Visit(TypeReference type)
    at Unity.ReferenceRewriter.ReferenceDispatcher.DispatchFields(TypeDefinition type)
    at Unity.ReferenceRewriter.ReferenceDispatcher.Dispatch(TypeDefinition type)
    at Unity.ReferenceRewriter.ReferenceDispatcher.Dispatch()
    at Unity.ReferenceRewriter.ReferenceDispatcher.DispatchOn(ModuleDefinition module, IReferenceVisitor visitor)
    at Unity.ReferenceRewriter.RewriteTypeReferences.Run()
    at Unity.ReferenceRewriter.RewriteStep.Execute(RewriteContext context)
    at Unity.ReferenceRewriter.RewriteOperation.Execute(RewriteContext context)
    at Unity.ReferenceRewriter.Program.Main(String[] args)
     
  19. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,530
    If you do that, you have to put the resulting DLL of external calls to Assets/Plugins/WP8 as well.
     
  20. Murthy_Dumadu

    Murthy_Dumadu

    Joined:
    May 17, 2013
    Posts:
    33
    k i will do that now
     
  21. Murthy_Dumadu

    Murthy_Dumadu

    Joined:
    May 17, 2013
    Posts:
    33
    i kep that external dll inside the WP8 still geting the following error

    Error building Player: Exception: Failed to run assembly preprocessor with command line "Temp/StagingArea/Data/Managed\ImAdViewFromXAML.dll" -injectCtor -assemblyPath "Temp/StagingArea" -pdb.[Temp/StagingArea/Data/Managed\ImAdViewFromXAML.dll]
    No symbols for Temp/StagingArea/Data/Managed\ImAdViewFromXAML.dll
    Injecting ctor
    Error while in assembly preprocessor Temp/StagingArea/Data/Managed\ImAdViewFromXAML.dll
    Object reference not set to an instance of an object.
    at AssemblyPreprocessor.Utils.IsBaseType(TypeDefinition definition, String name)
    at AssemblyPreprocessor.Utils.IsFromNamespace(TypeDefinition definition, String namezpace)
    at AssemblyPreprocessor.ConstructorInjector.ShouldInject(TypeDefinition typeDefinition)
    at AssemblyPreprocessor.ConstructorInjector.InjectConstructorsForTypesIn(ModuleDefinition moduleDefinition)
    at AssemblyPreprocessor.Program.Main(String[] args)
     
  22. Phil-AV

    Phil-AV

    Joined:
    Jul 9, 2012
    Posts:
    57
    I'm having almost the same problems here too.

    I've managed to successfully create a basic plugin (4.5 WP8 target in Plugins/WP8 and 3.5 Win target in Plugins). From there I've added the Flurry WP8 SDK to my 4.5 WP8 project, compiled to DLL, added relevant fake functions to 3.5 DLL and it has been working fine. My Plugins/WP8 folder contained both my created DLL and the FlurryWP8SDK.dll, this compiled fine in Unity and runs fine. I've now added the Facebook.Net SDK using exactly the same process and I'm getting the same Unity compile error as Murthy_Dumadu:

    I find this really strange as Unity successfully finds, compiles and uses the external Flurry SDK dll file, but when it tries Facebook it just fails. I can only speculate that certain build options and dependencies in DLL files causes Unity/a Unity component to flips its S*** and break.
     
  23. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,530
    If you put the fake DLL which have all the methods in it to Assets/Plugins, and still getting this error, can you please submit a bug report? I can't really tell you the reason it fails just from the info you provided.
     
  24. Phil-AV

    Phil-AV

    Joined:
    Jul 9, 2012
    Posts:
    57
    Reported bug with Case 561892
     
  25. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,530
    Thanks. We'll get back to you.
     
  26. Bash-Mills

    Bash-Mills

    Joined:
    Sep 15, 2013
    Posts:
    3
    I am having exactly the same problem with the C# Facebook SDK and using my own basic DLL plugin with it. I have my custom plugin and all Facebook SDK files in Plugins/WP8 and the fake version of my plugin in Plugins but I also get this error:

    Code (csharp):
    1. Error building Player: Exception: Failed to run assembly preprocessor with command line "Temp/StagingArea/Data/Managed\Facebook.Client.dll" -injectCtor -assemblyPath "Temp/StagingArea" -pdb.[Temp/StagingArea/Data/Managed\Facebook.Client.dll]
    2. No symbols for Temp/StagingArea/Data/Managed\Facebook.Client.dll
    3. Injecting ctor
    4. Error while in assembly preprocessor Temp/StagingArea/Data/Managed\Facebook.Client.dll
    5. Object reference not set to an instance of an object.
    6.    at AssemblyPreprocessor.Utils.IsBaseType(TypeDefinition definition, String name)
    7.    at AssemblyPreprocessor.Utils.IsFromNamespace(TypeDefinition definition, String namezpace)
    8.    at AssemblyPreprocessor.ConstructorInjector.ShouldInject(TypeDefinition typeDefinition)
    9.    at AssemblyPreprocessor.ConstructorInjector.InjectConstructorsForTypesIn(ModuleDefinition moduleDefinition)
    10.    at AssemblyPreprocessor.Program.Main(String[] args)
    11.  
    Don't suppose you or anyone else has found a reason or even solution for it? I've been scratching my head over it for days!
     
  27. Murthy_Dumadu

    Murthy_Dumadu

    Joined:
    May 17, 2013
    Posts:
    33
    if ur dll file having the higher than .net 3.5 frame work it will show you that error

    main thing you need to remember that compile time u need lower version in run time u have to use the higher version dll then that will work.....!!!!!!!!!!

     
  28. Bash-Mills

    Bash-Mills

    Joined:
    Sep 15, 2013
    Posts:
    3
    Thanks for the reply. I have indeed used .NET 3.5 framework for the fake DLL as it shows in this guide:

    https://docs.unity3d.com/Documentation/Manual/wp8-plugins-guide-csharp.html

    The thing that strikes me as odd is that the file it's complaining about is Facebook.Client.dll which isn't even my file. Mine is called CSFacebook.dll which seems to be compiling fine. This leads me to a question: At the moment I have my .NET 4.5 "real" DLL and the .NET 3.5 "fake" DLL in the correct folders. Then I just have the C# Facebook SDK which my real dll references also in the /Plugins/WP8 folder. Do I need to make "fake" dlls for these too even though I never actually directly reference them in unity?
     
  29. Murthy_Dumadu

    Murthy_Dumadu

    Joined:
    May 17, 2013
    Posts:
    33
    Hii Zilys finally i am able to displaying the ads and in app also working now the problem is when add is displayed application gui buttons are not working even not responding ???? i guess it would be on pause state that means internally onAppllicationPause() will be called so please help me wt to do?? unity app is not running???


    I
     
  30. Murthy_Dumadu

    Murthy_Dumadu

    Joined:
    May 17, 2013
    Posts:
    33
    nneractiveAd: App Running in background
    The thread 0xfdc has exited with code 259 (0x103).
    The thread 0xb70 has exited with code 259 (0x103).
    The thread 0x6f4 has exited with code 259 (0x103).
    The thread 0xa30 has exited with code 259 (0x103).
    The thread 0x960 has exited with code 259 (0x103).
    The thread 0xfe0 has exited with code 259 (0x103).
    The thread 0x358 has exited with code 259 (0x103).
    The thread 0xf70 has exited with code 259 (0x103).
    The thread 0xce4 has exited with code 259 (0x103).
    The thread 0xf6c has exited with code 259 (0x103).
    The thread 0xda8 has exited with code 259 (0x103).
    The thread 0xa2c has exited with code 259 (0x103).
    The thread 0xe8c has exited with code 259 (0x103).
    The thread 0x6f8 has exited with code 259 (0x103).


    these are the responsive logsss
     
  31. Phil-AV

    Phil-AV

    Joined:
    Jul 9, 2012
    Posts:
    57
    @Bash Mills:

    The Unity developers are definitely aware of the issue and are dealing with it. We just need to be patient. Until then I'd possibly try creating a fake DLL for FacebookSDK.net and see if that works. I'd do it myself but I'm back on my Mac right now and don't have the time to switch over to my PC until at least tomorrow.

    If you could post any findings here I'd really appreciate it.
     
  32. weemundo

    weemundo

    Joined:
    Jul 29, 2013
    Posts:
    4
    Any update guys? I am facing the same issue as well.

     
  33. zeezeezee

    zeezeezee

    Joined:
    Aug 6, 2013
    Posts:
    20
    I think got the answer.

    The Unity Editor can NOT compile XAML files. This means you any XAML files in your C# library have to be removed.

    If you do need XAML files, then you can add them after in to the "Build" of your game in the Visual Studio Solution generated. Because you have to add the XAMLs after the build, you may want to use static functions.
     
  34. hirenkacha

    hirenkacha

    Joined:
    Apr 4, 2012
    Posts:
    10
    Hi @Phil-AV,

    I still didnt get, How to add facebook sdk in plugin folder? :(
    Is this like I just add the methods of facebook calls in Class library in dll file and add it to Plugins. Then add Facbook SDK to the solution in Build which was made by Unity for VS?
    Or I need to add all the class files compiled in DLL and added to the Plugins/WP8?

    Thanks in advance