コード例 #1
0
        /// <summary>
        /// Once Game Foundation completes initialization, we enable buttons, setup callbacks, update GUI, etc.
        /// </summary>
        private void OnGameFoundationInitialized()
        {
            // Create a single, stackable Health Potion item.
            var healthPotionDefinition = GameFoundationSdk.catalog.Find <InventoryItemDefinition>(k_HealthPotionKey);

            m_HealthPotion = GameFoundationSdk.inventory.CreateItem(healthPotionDefinition) as StackableInventoryItem;

            // Enable add button.  Others will be dynamically enabled/disabled based on quantity.
            increaseQuantityButton.interactable = true;

            // Show list of inventory items and update the button interactability.
            RefreshUI();

            // Ensure that the stackable-inventory-item-changed callback is connected
            SubscribeToGameFoundationEvents();
        }
コード例 #2
0
 /**
  *  When an item is dropped on this slot, swap
  *  it with the one currently in this place
  *
  **/
 public override DraggableItem ItemDropped(DraggableItem item)
 {
     if (item.GetComponent <ActionItem>() != null)
     {
         //	if this is a stackable item, try and stack it
         //	this works but it's _really_ ugly
         //	TODO: maybe there should be a helper that will attempt
         //	this as opposed to implementing it on anything that
         //	requires stackable items.
         StackableInventoryItem stackableSelf = this.item.GetComponent <StackableInventoryItem>();
         StackableInventoryItem stackableItem = item.GetComponent <StackableInventoryItem>();
         if (stackableSelf != null && stackableItem != null)
         {
             //	if we're dragging a single item and dropping it on a max stack
             //	that means we should swap these
             //	TODO: check stack types?
             if (stackableItem.GetCount() == 1 && stackableSelf.GetCount() == stackableSelf.maxCount)
             {
                 items[position] = item.GetComponent <ActionItem>();
                 return(this.item.GetComponent <DraggableItem>());
             }
             else
             {
                 StackableInventoryItem remainder = stackableSelf.AddStackableInventoryItems(stackableItem);
                 if (remainder != null)
                 {
                     return(remainder);
                 }
             }
         }
         else
         {
             items[position] = item.GetComponent <ActionItem>();
             return(this.item.GetComponent <DraggableItem>());
         }
     }
     return(null);
 }
コード例 #3
0
        /**
         *  An item was dropped on this slot. Swap it with the
         *  item currently in that position and return it or
         *  stack it if it's a stackable item
         *
         **/
        public override DraggableItem ItemDropped(DraggableItem item)
        {
            if (item.GetComponent <InventoryItem>() != null)
            {
                StackableInventoryItem stackableItem = item.GetComponent <StackableInventoryItem>();
                StackableInventoryItem stackableSelf = this.item.GetComponent <StackableInventoryItem>();

                //	if this is a stackable item, stack it
                if (stackableItem != null && stackableSelf != null)
                {
                    if (!stackableSelf.IsMaxed())
                    {
                        return(stackableSelf.AddStackableInventoryItems(stackableItem));
                    }
                }

                //	otherwise, swap it
                GameObject tmpInventoryItem = inventory[inventoryPosition.x, inventoryPosition.y];
                inventory[inventoryPosition.x, inventoryPosition.y] = item.gameObject;
                return(tmpInventoryItem.GetComponent <InventoryItem>());
            }
            return(null);
        }