从纯C插件到Unity C#脚本传递复杂数据类型 [英] Passing complex data type from a pure c plugin to Unity C# scripts

查看:112
本文介绍了从纯C插件到Unity C#脚本传递复杂数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是纯C作为团结和Objective-C的code之间的API目前正在写一个应用程序内购买插件团结在Objective-C。

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.

介绍我面临的问题

的基本功能已经起作用。也就是说,我已经在我的插件一个非常基本的函数调用来启动一个产品要求苹果App Store可以从统一调用。在统一的脚本您只需调用这个方法是这样的:

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);
}

这调用C函数看起来像这样:

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];
}

现在我省略C函数它接受productIdentifiers阵列并将其转换成一个NSArray的一部分,只是为了保持它的简单,并解释我试图解决的问题。

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.

现在的InAppPurchaseManager类是一个单例类。该RequestProductData方法启动产品请求到应用程序商店。

Now the InAppPurchaseManager class is a singleton class. The RequestProductData method initiates the product request to the app store.

问题

当StoreKit给我回一个响应的所有产品,这就是它开始变得棘手我。我想通过所有相关数据检索回统一C#脚本,所以你可以在你的游戏处理数据的每一个产品。这意味着存储:

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

-The name of each product

每个产品的说明-The

-The description of each product

每个产品的价格-The

-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.

问题

现在的问题是,我怎么会去送这个数组复杂的数据结构的回统一脚本? Unity的官方文档中提到,您可以使用此方法调用将消息发送回统一:
UnitySendMessage(GameObjectName1,MethodName1,消息派);

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.

所以:

我如何将着手发送复杂的数据结构数组回到统一的脚本?这甚至可能?

推荐答案

跟进我的评论和您的评论:如果你想要一个强大的解决方案,我会建议您检查出的这个答案。如果这是什么性能的关键,那么你将要得到更多的手动与你的序列化。因此,如何表现的关键是这种转移的数据?

Follow up on my comment and your comment: if you want a robust solution, I would recommend that you check out this answer. If this is something performance critical, then you will have to get a lot more "manual" with your serialization. So how performance critical is this transfer of data?

这篇关于从纯C插件到Unity C#脚本传递复杂数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