Exemplo n.º 1
0
        public override void OnItemDrop(ItemDisplay display)
        {
            Item       item         = display.Item;
            Vector2Int size         = item.Size;
            Vector3    dragPosition = display.transform.position;

            // Get item center position
            var     rect       = display.GetComponent <RectTransform>().rect;
            Vector2 rectCenter = new Vector2(rect.width / 2, rect.height / 2);
            var     position   = GetSlotPositionExact(new Vector2(dragPosition.x + rectCenter.x, dragPosition.y - rectCenter.y));

            // Offset slot by item dimensions
            var slot = new Vector2Int(Mathf.RoundToInt(position.x - size.x / 2f), Mathf.RoundToInt(position.y - size.y / 2f));

            if (!AttachedContainer.Container.IsAreaFreeExcluding(new RectInt(slot, size), item))
            {
                return;
            }

            display.DropAccepted = true;
            CreateItemDisplay(display.Item, slot);
            Inventory.ClientTransferItem(item, slot, AttachedContainer);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Called when an item is being dropped onto this display
 /// </summary>
 /// <param name="display"></param>
 public abstract void OnItemDrop(ItemDisplay display);