示例#1
0
        /// <summary>
        /// Purchase overload for virtual products, as they differ in their workflow on PlayFab.
        /// Also the virtual currency funds are checked locally before forwarding the request to PlayFab.
        /// </summary>
        public void Purchase(IAPObject obj)
        {
            int curIndex = 0;

            for (int i = 0; i < obj.virtualPrice.Count; i++)
            {
                if (obj.virtualPrice[i].amount != 0)
                {
                    curIndex = i;
                    break;
                }
            }

            //local check before doing the request
            if (DBManager.GetFunds(obj.virtualPrice[curIndex].name) < obj.virtualPrice[curIndex].amount)
            {
                IAPManager.OnPurchaseFailed("Insufficient Funds.");
                return;
            }

            PurchaseItemRequest request = new PurchaseItemRequest()
            {
                ItemId          = obj.id,
                VirtualCurrency = obj.virtualPrice[curIndex].name.Substring(0, 2).ToUpper(),
                Price           = obj.virtualPrice[curIndex].amount
            };

            PlayFabClientAPI.PurchaseItem(request, OnPurchaseSucceeded, OnVirtualPurchaseFailed);
        }
示例#2
0
        //starts a coroutine with the desired target value
        void UpdateValue(string s)
        {
            //stop existing text animation routines,
            //we don't want to have two running at the same time
            StopCoroutine("CountTo");

            //if this gameobject is active and visible in our GUI,
            //start text animation to the current currency value
            //(if it isn't active, the value will be updated in OnEnable())
            if (gameObject.activeInHierarchy)
            {
                StartCoroutine("CountTo", DBManager.GetFunds(currency));
            }
        }
示例#3
0
        void OnEnable()
        {
            //subscribe to successful purchase/update event,
            //it could be that the player obtained currency
            IAPManager.purchaseSucceededEvent += UpdateValue;
            DBManager.updatedDataEvent        += UpdateValue;

            //update currency display right away
            if (!DBManager.GetInstance())
            {
                return;
            }
            //get current currency value
            int funds = DBManager.GetFunds(currency);

            //display value in the UILabel
            label.text = funds.ToString();
            //store value
            curValue = funds;
        }