I'm currently writing an In-App purchase plugin for Unity in Objective-C using pure C as the API between unity and the objective-c code.
Introduction to the problem I am facing
The basic functionality already works. That is, I already have a very basic function call in my plugin to start a product request to the Apple App Store which can be called from Unity. In the unity script you simply call this method like this:
[DllImport ("__Internal")]
private static extern void RequestProducts(string[] productIdentifiers, int arrayCount);
public static void RequestProductData( string[] productIdentifiers )
{
RequestProducts(productIdentifiers, productIdentifiers.Length);
}
This calls the C function which looks like this:
void RequestProducts(char* productIdentifiers[], int arrayCount)
{
// Call the In-App purchase manager to initialize the product request
[[InAppPurchaseManager sharedInAppPurchaseManager] RequestProductData:productIdentifierCollection];
}
Now I've omitted the part of the C function which takes the productIdentifiers array and converts it into an NSArray just to keep it simple and explain the problem I'm trying to solve.
Now the InAppPurchaseManager class is a singleton class. The RequestProductData method initiates the product request to the app store.
The Problem
When the StoreKit gives me a response back with all the products, this is where it starts to get tricky for me. I want to pass all the relevant data for each product retrieved back to the unity C# script so you can handle the data in your game. This means storing:
-The name of each product
-The description of each product
-The price of each product
An obvious solution would be to make a struct or class which contains this information and then make an instance for each product and put them all into an array.
The Question
Now the question is, how would I go about sending this array of complex data structures back to the Unity script? Unity's official documentation mentions that you can send messages back to Unity using this method call: UnitySendMessage("GameObjectName1", "MethodName1", "Message to send");
I got the call to work, but the obvious problem is that it only allows you to send strings.
So:
how would I go about sending arrays of complex data structures back to the Unity script? Is this even possible?