Exemplo n.º 1
0
            private IAPButtonStoreManager()
            {
                catalog = ProductCatalog.LoadDefaultCatalog();

                StandardPurchasingModule module = StandardPurchasingModule.Instance();

                module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser;

                ConfigurationBuilder builder = ConfigurationBuilder.Instance(module);

                foreach (var product in catalog.allProducts)
                {
                    if (product.allStoreIDs.Count > 0)
                    {
                        var ids = new IDs();
                        foreach (var storeID in product.allStoreIDs)
                        {
                            ids.Add(storeID.id, storeID.store);
                        }
                        builder.AddProduct(product.id, product.type, ids);
                        Debug.Log(string.Format("Add Product: {0}", product.id));
                    }
                    else
                    {
                        builder.AddProduct(product.id, product.type);
                        Debug.Log(string.Format("Add Product: {0}", product.id));
                    }
                }

                UnityPurchasing.Initialize(this, builder);
            }
Exemplo n.º 2
0
        static void InitializeCodelessPurchasingOnLoad()
        {
            ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog();

            if (catalog.enableCodelessAutoInitialization && !catalog.IsEmpty() && instance == null)
            {
                CreateCodelessIAPStoreListenerInstance();
            }
        }
Exemplo n.º 3
0
        public ProductCatalog LoadDefaultCatalog()
        {
            var asset = Resources.Load("IAPProductCatalog") as TextAsset;

            if (asset != null)
            {
                return(ProductCatalog.FromTextAsset(asset));
            }
            else
            {
                return(new ProductCatalog());
            }
        }
Exemplo n.º 4
0
            private IAPButtonStoreManager()
            {
                catalog = ProductCatalog.LoadDefaultCatalog();

                StandardPurchasingModule module = StandardPurchasingModule.Instance();

                module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser;

                ConfigurationBuilder builder = ConfigurationBuilder.Instance(module);

                IAPConfigurationHelper.PopulateConfigurationBuilder(ref builder, catalog);

                UnityPurchasing.Initialize(this, builder);
            }
Exemplo n.º 5
0
        // This is now being used by the INativeStore implementation
        public void StoreRetrieveProducts(ReadOnlyCollection <ProductDefinition> productDefinitions)
        {
            var products = new List <ProductDescription>();

            foreach (var product in productDefinitions)
            {
                if (unavailableProductId != product.id)
                {
                    var            metadata = new ProductMetadata("$0.01", "Fake title for " + product.id, "Fake description", "USD", 0.01m);
                    ProductCatalog catalog  = ProductCatalog.LoadDefaultCatalog();
                    if (catalog != null)
                    {
                        foreach (var item in catalog.allProducts)
                        {
                            if (item.id == product.id)
                            {
                                metadata = new ProductMetadata(item.googlePrice.value.ToString(), item.defaultDescription.Title, item.defaultDescription.Description, "USD", item.googlePrice.value);
                            }
                        }
                    }
                    products.Add(new ProductDescription(product.storeSpecificId, metadata));
                }
            }

            Action <bool, InitializationFailureReason> handleAllowInitializeOrRetrieveProducts =
                (bool allow, InitializationFailureReason failureReason) =>
            {
                if (allow)
                {
                    m_Biller.OnProductsRetrieved(products);

                    // Since iOS is already rigged to work this way might as well just use it...
                    // *** if we want to use this change without Promo then we'll need to use reflection here
                    Promo.ProvideProductsToAds(this, m_Biller);
                }
                else
                {
                    m_Biller.OnSetupFailed(failureReason);
                }
            };

            // To mimic typical store behavior, only display RetrieveProducts dialog for developers
            if (!(UIMode == FakeStoreUIMode.DeveloperUser &&
                  StartUI <InitializationFailureReason> (productDefinitions, DialogType.RetrieveProducts, handleAllowInitializeOrRetrieveProducts)))
            {
                // Default non-UI FakeStore RetrieveProducts behavior is to succeed
                handleAllowInitializeOrRetrieveProducts(true, InitializationFailureReason.AppNotKnown);
            }
        }
