public void OnBeginDrag(PointerEventData eventData) { isDragCanceled = false; if (!alreadyUsed) { //allow dragging from item slot or from level if in pickup range bool isInRange = false; if (isAttachedToItemSlot || (isInRange = IsInPickupRange())) { //allow to detect drop (fe. on item slots), this wont catch UIraycasts when dragging canvasGroup.blocksRaycasts = false; SetHigherSortingLayer(); ToggleItemSlotHighlights(true); isDragged = true; } if (!isAttachedToItemSlot && !isInRange) { HelperText.DisplayText("Out of range", 1f); } } }
public bool PlaceOnDropTarget(ItemDropTarget dropTarget) { if (dropTarget == null) { Debug.LogError($"Cannot find {nameof(dropTarget)} component"); } //is drop target valid?can we drop this item here?(f.e this key's uid matches the keypillar's allowed uids) if (dropTarget.IsValidForItem(this.Uid)) { //empty item slot of current item var slot = GetAttachedItemSlot(); if (slot == null) { //slot might be null when loading already placed object SlotUid = null; } else { //placing item in dropTarget so need to empty the inventory slot it occupies slot.SetSlotState(null); SlotUid = null; } //restore parent to worldPointCanvas and then perform placement positioning RestoreInitialValues(); dropTarget.PlaceItem(this); DropTargetId = dropTarget.Uid; alreadyUsed = true; return(true); } else { HelperText.DisplayText(StringResources.HelpMessages.Item_InvalidPlacement, Constants.HelpMessage_ShortDuration); Debug.LogWarning(string.Format(StringResources.System_Messages.DropTarget_ValidationFailedFormat, dropTarget.name, this.name, this.Uid)); return(false); } }