public static InventoryUIDragLookup BeginDrag(InventoryUIItemWrapper toDrag, uint startIndex, ItemCollectionBase collection, PointerEventData eventData) { if (draggingItem != null) { Debug.LogWarning("Item still attached to cursor, can only drag one item at a time", draggingItem.gameObject); return(null); // Can only drag one item at a time } if (eventData.button != PointerEventData.InputButton.Left) { return(null); } draggingItem = toDrag; //draggingButtonCollection = collection; // Canvas group allows object to ignore raycasts. CanvasGroup group = draggingItem.gameObject.GetComponent <CanvasGroup>(); if (group == null) { group = draggingItem.gameObject.AddComponent <CanvasGroup>(); } group.blocksRaycasts = false; // Allows rays to go through so we can hover over the empty slots. group.interactable = false; var lookup = new InventoryUIDragLookup(); lookup.startIndex = (int)startIndex; lookup.startItemCollection = collection; return(lookup); }
public static InventoryUIDragLookup EndDrag(InventoryUIItemWrapper toDrag, uint startSlot, ItemCollectionBase handler, PointerEventData eventData) { if (eventData.button == PointerEventData.InputButton.Left) { var lookup = new InventoryUIDragLookup(); lookup.startIndex = (int)draggingItem.index; lookup.startItemCollection = draggingItem.itemCollection; if (hoveringItem != null) { lookup.endIndex = (int)hoveringItem.index; lookup.endItemCollection = hoveringItem.itemCollection; } Object.Destroy(draggingItem.gameObject); // No longer need it draggingItem = null; //draggingButtonCollection = null; return(lookup); } return(null); }
public static InventoryUIDragLookup BeginDrag(InventoryUIItemWrapper toDrag, uint startIndex, ItemCollectionBase collection, PointerEventData eventData) { if (draggingItem != null) { Debug.LogWarning("Item still attached to cursor, can only drag one item at a time", draggingItem.gameObject); return null; // Can only drag one item at a time } if (eventData.button != PointerEventData.InputButton.Left) return null; draggingItem = toDrag; //draggingButtonCollection = collection; // Canvas group allows object to ignore raycasts. CanvasGroup group = draggingItem.gameObject.GetComponent<CanvasGroup>(); if(group == null) group = draggingItem.gameObject.AddComponent<CanvasGroup>(); group.blocksRaycasts = false; // Allows rays to go through so we can hover over the empty slots. group.interactable = false; var lookup = new InventoryUIDragLookup(); lookup.startIndex = (int)startIndex; lookup.startItemCollection = collection; return lookup; }
public static InventoryUIDragLookup EndDrag(InventoryUIItemWrapper toDrag, uint startSlot, ItemCollectionBase handler, PointerEventData eventData) { if(eventData.button == PointerEventData.InputButton.Left) { var lookup = new InventoryUIDragLookup(); lookup.startIndex = (int)draggingItem.index; lookup.startItemCollection = draggingItem.itemCollection; if (hoveringItem != null) { lookup.endIndex = (int)hoveringItem.index; lookup.endItemCollection = hoveringItem.itemCollection; } Object.Destroy(draggingItem.gameObject); // No longer need it draggingItem = null; //draggingButtonCollection = null; return lookup; } return null; }