public void OnEndDrag(PointerEventData eventData) { if (!draggable) { return; } DraggedItem = null; var t = transform; t.SetParent(_parent); t.localPosition = Vector3.zero; _image.raycastTarget = true; _mesh.raycastTarget = true; if (!DraggedSlot) { return; } var currentItem = Item; var changingItem = DraggedSlot.Inventory.Get(DraggedSlot.InventorySlot); if (currentItem != null && changingItem != null) { // Merge two items var mergeable = ( (currentItem.Meta == null && changingItem.Meta == null) && (currentItem.ItemId == changingItem.ItemId) ); if (mergeable) { var addingCount = Math.Min(currentItem.MaxStack, currentItem.Count + changingItem.Count) - currentItem.Count; currentItem.Count += addingCount; changingItem.Count -= addingCount; if (changingItem.Count == 0) { changingItem = null; } } } Slot.Inventory.Set(Slot.InventorySlot, changingItem); DraggedSlot.Inventory.Set(DraggedSlot.InventorySlot, currentItem); }
public void OnBeginDrag(PointerEventData eventData) { if (!draggable) { return; } DraggedItem = this; _parent = transform.parent; _image.raycastTarget = false; _mesh.raycastTarget = false; transform.SetParent(_canvas); }