コード例 #1
0
 public void Invoke()
 {
     for (int i = 0; i < numItemsToDrop; i++)
     {
         ItemTemplate chosenTemplate = itemClass.FetchItem();
         if (chosenTemplate != null)
         {
             Item item = itemFactory.Build(chosenTemplate);
             ground.DropItem(item, transform.position);
         }
     }
 }
コード例 #2
0
        public bool TryPickupItem()
        {
            if (!ground.IsItemOnGround)
            {
                return(false);
            }

            Item item = ground.PickUpItem();

            if (item.CanEquip)
            {
                Item oldItem = item.Equip(this);
                ground.DropItem(oldItem, transform.position);
                inventoryChanged.Invoke(EquippedItems);
            }
            else
            {
                // might be better to fold this into Equip so that all items can be 'equipped'
                IConsumable itemAsConsumable = (IConsumable)item;
                itemAsConsumable.Use(transform.parent.gameObject);
            }
            return(true);
        }