Game Development Reference
In-Depth Information
Access to the platform
If you reverse the previous implementation, there are cases where you need to access a
specific behavior on the native platform itself.
If you need a bit more interactivity from your Unity project, and you wish to enable Unity
to communicate directly to the platform, then the following are the two common methods
to achieve this:
• Static events (.NET platforms only)
• Plugins
Static events in your Unity project
We covered events back in Chapter 5 , NPCs and Interactions , to enable a loose coupling
between an action and a dependency. We can reuse events to bridge the gap between Un-
ity and the .NET platforms such as Windows and Windows Phone.
We will begin by defining a static event in Unity, which is intended to indicate an ac-
tion the project needs the native platform to enact:
public static EventHandler PurchaseRequested;
public static void Purchase(string productID)
{
if (PurchaseRequested != null)
{
PurchaseRequested(productID, null);
}
}
Search WWH ::




Custom Search