Android Uniy3D IAP订阅

时间:2019-01-13 22:16:48

标签: c# android unity3d google-play in-app-purchase

我有一个适用于Android的Unity3D游戏,在此游戏中,我使用的是Unity IAP系统,一切正常,但是如果播放器没有我所拥有的三个订阅中的任何一个,我将无法获取可用。我当前的代码是这样:

  public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        // Purchasing has succeeded initializing. Collect our Purchasing references.
        Debug.Log("OnInitialized: PASS");
    m_GooglePlayExtensions = extensions.GetExtension<IGooglePlayStoreExtensions>();
        // Overall Purchasing system, configured with products for this application.
        m_StoreController = controller;
        // Store specific subsystem, for accessing device-specific store features.
        m_StoreExtensionProvider = extensions;
    Dictionary<string, string> Dict = m_GooglePlayExtensions.GetProductJSONDictionary();
    foreach ( Product item in controller.products.all)
    {


        if (item.receipt != null)
        {
            if (item.definition.type == ProductType.Subscription)
            {
                print("Subscription");

                string json = (Dict == null || !Dict.ContainsKey(item.definition.storeSpecificId)) ? null : Dict[item.definition.storeSpecificId];
                SubscriptionManager s = new SubscriptionManager(item, json);
                SubscriptionInfo info = s.getSubscriptionInfo();
                if (PlayerPrefs.GetInt("VIP") == 1)
                {
                    if (info.getProductId() == ProductVIP)
                    {
                        if (info.isSubscribed() == Result.False)
                        {
                            PlayerPrefs.SetInt("VIP", 0);
                        }
                    }
                }
                else if (PlayerPrefs.GetInt("VIP") == 2)
                {
                    if (info.getProductId() == ProductGVIP)
                    {
                        if (info.isSubscribed() == Result.False)
                        {
                            PlayerPrefs.SetInt("VIP", 0);
                        }
                    }
                }
                else if (PlayerPrefs.GetInt("VIP") == 3)
                {
                    if (info.getProductId() == ProductDVIP)
                    {
                        if (info.isSubscribed() == Result.False)
                        {
                            PlayerPrefs.SetInt("VIP", 0);
                        }
                    }
                }
            }

        }

当玩家购买任何订阅时,我将更改保存在PlayerPrefs中的Int“ VIP”的值,以便游戏可以知道是否有订阅以及哪个订阅。如果未订阅,则应获取的代码;如果是,则将VIP值更改为0,表示尚未激活订阅

0 个答案:

没有答案