public virtual 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)) { var equipArea = System.Array.Find(inventory.equipAreas, e => e.ValidSlots.Exists(s => s.item != null && s.item.id.Equals(item.id))); if (equipArea != null) { equipArea.RemoveItem(item); } items.Remove(item); Destroy(item); } }
protected override void OnEnable() { base.OnEnable(); manager = (vItemCollection)target; skin = Resources.Load("vSkin") as GUISkin; itemReferenceList = serializedObject.FindProperty("items"); }
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); } }
void OnEnable() { m_Logo = (Texture2D)Resources.Load("icon_v2", typeof(Texture2D)); manager = (vItemCollection)target; skin = Resources.Load("skin") as GUISkin; itemReferenceList = serializedObject.FindProperty("items"); }
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(); }