private void AddItem(InventoryItemModel itemInformation) { var newItem = Instantiate(itemPrefab, itemParent); newItem.GetComponent <InventoryItemUI>().Initialize(itemInformation); _items.Add(newItem); }
public void ConsumeInventoryItem(InventoryItemModel item, int count = 1, Action <InventoryItemModel> onSuccess = null, Action <Error> onError = null, bool isConfirmationRequired = true) { var onConfirmation = new Action(() => { var isFinished = false; PopupFactory.Instance.CreateWaiting().SetCloseCondition(() => isFinished); SdkInventoryLogic.Instance.ConsumeInventoryItem(item, count, onSuccess: consumedItem => { isFinished = true; onSuccess?.Invoke(consumedItem); }, onError: error => { isFinished = true; StoreDemoPopup.ShowError(error); onError?.Invoke(error); }); }); if (isConfirmationRequired) { StoreDemoPopup.ShowConsumeConfirmation(item.Name, (uint)count, onConfirmation, () => onError?.Invoke(null)); } else { onConfirmation?.Invoke(); } }
private void DrawItemsCount(InventoryItemModel model) { if (model.RemainingUses == null || itemQuantityImage == null || itemQuantityText == null) { return; } EnableQuantityImage(); itemQuantityText.text = model.RemainingUses.Value.ToString(); }
public void ConsumeInventoryItem(InventoryItemModel item, int?count = 1, Action <InventoryItemModel> onSuccess = null, Action <Error> onError = null) { var consumeItem = new ConsumeItem { sku = item.Sku, instance_id = item.InstanceId, quantity = count }; XsollaStore.Instance.ConsumeInventoryItem(XsollaSettings.StoreProjectId, consumeItem, onSuccess: () => onSuccess?.Invoke(item), onError); }
private void TryUpTheLevel() { var userCurrency = UserInventory.Instance.Balance?.Find(currency => _targetCurrency.Sku == currency.Sku); if (userCurrency == null) { Debug.Log("UserInventory does not contain required currency"); return; } if (userCurrency.Amount >= LevelUpPrice) { var levelUpPayment = new InventoryItemModel() { Name = _targetCurrency.Name, Sku = _targetCurrency.Sku, }; Action onSuccessConsume = () => { _characterLevel++; SaveLevel(_characterLevelEntry, _characterLevel); ShowLevel(_characterLevel); if (UserInventory.IsExist) { UserInventory.Instance.Refresh(onError: StoreDemoPopup.ShowError); } }; if (DemoMarker.IsInventoryPartAvailable) { DemoInventory.Instance.ConsumeInventoryItem( levelUpPayment, (int)LevelUpPrice, onSuccess: _ => onSuccessConsume.Invoke(), onError: _ => Debug.Log("Could not consume virtual currency")); } else { Debug.LogError("Character level up supposed to be hidden in case InventoryDemo was not provided"); } } else { var errorMessage = "Not enough currency amount to up the level"; Debug.Log(errorMessage); StoreDemoPopup.ShowWarning(new Error(errorMessage: errorMessage)); } }