This class will help you do your day to day virtual economy operations easily. You can give or take items from your users. You can buy items or upgrade them. You can also check their equipping status and change it.
 void SpawnCars()
 {
     Debug.Log("spawner car count " + cars.Count);
     try
     {
         Debug.Log("try " + "cars.Count"
                   + cars.Count);
         for (int i = 0; i < cars.Count; i++)
         {
             Debug.Log("cars[i]" + cars[i]);
             Debug.Log("showCaseTransform" + showCaseTransform);
             //instantiate cars from assets into scene
             cars[i] = Instantiate(cars[i]);
             cars[i].transform.parent =
                 platform.transform;
             cars[i].transform.position
                 = showCaseTransform.position;
             cars[i].SetActive(false);
         }
         //put currently selected car on platform
         foreach (GameObject car in cars)
         {
             Debug.Log(car.GetComponentInChildren <Car>());
             if ((car) && (car.GetComponentInChildren <Car>()) &&
                 (StoreInventory.IsVirtualGoodEquipped(car
                                                       .GetComponentInChildren <Car>().virtualGood.ItemId)))
             {
                 selectedCar = car;
                 break;
             }
         }
         if (!selectedCar) // if there's no selected car
         {
             Debug.Log("no selected car");
             //mark a bought car as selected
             foreach (GameObject car in cars)
             {
                 // at the beginning there's at least one bought car
                 if ((car) && (car.GetComponentInChildren <Car>()) &&
                     (car.GetComponentInChildren <Car>().virtualGood
                      .GetBalance() > 0))
                 {
                     selectedCar = car;
                     StoreInventory.EquipVirtualGood(car
                                                     .GetComponentInChildren <Car>().virtualGood.ItemId);
                     break;
                 }
             }
         }
         //sort by price
         cars = cars.OrderBy(o => o.GetComponentInChildren
                             <Car>().carData
                             .price).ToList <GameObject>();
         areCarsSpawned = true;
     }
     catch (Exception e)
     {
         Debug.Log("i caught this err " + e);
     }
 }
Exemple #2
0
 void CheckIAP_PurchaseStatus()
 {
     if (StoreInventory.GetItemBalance("No_Ads_Item_ID") >= 1)
     {
         GameController.NO_ADS_UNLOCKED = true;
     }
 }
        //will be called by soomla
        public void OnStoreInitialized()
        {
            Debug.Log("store init ");
            int timesPlayed = 0;

            if (PlayerPrefs.HasKey("times_played"))
            {
                timesPlayed = PlayerPrefs.GetInt("times_played");
            }

            Debug.Log(StoreInventory.GetItemBalance(MashinRunAssets.mashinRunCurrency.ItemId));
            if (timesPlayed == 0)
            {
                StoreInventory.BuyItem(MashinRunAssets.volksWagenCar.ItemId);
                StoreInventory.EquipVirtualGood(MashinRunAssets.volksWagenCar.ItemId);
            }
            timesPlayed++;
            PlayerPrefs.SetInt("times_played", timesPlayed);
            cars = DataManager.GetAllDataFromResourcesFolder
                   <GameObject>("Cars");
            Debug.Log("cars.Count " + cars.Count);
            Debug.Log("cars");
            Debug.Log("cars.Count" + cars.Count);
            camera = Camera.main;
        }
Exemple #4
0
        public void onGoodUpgrade(string message, bool alsoPush)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGoodUpgrade:" + message);

            var eventJSON = new JSONObject(message);

            VirtualGood vg  = (VirtualGood)StoreInfo.GetItemByItemId(eventJSON["itemId"].str);
            UpgradeVG   vgu = null;

            if (eventJSON.HasField("upgradeItemId") && !string.IsNullOrEmpty(eventJSON["upgradeItemId"].str))
            {
                vgu = (UpgradeVG)StoreInfo.GetItemByItemId(eventJSON["upgradeItemId"].str);
            }

            StoreInventory.RefreshOnGoodUpgrade(vg, vgu);

            StoreEvents.OnGoodUpgrade(vg, vgu);

            if (alsoPush)
            {
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
                sep.PushEventOnGoodUpgrade(vg, vgu);
#endif
            }
        }
 public void SelectCar()
 {
     //soomla will automatically unequip all other cars.
     //equip the current showcased car.
     StoreInventory.EquipVirtualGood(currentShowCasedCar.GetComponentInChildren <Car>
                                         ()
                                     .virtualGood.ItemId);
     selectedCar = currentShowCasedCar;
     UpdateUI();
 }
