In this guide we will create a Unity Plugin for Windows Phone which uses Windows Phone specific API to get device name. On other devices such information is not available, so we will return “Not Windows Phone” string instead.
To create a plugin specific to Windows Phone, create a new solution in Visual Studio. Select Other Project Types -> Visual Studio Solutions -> Blank Solution:
Next, you’ll need to add two projects, one for Windows Phone (real DLL) and one for Editor (fake DLL). In Solution Explorer, right click the newly created solution and select add project:
Select Windows Phone Class Library template. We’ll name the project “RealDLL” for clarity sakes:
When prompt, make sure to select Windows Phone 8.0 OS, rather than Windows Phone 7.1:
Once the project is created, go to its properties and change Assembly name and Default namespace to your solution name:
Next, open file “Class1.cs” and change its namespace to solution name as well:
Add Windows Phone specific functionally to the project. In this example, we’ll make a property to get device name:
Build the Solution. 2 files should be created:
Alright, the first part is done. Now we need to create the fake DLL for the editor to use. Create a new project again, and this time, select Windows -> Class Library template. Make sure to change the .NET framework to 3.5!
Once again, change Assembly name and Default namespace in project properties and change the namespace of the class. Next, implement identical non-private methods/fields/properties as in the real DLL:
Build the solution. 2 more files should be created:
That’s it! The plugins were created. To import them to your Unity project, copy the FakeDLL to <UnityProjectPath>/Assets/Plugins:
And the RealDLL to <UnityProjectPath>/Assets/Plugins/WP8:
Finally, write a script to make use of the new plugin (and don’t forget to attach it to the camera!):
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.