public void OnEndDrag(PointerEventData eventData)
        {
            var invrect = Inventory.GetComponent <RectTransform>();

            if (!InCraft)
            {
                List <RaycastHit2D> hit = Physics2D.GetRayIntersectionAll(Camera.main.ScreenPointToRay(Input.mousePosition)).ToList();
                if (hit.Any(h => h.collider == Crafter.GetComponentInParent <Collider2D>()))
                {
                    if (Crafter.AddItem(Item))
                    {
                        OnDrop?.Invoke();
                    }
                    else
                    {
                        // display msg
                    }
                }
            }
            else if (InCraft && RectTransformUtility.RectangleContainsScreenPoint(invrect, Input.mousePosition))
            {
                if (Inventory.AddItem(Item))
                {
                    OnDrop?.Invoke();
                }
                else
                {
                    // display msg
                }
            }
            _image.transform.localPosition = Vector3.zero;
        }
示例#2
0
 void Start()
 {
     inventoryView = GetComponentInParent <InventoryView>();
     if (inventoryView == null)
     {
         inventoryView = GameObject.Find("Inventory").GetComponent <InventoryView>();
     }
     tooltip = inventoryView.GetComponent <Tooltip>();
 }