예제 #1
0
        /// <summary>
        /// Callback invoked after initiating a restore attempt.
        /// </summary>
        public static void OnTransactionsRestored(bool success)
        {
            instance.isRestoringTransactions = false;

            if (!success)
            {
                string error = "Restore failed.";
                if (isDebug)
                {
                    Debug.Log("IAPManager reports: " + error);
                }
                purchaseFailedEvent(error);
                return;
            }

            #if PLAYFAB && !PLAYFAB_VALIDATION
            List <string> restoreProducts = DBManager.GetAllPurchased(true);
            restoreProducts.RemoveAll(p => controller.products.WithID(p) == null);
            GetInstance().StartCoroutine(PlayfabManager.SetPurchase(restoreProducts));
            #endif

            purchaseSucceededEvent("restore");
        }
        /// <summary>
        /// Sets up shop items based on previous purchases, meaning we
        /// set them to 'purchased' thus not purchasable in the GUI.
        /// Also select the items that were selected by the player before.
        /// </summary>
        public static void SetItemState()
        {
            //this method is based on data from the database,
            //so if we don't have a DBManager instance don't continue
            if (!DBManager.GetInstance())
            {
                return;
            }

            //get array of purchased item ids, look them up in our
            //shop item dictionary and set them to purchased
            List <string> purchasedItems = DBManager.GetAllPurchased();

            for (int i = 0; i < purchasedItems.Count; i++)
            {
                if (instance.IAPItems.ContainsKey(purchasedItems[i]) &&
                    IAPManager.GetIAPUpgrades(purchasedItems[i]).Count == 0)
                {
                    instance.IAPItems[purchasedItems[i]].Purchased(true);
                }
            }

            //get dictionary of selected item ids, look them up in our
            //shop item dictionary and set the checkbox component to selected
            Dictionary <string, List <string> > selectedItems = DBManager.GetAllSelected();

            foreach (string key in selectedItems.Keys)
            {
                for (int i = 0; i < selectedItems[key].Count; i++)
                {
                    if (instance.IAPItems.ContainsKey(selectedItems[key][i]))
                    {
                        instance.IAPItems[selectedItems[key][i]].IsSelected(true);
                    }
                }
            }
        }