void GrantStartItemsAndUpdateUI() { if (_itemInstanceDatas == null) { _itemInstanceDatas = new Dictionary <int, InventoryInstanceData>(); } InventoryInstanceData instanceData; ChapterUIManager chapterUIManager = ChapterUIManager.instance; foreach (InventoryItemData itemData in _itemDatas) { if (_itemInstanceDatas.TryGetValue(itemData.itemId, out instanceData)) { if (!_grantedStartItems && itemData.startCount > 0) { instanceData.count += itemData.startCount; } chapterUIManager.UpdateInventoryItemCount(itemData, instanceData.count); } else { if (!_grantedStartItems && itemData.startCount > 0) { instanceData = new InventoryInstanceData(itemData.itemId, itemData.startCount, 0); _itemInstanceDatas.Add(itemData.itemId, instanceData); chapterUIManager.UpdateInventoryItemCount(itemData, instanceData.count); } } } _grantedStartItems = true; }
public void RemoveItem(int pId, int pCount = 1) { if (pCount < 1) { Debug.LogError("Can't remove less than 1 item"); return; } InventoryItemData itemData = GetItemData(pId); if (itemData == null) { Debug.LogError("No data found for item id " + pId); return; } if (_itemInstanceDatas == null) { return; } else { InventoryInstanceData instanceData = null; if (_itemInstanceDatas.TryGetValue(pId, out instanceData)) { ChapterUIManager chapterUIManager = ChapterUIManager.instance; instanceData.count -= pCount; chapterUIManager.UpdateInventoryItemCount(itemData, instanceData.count); if (instanceData.count <= 0) { chapterUIManager.ClearSelectedItem(); } //we dont delete the item if count is 0 because the presence of the item //indicates that the animation has already played } } }
public void AddItem(int pId, int pCount = 1) { if (pCount < 1) { Debug.LogError("Can't add less than 1 item"); return; } InventoryItemData itemData = GetItemData(pId); if (itemData == null) { Debug.LogError("No data found for item id " + pId); return; } ChapterUIManager chapterUIManager = ChapterUIManager.instance; if (_itemInstanceDatas == null) { _itemInstanceDatas = new Dictionary <int, InventoryInstanceData> (); _itemInstanceDatas.Add(pId, new InventoryInstanceData(pId, pCount, 0)); chapterUIManager.PlayAddInventoryItemAnimation(itemData, pCount); } else { InventoryInstanceData instanceData = null; if (_itemInstanceDatas.TryGetValue(pId, out instanceData)) { instanceData.count += pCount; chapterUIManager.UpdateInventoryItemCount(itemData, instanceData.count, true); } else { _itemInstanceDatas.Add(pId, new InventoryInstanceData(pId, pCount, 0)); chapterUIManager.PlayAddInventoryItemAnimation(itemData, pCount); } } }