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 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 IsChannelMatch(DragDropTarget target, DragDropItem item) { if (target.universalMatching || item.universalMatching) { return(true); } return((target.matchingChannel & item.matchingChannel) != 0); }
internal bool AddInitialAttachedItem(DragDropItem item) { bool contain = attachedItems.Contains(item); if (attachedItems.Count >= maxItemCount && !contain) { return(false); } if (!contain) { attachedItems.Add(item); } return(true); }
private void OnEnable() { dragDropItem = target as DragDropItem; m_OnItemExit = serializedObject.FindProperty("m_OnItemExit"); m_OnItemEnter = serializedObject.FindProperty("m_OnItemEnter"); m_OnItemDetach = serializedObject.FindProperty("m_OnItemDetach"); m_OnItemAttach = serializedObject.FindProperty("m_OnItemAttach"); m_OnItemDrag = serializedObject.FindProperty("m_OnItemDrag"); matchingChannel = serializedObject.FindProperty("matchingChannel"); matchingTag = serializedObject.FindProperty("matchingTag"); m_OnItemSetFree = serializedObject.FindProperty("m_OnItemSetFree"); m_OnItemClick = serializedObject.FindProperty("m_OnItemClick"); m_parentWhenDragging = serializedObject.FindProperty("m_parentWhenDragging"); m_longPressDetach = serializedObject.FindProperty("m_longPressDetach"); displayEvents = !Application.isPlaying; }
public static int RemoveAllItems(DragDropTarget target, bool sendCallback = true) { var items = target.GetAllAttachedItems(); DragDropEventData eventData = new DragDropEventData(!sendCallback); eventData.Reset(); eventData.target = target; for (int count = items.Count, i = count - 1; i >= 0; --i) { DragDropItem item = items[i]; eventData.item = item; target.OnItemDetach(eventData); item.OnItemDetach(eventData); item.OnSetFree(eventData); } return(items.Count); }
internal bool CheckCanAttachItem(DragDropEventData eventData, out DragDropItem replacedItem) { replacedItem = null; if (attachedItems.Count >= maxItemCount) { if (replaceItem) { replacedItem = attachedItems[0]; return(true); } else { return(false); } } return(true); }
public static bool TryRemoveItem(DragDropItem item, DragDropTarget target) { if (item.attachedTarget == target && target.HasItemAttached(item)) { DragDropEventData eventData = new DragDropEventData(); eventData.Reset(); eventData.external = true; eventData.target = target; eventData.item = item; target.OnItemDetach(eventData); item.OnItemDetach(eventData); target.OnItemExit(eventData); item.OnItemExit(eventData); item.OnSetFree(eventData); return(true); } else { return(false); } }
public DragDropTarget FindDropTarget(PointerEventData pointerEventData, DragDropItem dragDropItem) { foreach (var ddt in managedTargets) { if (!ddt.isActiveAndEnabled) { continue; } if (!DragDropHelper.IsChannelMatch(ddt, dragDropItem)) { continue; } bool contain = RectTransformUtility.RectangleContainsScreenPoint(ddt.rectTransform, pointerEventData.position, pointerEventData.pressEventCamera); if (contain) { return(ddt); } } return(null); }
public static bool TryRemoveItem(DragDropItem item, DragDropTarget target, bool sendCallback = true) { if (item == null || target == null) { return(false); } if (item.attachedTarget == target && target.HasItemAttached(item)) { DragDropEventData eventData = new DragDropEventData(!sendCallback); eventData.Reset(); eventData.target = target; eventData.item = item; target.OnItemDetach(eventData); item.OnItemDetach(eventData); item.OnSetFree(eventData); return(true); } else { return(false); } }
public bool HasItemAttached(DragDropItem item) { return(attachedItems.Contains(item)); }
public static bool IsChannelMatch(DragDropTarget target, DragDropItem item) { return((target.matchingChannel & item.matchingChannel) != 0); }
public void UnRegister(DragDropItem item) { managedItems.Remove(item); }
public void Register(DragDropItem item) { managedItems.Add(item); }
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(); }
public static bool InitializePair(DragDropItem item, DragDropTarget target) { item.SetInitialTarget(target); return(true); }