예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        private void OnInventoryUpdate(Inventory.InventoryUpdateType type, InventoryObject inventoryObject)
        {
            if (type == Inventory.InventoryUpdateType.Add)
            {
                AddInventoryObject(inventoryObject);
            }

            if (type == Inventory.InventoryUpdateType.Remove)
            {
                RemoveInventoryObject(inventoryObject);
            }
        }
예제 #6
0
        public bool IsInInventory(InventoryObject inventoryObject)
        {
            if (inventoryObject == specialInventoryObject)
            {
                return(true);
            }

            foreach (InventoryObject iObject in inventoryObjects)
            {
                if (iObject == inventoryObject)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #7
0
        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);
        }
예제 #8
0
 public void SetInventoryObject(InventoryObject inventoryObject)
 {
     this.inventoryObject = inventoryObject;
 }
예제 #9
0
 public void MoveNormalInventoryObjectToSpecial(InventoryObject inventoryObject)
 {
     inventoryObjects.Remove(inventoryObject);
     specialInventoryObject = inventoryObject;
 }
예제 #10
0
 public void MoveSpecialInventoryObjectToNormal(InventoryObject inventoryObject)
 {
     specialInventoryObject = null;
     inventoryObjects.Add(inventoryObject);
 }