我刚买了Prime31的“Google In App Billing Plugin for unity3d”。我不明白如何在我想开发的游戏中使用它。
你能告诉我一个代码示例吗?我知道我需要使用我的app键,但我不知道接下来该做什么。 如何使用此插件进行测试购买?
请尽可能多地帮助,因为我在这个问题上坚持了很长一段时间。
这是我的一些名为MoneyTakerScript的“购买者”对象(继承自MonoBehaviour):
void Start()
{
string key = "My App Key...";
GoogleIAB.init(key);
var skus = new string[] { "cl.48931", "tp.58932", "mmm.68393" };
GoogleIAB.queryInventory( skus );
TPS = GameObject.Find("TPBtn").GetComponent(typeof(TPScript)) as TPScript;
CLS = GameObject.Find("CLBtn").GetComponent(typeof(CLScript)) as CLScript;
MMM = GameObject.Find("MMBtn").GetComponent(typeof(MMMScript)) as MMMScript;
}
public void Purchase(string ProductId)
{
GoogleIAB.purchaseProduct(ProductId);
}
public void UseProduct(string ProductId)
{
if (ProductId.Contains("cl"))
{
CLS.MakeCL();
}
if (ProductId.Contains("tp"))
{
TPS.MakeTP();
}
if (ProductId.Contains("mmm"))
{
MMM.MakeMMM();
}
GoogleIAB.consumeProduct(ProductId);
}
这是我的一些“购买清单”对象代码:
void purchaseSucceededEvent(GooglePurchase purchase)
{
//Debug.Log( "purchaseSucceededEvent: " + purchase );
MoneyScript.UseProduct(purchase.productId);
}
void Start()
{
MoneyScript = GameObject.Find("MoneyTaker").GetComponent(typeof(MoneyTakerScript)) as
MoneyTakerScript;
}
答案 0 :(得分:2)
我找到了问题并解决了它!
由于某些原因,我的AndroidManifest.Xml中缺少此行:
<activity android:name="com.prime31.GoogleIABProxyActivity"></activity>
刚刚添加了该行,现在我有In App Purchase !!