Exemple #6
0
 void OnMouseUp()
 {
     try {
         Debug.Log("attempt to purchase");
         StoreInventory.BuyItem("No_Ads_Item_ID");
     }
     catch (Exception e) {
         this.GetComponent <AudioSource>().Play();
         Debug.Log("SOOMLA/UNITY" + e.Message);
     }
 }
        public void BuyCar()
        {
            Car showCasedCar = currentShowCasedCar.
                               GetComponentInChildren <Car>();

            if (StoreInventory.GetItemBalance(MashinRunAssets.
                                              MASHIN_RUN_CURRENCY_ITEM_ID) >= showCasedCar.carData.price)
            {
                showCasedCar.virtualGood.Buy("somepayload");
                UpdateUI();
            }
        }
Exemple #8
0
        public void onSoomlaStoreInitialized(string message, bool alsoPush)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onSoomlaStoreInitialized");

            StoreInventory.RefreshLocalInventory();

            StoreEvents.OnSoomlaStoreInitialized();

            if (alsoPush)
            {
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
                sep.PushEventSoomlaStoreInitialized();
#endif
            }
        }
        public static void onGoodUnequipped(GoodUnEquippedEvent _Event, bool alsoPush)
        {
            SoomlaWpStore.domain.virtualGoods.EquippableVG good = _Event.GetEquippableVG();
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onVirtualGoodUnEquipped:" + good.getItemId());

            EquippableVG vg = (EquippableVG)StoreInfo.GetItemByItemId(good.getItemId());

            StoreInventory.RefreshOnGoodUnEquipped(vg);
            StoreEvents.OnGoodUnEquipped(vg);

            if (alsoPush)
            {
                sep.PushEventOnGoodUnequipped(_Event);
            }
        }
        public void AttemptBuyCar()
        {
            Car showCasedCar = currentShowCasedCar.
                               GetComponentInChildren <Car>();

            Debug.Log(((PurchaseWithVirtualItem)showCasedCar.virtualGood
                       .PurchaseType).Amount);
            if (StoreInventory.GetItemBalance(MashinRunAssets.
                                              MASHIN_RUN_CURRENCY_ITEM_ID) >= ((PurchaseWithVirtualItem)
                                                                               showCasedCar.virtualGood.PurchaseType).Amount /*price */)
            {
                uiManager.ShowDialog(buyDialog);
            }
            else
            {
                uiManager.ShowMessage(notEnoughMoneyMessage);
            }
        }
Exemple #11
0
        public static void onGoodBalanceChanged(GoodBalanceChangedEvent _Event, bool alsoPush)
        {
            SoomlaWpStore.domain.virtualGoods.VirtualGood good = _Event.GetGood();
            int balance     = _Event.GetBalance();
            int amountAdded = _Event.GetAmountAdded();

            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGoodBalanceChanged:" + good.getItemId() + " " + balance.ToString() + " " + amountAdded.ToString());

            VirtualGood vg = (VirtualGood)StoreInfo.GetItemByItemId(good.getItemId());

            StoreInventory.RefreshOnGoodBalanceChanged(vg, balance, amountAdded);
            StoreEvents.OnGoodBalanceChanged(vg, balance, amountAdded);

            if (alsoPush)
            {
                sep.PushEventOnGoodBalanceChanged(_Event);
            }
        }
Exemple #12
0
        public void onGoodUnequipped(string message, bool alsoPush)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onVirtualGoodUnEquipped:" + message);

            var eventJSON = new JSONObject(message);

            EquippableVG vg = (EquippableVG)StoreInfo.GetItemByItemId(eventJSON["itemId"].str);

            StoreInventory.RefreshOnGoodUnEquipped(vg);

            StoreEvents.OnGoodUnEquipped(vg);

            if (alsoPush)
            {
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
                sep.PushEventOnGoodUnequipped(vg);
#endif
            }
        }
Exemple #13
0
        public void onGoodBalanceChanged(string message, bool alsoPush)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGoodBalanceChanged:" + message);

            JSONObject eventJSON = new JSONObject(message);

            VirtualGood vg          = (VirtualGood)StoreInfo.GetItemByItemId(eventJSON["itemId"].str);
            int         balance     = (int)eventJSON["balance"].n;
            int         amountAdded = (int)eventJSON["amountAdded"].n;

            StoreInventory.RefreshOnGoodBalanceChanged(vg, balance, amountAdded);

            StoreEvents.OnGoodBalanceChanged(vg, balance, amountAdded);

            if (alsoPush)
            {
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
                sep.PushEventOnGoodBalanceChanged(vg, balance, amountAdded);
#endif
            }
        }
