예제 #1
0
 public void DropItem(vItem item, int amount)
 {
     item.amount -= amount;
     if (item.dropObject != null)
     {
         var             dropObject = Instantiate(item.dropObject, transform.position, transform.rotation) as GameObject;
         vItemCollection collection = dropObject.GetComponent <vItemCollection>();
         if (collection != null)
         {
             collection.items.Clear();
             var itemReference = new ItemReference(item.id);
             itemReference.amount     = amount;
             itemReference.attributes = new List <vItemAttribute>(item.attributes);
             collection.items.Add(itemReference);
         }
     }
     onDropItem.Invoke(item, amount);
     if (item.amount <= 0 && items.Contains(item))
     {
         if (item.type != vItemType.Consumable)
         {
             var equipPoint = equipPoints.Find(ep => ep.equipmentReference.item == item || ep.area != null && ep.area.ValidSlots.Find(slot => slot.item == item));
             if (equipPoint != null)
             {
                 if (equipPoint.area)
                 {
                     equipPoint.area.RemoveItem(item);
                 }
             }
         }
         items.Remove(item);
         Destroy(item);
     }
 }
예제 #2
0
 void OnEnable()
 {
     m_Logo            = (Texture2D)Resources.Load("icon_v2", typeof(Texture2D));
     manager           = (vItemCollection)target;
     skin              = Resources.Load("skin") as GUISkin;
     itemReferenceList = serializedObject.FindProperty("items");
 }
예제 #3
0
        public void DropAllItens(GameObject target = null)
        {
            if (target != null && target != gameObject)
            {
                return;
            }
            List <ItemReference> itemReferences = new List <ItemReference>();

            for (int i = 0; i < items.Count; i++)
            {
                if (itemReferences.Find(_item => _item.id == items[i].id) == null)
                {
                    var           sameItens     = items.FindAll(_item => _item.id == items[i].id);
                    ItemReference itemReference = new ItemReference(items[i].id);
                    for (int a = 0; a < sameItens.Count; a++)
                    {
                        if (sameItens[a].type != vItemType.Consumable)
                        {
                            var equipPoint = equipPoints.Find(ep => ep.equipmentReference.item == sameItens[a]);
                            if (equipPoint != null && equipPoint.equipmentReference.equipedObject != null)
                            {
                                UnequipItem(equipPoint.area, equipPoint.equipmentReference.item);
                            }
                        }

                        itemReference.amount += sameItens[a].amount;
                        Destroy(sameItens[a]);
                    }
                    itemReferences.Add(itemReference);
                    if (equipPoints != null)
                    {
                        var equipPoint = equipPoints.Find(e => e.equipmentReference != null && e.equipmentReference.item != null && e.equipmentReference.item.id == itemReference.id && e.equipmentReference.equipedObject != null);
                        if (equipPoint != null)
                        {
                            Destroy(equipPoint.equipmentReference.equipedObject);
                            equipPoint.equipmentReference = null;
                        }
                    }
                    if (items[i].dropObject)
                    {
                        var             dropObject = Instantiate(items[i].dropObject, transform.position, transform.rotation) as GameObject;
                        vItemCollection collection = dropObject.GetComponent <vItemCollection>();
                        if (collection != null)
                        {
                            collection.items.Clear();
                            collection.items.Add(itemReference);
                        }
                    }
                }
            }
            items.Clear();
        }