public void PlaceItem(Draggable item) { var currentItemSlot = GetSlot(); var newItemSlot = item.GetSlot(); if (currentItemSlot.Same(newItemSlot) && currentItemSlot.Stackable && !currentItemSlot.MaxStack) { currentItemSlot.Add(newItemSlot); } else { currentItemSlot.transform.position = item.GetCell().transform.position; currentItemSlot.transform.SetParent(item.GetCell().transform); SetNewItem(item); } item.Dropped(); }
public void OnBeginDrag(PointerEventData eventData) { if (CookingHandler.Ongoing) { return; } if (!GameLibOfMethods.doingSomething && GameLibOfMethods.canInteract && !GameLibOfMethods.cantMove) { sourceCell = GetCell(); draggedItem = this; icon = new GameObject(); icon.name = "Icon"; Image myImage = GetComponentsInChildren <Image>()[1]; icon.transform.SetParent(canvas.transform); myImage.raycastTarget = false; // Disable icon's raycast for correct drop handling Image iconImage = icon.AddComponent <Image>(); iconImage.raycastTarget = false; iconImage.sprite = myImage.sprite; RectTransform iconRect = icon.GetComponent <RectTransform>(); // Set icon's dimensions RectTransform myRect = GetComponent <RectTransform>(); iconRect.pivot = new Vector2(0.5f, 0.5f); iconRect.anchorMin = new Vector2(0.5f, 0.5f); iconRect.anchorMax = new Vector2(0.5f, 0.5f); iconRect.sizeDelta = new Vector2(myRect.rect.width, myRect.rect.height); iconImage.preserveAspect = true; icon.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); GetSlot()?.SetButtonEnable(false); Inventory.SFX(Inventory.Sound.StartDrag); } else { GameLibOfMethods.CreateFloatingText("You are busy, can't rearrange inventory now!", 2); } }
private void RemoveCurrentItemWith(Draggable item) { GetSlot().Delete(); SetNewItem(item); }