Exemple #14
0
        public static void onGoodUpgrade(GoodUpgradeEvent _Event, bool alsoPush)
        {
            SoomlaWpStore.domain.virtualGoods.VirtualGood good      = _Event.GetGood();
            SoomlaWpStore.domain.virtualGoods.UpgradeVG   upgradeVG = _Event.GetUpgradeVG();
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGoodUpgrade:" + good.getItemId() + " " + upgradeVG.getItemId());

            VirtualGood vg  = (VirtualGood)StoreInfo.GetItemByItemId(good.getItemId());
            UpgradeVG   vgu = null;

            if (upgradeVG != null)
            {
                vgu = (UpgradeVG)StoreInfo.GetItemByItemId(upgradeVG.getItemId());
            }
            StoreInventory.RefreshOnGoodUpgrade(vg, vgu);
            StoreEvents.OnGoodUpgrade(vg, vgu);

            if (alsoPush)
            {
                sep.PushEventOnGoodUpgrade(_Event);
            }
        }
Exemple #15
0
        public static void onCurrencyBalanceChanged(CurrencyBalanceChangedEvent _Event, bool alsoPush)
        {
            SoomlaWpStore.domain.virtualCurrencies.VirtualCurrency currency = _Event.GetCurrency();
            int balance     = _Event.GetBalance();
            int amountAdded = _Event.GetAmountAdded();

            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onCurrencyBalanceChanged" + currency.getItemId() + " " + balance.ToString() + " " + amountAdded.ToString());

            VirtualCurrency vc = (VirtualCurrency)StoreInfo.GetItemByItemId(currency.getItemId());

            StoreEvents.OnCurrencyBalanceChanged(vc, balance, amountAdded);

            StoreInventory.RefreshOnCurrencyBalanceChanged(vc, balance, amountAdded);

            //Why this line was added twice ??
            //StoreEvents.OnCurrencyBalanceChanged(vc, balance, amountAdded);

            if (alsoPush)
            {
                sep.PushEventOnCurrencyBalanceChanged(_Event);
            }
        }
        void UpdateUI()
        {
            Debug.Log("currentShowCasedCar" + currentShowCasedCar);

            if (!(currentShowCasedCar.GetComponentInChildren <Car>()) ||
                !(currentShowCasedCar.GetComponentInChildren <Car>()).carData)
            {
                return;
            }
            Car currentCar = currentShowCasedCar
                             .GetComponentInChildren <Car>();
            int currentShowCasedCarIndex = cars.FindIndex
                                               (x => x == currentShowCasedCar);

            if ((currentCar) && (currentCar.carData))
            {
                carPriceText.text = currentCar.carData.price.ToString();
                carNameText.text  = currentCar.carData.name.ToString();
                carSpeedText.text = currentCar.carData.speedRate.ToString();
            }
            if (currentShowCasedCarIndex == 0)
            //if there's no previous car
            {
                rightArrowButton.SetActive(true);
                leftArrowButton.SetActive(false);
            }
            else if (currentShowCasedCarIndex == cars.Count - 1)
            //if there's no next car
            {
                leftArrowButton.SetActive(true);
                rightArrowButton.SetActive(false);
            }
            else // if there's a next car and a previous car
            {
                leftArrowButton.SetActive(true);
                rightArrowButton.SetActive(true);
            }
            //if current car wasn't bought
            if ((currentCar) && (currentCar.carData) &&
                (currentCar.virtualGood.GetBalance() == 0))
            {
                carStatus.text = unBoughtString;
                carPriceUI.SetActive(true);
                carPriceText.text = currentCar.carData.price
                                    .ToString();
                buyCarButton.SetActive(true);
                selectCarButton.SetActive(false);
            }
            else if ((currentCar) && (currentCar.carData) &&
                     (currentCar.virtualGood.GetBalance() > 0))
            //if current showcased car was bought
            {
                carStatus.text = boughtString;
                buyCarButton.SetActive(false);
                carPriceUI.SetActive(false);
                if (!StoreInventory.IsVirtualGoodEquipped(
                        currentCar.virtualGood.ItemId))
                {
                    selectCarButton.SetActive(true);
                }
                else // if current show cased car is selected
                {
                    selectCarButton.SetActive(false);
                }
            }
            //if either there is no car or it doesn't have a car data attached.
            else if (!(currentCar) || !(currentCar.carData))

            {
                Debug.Log("couldn't update UI because either there's no car , " +
                          "or it doesn't have a car data attached");
            }
        }
        private bool checkTargetBalance(VirtualItem item)
        {
            int balance = StoreInventory.GetItemBalance(item.ItemId);

            return(balance >= Amount);
        }