コード例 #1
0
ファイル: ItemDropHandler.cs プロジェクト: Jeunna/Univ
    public void OnDrop(PointerEventData eventData)
    {
        RectTransform invPanel = transform as RectTransform;

        if (collider.OverlapPoint(Input.mousePosition))
        {
            _Inventory.GetComponent <CanvasGroup>().blocksRaycasts = false;
            Debug.Log(_Inventory.GetComponent <CanvasGroup>().blocksRaycasts);

            InventoryItemBase item    = eventData.pointerDrag.gameObject.GetComponent <ItemDragHandler>().Item;
            GameObject        slotPos = eventData.pointerDrag.gameObject.GetComponent <ItemDragHandler>().mySlot;
            if (item != null)
            {
                item.OnDropScreen(_Inventory, slotPos);
                _Inventory.GetComponent <CanvasGroup>().blocksRaycasts = true;
            }
        }
        else if (!RectTransformUtility.RectangleContainsScreenPoint(invPanel, Input.mousePosition))
        {
            InventoryItemBase item = eventData.pointerDrag.gameObject.GetComponent <ItemDragHandler>().Item;
            if (item != null)
            {
                _Inventory.RemoveItem(item);
                item.OnDrop();
            }
        }
    }
コード例 #2
0
    public void OnDrop(PointerEventData eventData)
    {
        RectTransform invPanel = transform as RectTransform;

        if (!RectTransformUtility.RectangleContainsScreenPoint(invPanel,
                                                               Input.mousePosition))
        {
            InventoryItemBase item = eventData.pointerDrag.gameObject.GetComponent <ItemDragHandler>().Item;
            if (item != null)
            {
                _Inventory.RemoveItem(item);
                item.OnDrop();
            }
        }
    }
コード例 #3
0
    public void RemoveItem(InventoryItemBase item)
    {
        if (nSlots.Contains(item))
        {
            nSlots.Remove(item);

            item.OnDrop();

            Collider collider = (item as MonoBehaviour).GetComponent <Collider>();
            if (collider != null)
            {
                collider.enabled = true;
            }

            if (ItemRemoved != null)
            {
                ItemRemoved(this, new InventoryEventArgs(item));
            }
        }
    }