コード例 #1
0
    //Drops the item
    public void OnDrop(PointerEventData eventData)
    {
        RectTransform invPanel = transform as RectTransform;

        //Checks if the mouse pointer is within the inventory panel or not. If not then it will indicate that the item has been dropped
        if (!RectTransformUtility.RectangleContainsScreenPoint(invPanel, Input.mousePosition))
        {
            //Grabs the item along with the drag
            TheInventoryItem item = eventData.pointerDrag.gameObject.GetComponent <ItemDrag>().Item;
            if (item != null)
            {
                //Drops the item
                //Debug.Log("It has been dropped " + item);
                inventory.RemoveItem(item);
                item.OnDrop();
            }
        }
    }
コード例 #2
0
ファイル: Inventory.cs プロジェクト: JacobLCarter/StranDEAD
    //Removes the item from the inventory list then drops the item. Turns on colliders to make it the same as it was before. Activating the object in the view
    public void RemoveItem(TheInventoryItem item)
    {
        //Debug.Log("This is the remove item");
        if (myItems.Contains(item))
        {
            myItems.Remove(item);

            item.OnDrop();

            //Debug.Log("This is the ondrop");
            Collider collider = (item as MonoBehaviour).GetComponent <Collider>();
            if (collider != null)
            {
                collider.enabled = true;
            }

            ItemRemove?.Invoke(this, new InventoryEventArgs(item));
        }
    }