public bool AddInventoryObject(InventoryObject inventoryObject, bool isSpecial = false) { InventoryUISlot nextFreeSlot; // get next free slot if (isSpecial && slotSpecial.IsEmpty()) { nextFreeSlot = slotSpecial; } else { nextFreeSlot = GetNextFreeSlot(inventoryObject.GetCurrentPos()); } if (nextFreeSlot != null) { // create new inventory ui object from template GameObject templateClone = Instantiate(inventoryUIObjectTemplate.gameObject, Vector3.zero, Quaternion.identity); templateClone.SetActive(true); templateClone.name = inventoryObject.GetTitle(); // link it with the slot InventoryUIObject newInventoryUIObject = templateClone.GetComponent <InventoryUIObject>(); newInventoryUIObject.SetInventoryObject(inventoryObject); newInventoryUIObject.SetCurrentSlot(nextFreeSlot); newInventoryUIObject.GetTransform().localScale = inventoryUIObjectTemplate.GetTransform().localScale; nextFreeSlot.Init(this); return(true); } return(false); }
public bool RemoveInventoryObject(InventoryObject inventoryObject) { bool success = false; if (slotSpecial.IsEmpty() == false && slotSpecial.GetInventoryUIObject().GetInventoryObject() == inventoryObject) { Destroy(slotSpecial.GetInventoryUIObject().gameObject); slotSpecial.SetInventoryUIObject(null); success = true; } else { foreach (InventoryUISlot slot in slots) { if (slot.IsEmpty()) { continue; } if (slot.GetInventoryUIObject().GetInventoryObject() == inventoryObject) { Destroy(slot.GetInventoryUIObject().gameObject); slot.SetInventoryUIObject(null); success = true; } } } return(success); }
public bool RemoveInventoryObject(InventoryObject inventoryObject) { bool success = false; if (specialInventoryObject == inventoryObject) { specialInventoryObject = null; success = true; } else { if (inventoryObjects.Contains(inventoryObject)) { inventoryObjects.Remove(inventoryObject); inventoryObject.OnRemoveFromInventory(this); success = true; } else { if (logWarnings) { Debug.LogWarning(name + ":" + inventoryObject.name + " is not set in this inventory!"); } success = false; } } if (success && onInventoryUpdate != null) { onInventoryUpdate(InventoryUpdateType.Remove, inventoryObject); } return(success); }
public bool AddInventoryObject(InventoryObject inventoryObject, bool isSpecial = false) { bool success = false; // handle special inventory object if (isSpecial) { if (specialInventoryObject == null) { specialInventoryObject = inventoryObject; success = true; } else { if (logWarnings) { Debug.LogWarning(name + ": specialInventoryObject is already set! Remove it first!"); } } } else { // handle normal inventory objects if (inventoryObjects.Count < inventorySlots) { if (inventoryObjects.Contains(inventoryObject) == false && inventoryObject != specialInventoryObject) { inventoryObjects.Add(inventoryObject); inventoryObject.OnAddToInventory(this); success = true; } else { if (logWarnings) { Debug.LogWarning(name + ":" + inventoryObject.name + " is already in inventory!"); } } } else { if (logWarnings) { Debug.LogWarning(name + ": inventory is full!"); } } } if (success && onInventoryUpdate != null) { onInventoryUpdate(InventoryUpdateType.Add, inventoryObject); } return(success); }
private void OnInventoryUpdate(Inventory.InventoryUpdateType type, InventoryObject inventoryObject) { if (type == Inventory.InventoryUpdateType.Add) { AddInventoryObject(inventoryObject); } if (type == Inventory.InventoryUpdateType.Remove) { RemoveInventoryObject(inventoryObject); } }
public bool IsInInventory(InventoryObject inventoryObject) { if (inventoryObject == specialInventoryObject) { return(true); } foreach (InventoryObject iObject in inventoryObjects) { if (iObject == inventoryObject) { return(true); } } return(false); }
public List <InventoryObject> GetInventoryObjects() { if (initDone == false) { inventoryObjects = new List <InventoryObject>(); foreach (InventoryObject iObj in startInventoryObjects) { if (iObj == null) { continue; } inventoryObjects.Add(iObj); } specialInventoryObject = startSpecialInventoryObject; initDone = true; } return(inventoryObjects); }
public void SetInventoryObject(InventoryObject inventoryObject) { this.inventoryObject = inventoryObject; }
public void MoveNormalInventoryObjectToSpecial(InventoryObject inventoryObject) { inventoryObjects.Remove(inventoryObject); specialInventoryObject = inventoryObject; }
public void MoveSpecialInventoryObjectToNormal(InventoryObject inventoryObject) { specialInventoryObject = null; inventoryObjects.Add(inventoryObject); }