How to implement Windows Phone code to communicate with unity (plug-in mode)

Source: Internet
Author: User

Some crap

Original address:

http://imwper.com/unity/petto/%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0windows-phone%E4%BB%A3%E7%A0%81%E4%B8% 8eunity%e7%9b%b8%e4%ba%92%e9%80%9a%e4%bf%a1%ef%bc%88%e6%8f%92%e4%bb%b6%e6%96%b9%e5%bc%8f%ef%bc%89.html

My blog moved here to Www.imwper.com, and all my technical blogs should be starting here, and then syncing to Cnblogs.

Today is my first cottage game landing WP store. To tell the truth, these days for this game really hard, I also do not bother to pour bitterness, is the line. Thanks so much for the encouragement and support of so many good friends, knowing that it is a cottage, give me praise. However, the cottage of the well, there are always some people who do not, stand in the perspective of justice to give severe criticism. This itself is not a problem, the cottage is not right, not to criticize, even if you have all kinds of difficulties, you have to hehe. So I gladly accept it, but the game will not be off the shelf, and may later in the premise without affecting the experience of advertising, in exchange for a day of 10 dollars of breakfast money (why?) I have left the most ideal employer in the eyes of many people, without any income. Without making some money, I would be starved to death. But what does it matter if I starve and starve to death? "Anyway the cottage is wrong, I just can't stand it"). I hope you can understand, I believe most people can understand. I have always liked the simple and rough way to solve the problem, the most like a few big attacking grinding chirp scold to scold to what result not, have a mouth addiction. So I would like to really hate my people come straight to me and say, or call, or QQ voice? I can explain the White said, really say do not understand on a fight, lost the mistake, it is knot. But experience shows that after meeting with me basically will not fight up, even if the hands, eventually become friends. After all, can use the same species people look wonderful way to solve the problem, should be very cast temper.

The previous blog is about one of the ways that WP and unity call each other-events.

This said that the most commonly used is also a strong reuse of plug-in mode. There will be a lot of pictures and a small amount of code. Figure more kill cats, but blog intentions, hope to see this article of people some help. Buddhist speaking, the strong self-degree, the holy person. I am a cock silk, can help some people who know or do not know, also is a small merit one.

Oh yes, this article is a reference to the official unity document, shouldn't it be a cottage? If you want to say yes, then I can not do nothing but hehe.

Original link: http://docs.unity3d.com/Manual/wp8-plugins-guide-csharp.html

Write WP Plugin

OK, get in the chase.

First create a blank solution, I gave him the name PettoStudio.WP.Plugins, you can be arbitrary. Steps to look at the picture is good:

Then make sure to enter a blank solution without engineering. Right-click solution-> Add-New project---Find WP project TEMPLATE (because vs2012 and 2013 are not the same, can not be written in detail), select WP Class Library project.

Project name at random, suggest and just solution agree on the line, but inconsistent I also can't hit you.

Click OK.

Select the SDK version is 8.0 (if you have more than one version of the WP SDK)

All right. WP plug-in engineering has been built.

Note that if your project name does not match the name of the solution, you should do one more thing here (don't listen to me.) That!)

Right-click your project name--Properties. Change the assembly name and the default namespace name to the same name as your solution.

WP Project preparation is complete, write code.

Add a class where we name "AUV" and then write a static method (or attribute) here. Let's simply return a string. The complete code is as follows.

public static string getauvstring ()        {            return ' WP8? AUV!!! ";        }

  

All right. The WP8 DLL is now complete. But that's just half the plug-in development.

Creating a fake Dll

Next. Create a new project, yes, still in this solution, but at this point the template to choose the Windows Desktop Program Class library, in addition. NET version to choose 3.5. (What?) Why? Why does it have to be 3.5? Well, I know where I am. Ask Microsoft to go with unity! )

The project name cannot be written in the same way as solution. Just write Fakedll (fake dynamic link library. Oh

Once created, you will also need to change the name of the assembly and the default namespace to match solution. This was done to deceive unity successfully. It must be said that Microsoft and unity in the implementation of plug-ins is really elegant, it should be done with minimal changes (add) to get the desired results. (It's also possible to bring a big hole for our developers ....) )

OK, next or repeat operation, in this Fakedll project created in the WP project the same class name, the same method name. The only thing that can be different is the realization inside. As follows:

Here's the code in the AUV class:

public class AUV    {public        static string getauvstring ()        {            return ' not WP8? AUV!!! ";        }    }

  

Well. This is "not WP8?" AUV!!! ";

To this, the plug-in development is complete, compiling two DLLs.

Add to Unity

Copy the DLL generated by the Fakedll project to the Assect/plugins Path of unity (what? Is there a plugins folder?) So you're not going to create one yourself? );

Copy the WP project-generated DLL to Unity's ASSECT/PLUGINS/WP8 path (note that WP8 is uppercase and I don't know if lowercase can be used.) I am too lazy to try, if there is a special diligent (idle egg pain) friend can try, by the way to tell me (thank you)).

Results after completion of the above operation

Then create a script test.cs, open vs for editing. The code is as follows:

private string _auv;    void Ongui ()    {        GUI. Label (New Rect (n, N, Max, _AUV);         if (GUI. button (new Rect (N, A, Max, Max), "befucked"))        {            _AUV = PettoStudio.WP.Plugins.AUV.GetAUVString ();        }    }

  

and then save. Go back to unity and try it out and click the befucked button to see the results. What is the reality?

"Not WP8?" AUV!!! " Why is this? What code does this execute? Yes, it's the code in Fakedll! Why not in the WP8?

Ah, because you're doing it under Windows, Unity automatically executes the code in the plug-in based on the environment.

OK, let's deploy to WP and try it out.

Then look at the results of the execution:

"WP8?" AUV!!! "; Yes, it is the result we want.

OK, at this point, WP and unity call each other way-the plug-in mode is finished. In this way you can write lots and lots of libraries to facilitate reuse later. For example, some task in the market, choose photos, pay inside, and so on.

I also will enrich my PettoStudio.WP.Plugins, in the future for everyone free direct use.

In addition to the previous introduction of the event mode, basically can cover all the unity, WP calls between the scene.

Summarize

All right, that's all. Trapped dead.

Say to yourself, come on. To see this article you say, refueling.

I believe that a lot of people play games to achieve a childhood dream. In front of the dream, anything is a decoration, no difficulty will not realize the value.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.