コード例 #1
0
        /// <summary>
        /// Simple example on how to add one or more items into the inventory using code
        /// You can also auto equip the item if it's a MeleeWeapon Type
        /// </summary>
        /// <param name="other"></param>
        void OnTriggerEnter(Collider other)
        {
            if (other.gameObject.CompareTag("Player"))
            {
                var itemManager = other.gameObject.GetComponent <vItemManager>();
                if (itemManager)
                {
                    var reference = new ItemReference(id);
                    reference.amount         = amount;
                    reference.addToEquipArea = addToEquipArea;
                    reference.autoEquip      = autoEquip;
                    itemManager.AddItem(reference);
                }

                if (destroyAfter)
                {
                    Destroy(gameObject);
                }
            }
        }
コード例 #2
0
        public virtual 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);
                            }
                        }
                        else
                        {
                            var equipArea = System.Array.Find(inventory.equipAreas, e => e.ValidSlots.Exists(s => s.item != null && s.item.id.Equals(sameItens[a].id)));

                            if (equipArea != null)
                            {
                                equipArea.RemoveItem(sameItens[a]);
                            }
                        }

                        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();
        }
コード例 #3
0
 public virtual void CollectItem(ItemReference itemRef, bool immediate = false)
 {
     AddItem(itemRef, immediate);
 }