public static bool TryAddItem(DragDropItem item, DragDropTarget target, bool sendCallback = true) { if (item == null || target == null) { return(false); } if (!(item.isActiveAndEnabled && target.isActiveAndEnabled)) { return(false); } if (item.attachedTarget != null) { return(false); } if (!IsChannelMatch(target, item)) { return(false); } DragDropEventData eventData = new DragDropEventData(!sendCallback); eventData.Reset(); eventData.target = target; eventData.item = item; target.OnItemAttach(eventData); item.OnItemAttach(eventData); return(true); }
public static bool TryAddItem(DragDropItem item, DragDropTarget target) { if (item.attachedTarget != null) { return(false); } if (!IsChannelMatch(target, item)) { return(false); } if (target.currentItemCount >= target.maxItemCount) { return(false); } DragDropEventData eventData = new DragDropEventData(); eventData.Reset(); eventData.external = true; eventData.target = target; eventData.item = item; target.OnItemEnter(eventData); item.OnItemEnter(eventData); target.OnItemAttach(eventData); item.OnItemAttach(eventData); return(true); }
public void OnPointerUp(PointerEventData eventData) { if (DragDropEventData.current.eligibleForClick) { OnClick(DragDropEventData.current); } if (!HandlingDragDropEvent()) { DragDropEventData.current.Reset(); return; } if (DragDropEventData.current.valid) { DragDropItem replacedItem = null; if (DragDropEventData.current.target.CheckCanAttachItem(DragDropEventData.current, out replacedItem)) { if (replacedItem) { // 旧item 离开 DragDropEventData.current.isReplaced = true; DragDropEventData.current.item = replacedItem; DragDropEventData.current.target.OnItemDetach(DragDropEventData.current); replacedItem.OnItemDetach(DragDropEventData.current); // 新item 附着 DragDropEventData.current.isReplaced = false; DragDropEventData.current.item = this; DragDropEventData.current.target.OnItemAttach(DragDropEventData.current); OnItemAttach(DragDropEventData.current); // 旧item 附着到新item原来的target 完成交换 DragDropEventData.current.isReplaced = true; DragDropEventData.current.item = replacedItem; DragDropEventData.current.target = lastTarget; if (DragDropEventData.current.valid) { lastTarget.OnItemAttach(DragDropEventData.current); replacedItem.OnItemAttach(DragDropEventData.current); } else { replacedItem.attachedTarget = null; replacedItem.OnSetFree(DragDropEventData.current); } } else { DragDropEventData.current.target.OnItemAttach(DragDropEventData.current); OnItemAttach(DragDropEventData.current); } } else { DragDropEventData.current.target.OnItemExit(DragDropEventData.current); OnItemExit(DragDropEventData.current); } } else { OnSetFree(DragDropEventData.current); } DragDropEventData.current.Reset(); }