Exemplo n.º 6
0
        public override void OnInspectorGUI()
        {
            IAPButton button = (IAPButton)target;

            serializedObject.Update();

            EditorGUILayout.LabelField(new GUIContent("Product ID:", "Select a product from the IAP catalog"));

            if (validIDs == null)
            {
                var catalog = ProductCatalog.LoadDefaultCatalog();

                validIDs = new List <string>();
                validIDs.Add(kNoProduct);
                foreach (var product in catalog.allProducts)
                {
                    validIDs.Add(product.id);
                }
            }

            int currentIndex = string.IsNullOrEmpty(button.productId) ? 0 : validIDs.IndexOf(button.productId);
            int newIndex     = EditorGUILayout.Popup(currentIndex, validIDs.ToArray());

            if (newIndex > 0 && newIndex < validIDs.Count)
            {
                button.productId = validIDs[newIndex];
            }
            else
            {
                button.productId = string.Empty;
            }

            if (GUILayout.Button("IAP Catalog..."))
            {
                ProductCatalogEditor.ShowWindow();
            }

            DrawPropertiesExcluding(serializedObject, excludedFields);

            serializedObject.ApplyModifiedProperties();
        }
        public override void OnInspectorGUI()
        {
            IAPButton button = (IAPButton)target;

            serializedObject.Update();

            if (button.buttonType == IAPButton.ButtonType.Purchase)
            {
                EditorGUILayout.LabelField(new GUIContent("Product ID:", "Select a product from the IAP catalog"));

                var catalog = ProductCatalog.LoadDefaultCatalog();

                m_ValidIDs.Clear();
                m_ValidIDs.Add(kNoProduct);
                foreach (var product in catalog.allProducts)
                {
                    m_ValidIDs.Add(product.id);
                }

                int currentIndex = string.IsNullOrEmpty(button.productId) ? 0 : m_ValidIDs.IndexOf(button.productId);
                int newIndex     = EditorGUILayout.Popup(currentIndex, m_ValidIDs.ToArray());
                if (newIndex > 0 && newIndex < m_ValidIDs.Count)
                {
                    m_ProductIDProperty.stringValue = m_ValidIDs[newIndex];
                }
                else
                {
                    m_ProductIDProperty.stringValue = string.Empty;
                }

                if (GUILayout.Button("IAP Catalog..."))
                {
                    ProductCatalogEditor.ShowWindow();
                }
            }

            DrawPropertiesExcluding(serializedObject, button.buttonType == IAPButton.ButtonType.Restore ? restoreButtonExcludedFields : excludedFields);

            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 8
0
 private CodelessIAPStoreListener()
 {
     catalog = ProductCatalog.LoadDefaultCatalog();
 }
Exemplo n.º 9
0
        /// Populate a ConfigurationBuilder with products from a ProductCatalog
        public static void PopulateConfigurationBuilder(ref ConfigurationBuilder builder, ProductCatalog catalog)
        {
            foreach (var product in catalog.allValidProducts)
            {
                IDs ids = null;

                if (product.allStoreIDs.Count > 0)
                {
                    ids = new IDs();
                    foreach (var storeID in product.allStoreIDs)
                    {
                        ids.Add(storeID.id, storeID.store);
                    }
                }

#if UNITY_2017_2_OR_NEWER
                var payoutDefinitions = new List <PayoutDefinition>();
                foreach (var payout in product.Payouts)
                {
                    payoutDefinitions.Add(new PayoutDefinition(payout.typeString, payout.subtype, payout.quantity, payout.data));
                }
                builder.AddProduct(product.id, product.type, ids, payoutDefinitions.ToArray());
#else
                builder.AddProduct(product.id, product.type, ids);
#endif
            }
        }
Exemplo n.º 10
0
        public static void CreateStore()
        {
            GameObject controlsRoot = GameObject.Find("Controls");
            GameObject storeRoot;

            ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog();

            if (controlsRoot.transform.Find("Store") == null)
            {
                GameObject storePrefab = AssetDatabase.LoadAssetAtPath("Assets/Zyndo/Prefabs/Store/Store.prefab", typeof(GameObject)) as GameObject;
                //create the root
                storeRoot = GameObject.Instantiate(storePrefab, controlsRoot.transform) as GameObject;
                storeRoot.transform.SetAsLastSibling();
                storeRoot.name = "Store";
                RectTransform rectTransform = (RectTransform)storeRoot.transform;
                rectTransform.offsetMin = new Vector2(0, 0);
                rectTransform.offsetMax = new Vector2(0, 0);

                /*if (EditorUtility.DisplayDialog ("Create Store From Catalog", string.Format("A store hasn't existed in this scene thus far, do you want to automatically connect into into the NavBar?."), "Okay", "No"))
                 * {
                 *
                 *      ToolbarNavigation toolbarNav = controlsRoot.transform.GetComponentInChildren<ToolbarNavigation>(true);
                 *      if (toolbarNav != null)
                 *      {
                 *              //Create Menu Item
                 *
                 *              GameObject storeNavBarPF = AssetDatabase.LoadAssetAtPath("Assets/Zyndo/Prefabs/Store/StoreNavBar.prefab", typeof(GameObject)) as GameObject;
                 *              GameObject storeNavBarItem = GameObject.Instantiate(storeNavBarPF);
                 *              Toggle toggle = storeNavBarItem.GetComponent<Toggle> ();
                 *              Text text = storeNavBarItem.GetComponent<Text> ();
                 *              text.text = "Store";
                 *              storeNavBarItem.name = "Store";
                 *              UnityEngine.Events.UnityAction action1 = (val) => { toolbarNav.SetActive(storeRoot); };
                 *
                 *              toggle.onValueChanged.AddListener (action1);
                 *              //Add to NavBar
                 *              storeNavBarItem.transform.SetParent(toolbarNav.transform, false);
                 *              storeNavBarItem.transform.SetSiblingIndex (toolbarNav.transform.childCount - 2);
                 *              toolbarNav.AddToolBarMember (storeNavBarItem, toolbarNav.toolbarMembers.Length - 2);
                 *      }
                 * }*/
            }
            else
            {
                storeRoot = controlsRoot.transform.Find("Store").gameObject;
            }
            storeRoot.SetActive(true);
            GameObject contentRoot = GameObject.Find("Content");
            int        numProducts = catalog.allProducts.Count;
            int        newItem     = 0;
            int        catID       = 0;

            foreach (var product in catalog.allProducts)
            {
                catID++;
                string updatedText = String.Format("{0}/{1} Products Complete", catID, numProducts);
                if (EditorUtility.DisplayCancelableProgressBar("Progress", updatedText, (float)catID / numProducts))
                {
                    EditorUtility.ClearProgressBar();
                    return;
                }

                if (contentRoot.transform.Find("StoreItem_" + product.id) == null)
                {
                    GameObject storeItemPF = AssetDatabase.LoadAssetAtPath("Assets/Zyndo/Prefabs/Store/StoreItem.prefab", typeof(GameObject)) as GameObject;
                    GameObject storeItem   = GameObject.Instantiate(storeItemPF, contentRoot.transform) as GameObject;
                    storeItem.name = "StoreItem_" + product.id;
                    ZyndoIAPButton zyndoIAPButton = storeItem.GetComponentInChildren <ZyndoIAPButton> ();
                    zyndoIAPButton.productId = product.id;

                    PurchaseAccessToScene purchaseAccessToScene = storeItem.GetComponentInChildren <PurchaseAccessToScene> ();
                    if (purchaseAccessToScene != null)
                    {
                        purchaseAccessToScene.SceneToBuy = "Need To Fill In";
                    }
                    newItem++;
                }
            }
            Transform restoreGO = contentRoot.transform.Find("StoreItemRestore");

            if (restoreGO == null)
            {
                GameObject restorePF = AssetDatabase.LoadAssetAtPath("Assets/Zyndo/Prefabs/Store/StoreItemRestore.prefab", typeof(GameObject)) as GameObject;
                //create the root
                restoreGO = (GameObject.Instantiate(restorePF, contentRoot.transform) as GameObject).transform;
                restoreGO.gameObject.name = "StoreItemRestore";
            }
            restoreGO.SetAsLastSibling();

            storeRoot.SetActive(false);

            EditorUtility.ClearProgressBar();
            EditorUtility.DisplayDialog("Create Store From Catalog", string.Format("Store created with {0} StoreItem(s) created, please goto each button and set SceneToBuy on the PurchaseAccessToScene component.", newItem), "Okay");
        }
Exemplo n.º 11
0
 public static string Serialize(ProductCatalog catalog)
 {
     return(JsonUtility.ToJson(catalog));
 }