internal void UseItem(MasterInventoryItemBase item) { if (ItemUsed != null) { ItemUsed(this, new MasterInventoryEventArgs(item)); } }
public void DoDropItem() { //Remove Rigibody Destroy((mCurrentItem as MonoBehaviour).GetComponent <Rigidbody>()); mCurrentItem = null; }
//When clicked all the item's Use function and the Inventory's UseItem function public void OnItemClicked() { MasterInventoryItemBase item = AttachedItem; if (item != null) { theInventory.UseItem(item); item.Use(); } }
//ItemRemoved Event private void Inventory_ItemRemoved(object sender, MasterInventoryEventArgs e) { MasterInventoryItemBase item = e.Item; //Set the set item back to active when its dropped GameObject goItem = (item as MonoBehaviour).gameObject; goItem.SetActive(true); goItem.transform.parent = null; }
public bool FindItem(MasterInventoryItemBase item) { foreach (MasterInventorySlot slot in theSlots) { if (slot.IsStackable(item)) { return(true); } } return(false); }
private MasterInventorySlot FindStackableSlot(MasterInventoryItemBase item) { foreach (MasterInventorySlot slot in theSlots) { //Edit max items in slots here if (slot.IsStackable(item) && slot.Count < 5) { return(slot); } } return(null); }
public void RemoveItem(MasterInventoryItemBase item) { foreach (MasterInventorySlot slot in theSlots) { if (slot.Remove(item)) { if (ItemRemoved != null) { ItemRemoved(this, new MasterInventoryEventArgs(item)); } break; } } }
//Check to see if the slot is empty, if not check ID of first item in that slot public bool IsStackable(MasterInventoryItemBase item) { if (IsEmpty) { return(false); } MasterInventoryItemBase theFirst = theItemStack.Peek(); if (theFirst.Name == item.Name) { return(true); } return(false); }
//What happens when dropping the item public void OnDrop(PointerEventData eventData) { RectTransform invPanel = transform as RectTransform; if (!RectTransformUtility.RectangleContainsScreenPoint(invPanel, Input.mousePosition)) { MasterInventoryItemBase item = eventData.pointerDrag.gameObject.GetComponent <MasterItemDragHandler>().Item; //Call the Inventory's RemoveItem and the Item's Drop function if (item != null) { theInventory.RemoveItem(item); item.Drop(); } } }
private void Inventory_ItemUsed(object sender, MasterInventoryEventArgs e) { if (!e.Item.IsConsumable) { //If the player carries an item, un-use it (remove from player's hand) if (mCurrentItem != null) { SetItemActive(mCurrentItem, false); } MasterInventoryItemBase item = e.Item; //Use item (put it to the hand of the player) SetItemActive(item, true); mCurrentItem = e.Item; } }
public void AddItem(MasterInventoryItemBase item) { MasterInventorySlot theFreeSlot = FindStackableSlot(item); if (theFreeSlot == null) { theFreeSlot = FindNextEmptySlot(); } if (theFreeSlot != null) { theFreeSlot.AddItem(item); if (ItemAdded != null) { ItemAdded(this, new MasterInventoryEventArgs(item)); } } }
//Add item to the Slot public void AddItem(MasterInventoryItemBase item) { item.Slot = this; theItemStack.Push(item); }
public MasterInventoryEventArgs(MasterInventoryItemBase item) { Item = item; }
private void SetItemActive(MasterInventoryItemBase item, bool active) { GameObject currentItem = (item as MonoBehaviour).gameObject; currentItem.SetActive(active); }