/// <summary> /// When this slot gets an item dropped on it, /// it verifies that it is of the same ItemType. /// If so, it adds the item to the slot.If not, /// it uses the eventData as the drop was successful. /// </summary> /// <param name="eventData">The `PointerEventData` of the event</param> public override void OnDrop(PointerEventData eventData) { DraggableItemType itemType = Draggable.DraggedItem.GetComponent<DraggableItemType>(); if (itemType == null) { eventData.Use(); return; } if (itemType.ItemType == Type) { base.OnDrop(eventData); } else { eventData.Use(); } }
public override void OnBeginDrag(PointerEventData eventData) { if (!interactable) { return; } //Debug.Log("OnBeginDrag (isFocused: {0}, isUsed: {1}, delta: {2})".Fmt(isFocused, eventData.used, eventData.delta)); // Pass event to parent if it is a vertical drag if (Mathf.Abs(eventData.delta.y) > Mathf.Abs(eventData.delta.x)) { //Debug.Log("Passing To Parent"); var parent = transform.parent; if (parent != null) { eventData.pointerDrag = ExecuteEvents.GetEventHandler<IBeginDragHandler>(parent.gameObject); if (eventData.pointerDrag != null) { ExecuteEvents.Execute(eventData.pointerDrag, eventData, ExecuteEvents.beginDragHandler); } } return; } eventData.Use(); _dragStartAmount = double.Parse(text); _currentValue = _dragStartAmount; var minStep = 1f; // Use a larger minimum step for integer numbers, since there are no fractional values if (contentType == ContentType.IntegerNumber) { minStep *= 10; } _dragStep = Math.Max(minStep, _dragStartAmount*0.05f); if (isFocused) { DeactivateInputField(); } }
/// <summary> /// Raises the end drag event. /// </summary> /// <param name="eventData">Event data.</param> public virtual void OnEndDrag(PointerEventData eventData) { // Check if a drag was initialized at all if (!this.m_DragHasBegan) return; // Reset the drag begin bool this.m_DragHasBegan = false; // Destroy the dragged icon object if (this.m_CurrentDraggedObject != null) { Destroy(this.m_CurrentDraggedObject); } // Reset the variables this.m_CurrentDraggedObject = null; this.m_CurrentDraggingPlane = null; // Use the event eventData.Use(); // Check if we are returning the icon to the same slot // By checking if the slot is highlighted if (this.IsHighlighted(eventData)) return; // Check if no drop was preformed if (!this.m_DropPreformed) { // Try to throw away the assigned content this.OnThrowAway(); } else { // Reset the drop preformed variable this.m_DropPreformed = false; } }
/// <summary> /// Raises the drop event. /// </summary> /// <param name="eventData">Event data.</param> public virtual void OnDrop(PointerEventData eventData) { // Get the source slot UISlotBase source = (eventData.pointerPress != null) ? eventData.pointerPress.GetComponent<UISlotBase>() : null; // Make sure we have the source slot and it's assigned if (source == null || !source.IsAssigned()) return; // Notify the source that a drop was performed so it does not unassign source.dropPreformed = true; // Check if this slot is enabled and it's drag and drop feature is enabled if (!this.enabled || !this.m_DragAndDropEnabled) return; // Prepare a variable indicating whether the assign process was successful bool assignSuccess = false; // Normal empty slot assignment if (!this.IsAssigned()) { // Assign the target slot with the info from the source assignSuccess = this.Assign(source); // Unassign the source on successful assignment and the source is not static if (assignSuccess && !source.isStatic) source.Unassign(); } // The target slot is assigned else { // If the target slot is not static // and we have a source slot that is not static if (!this.isStatic && !source.isStatic) { // Check if we can swap if (this.CanSwapWith(source) && source.CanSwapWith(this)) { // Swap the slots assignSuccess = source.PerformSlotSwap(this); } } // If the target slot is not static // and the source slot is a static one else if (!this.isStatic && source.isStatic) { assignSuccess = this.Assign(source); } } // If this slot failed to be assigned if (!assignSuccess) { this.OnAssignBySlotFailed(source); } // Use the event eventData.Use(); }
/// <summary> /// Raises the drag event. /// </summary> /// <param name="eventData">Event data.</param> public virtual void OnDrag(PointerEventData eventData) { // Check if the dragging has been started if (this.m_DragHasBegan) { // Update the dragged object's position if (this.m_CurrentDraggedObject != null) this.UpdateDraggedPosition(eventData); // Use the event eventData.Use(); } }
/// <summary> /// Raises the begin drag event. /// </summary> /// <param name="eventData">Event data.</param> public virtual void OnBeginDrag(PointerEventData eventData) { if (!this.enabled || !this.IsAssigned() || !this.m_DragAndDropEnabled) { eventData.Reset(); return; } // Check if we have a key modifier and if it's held down if (!this.DragKeyModifierIsDown()) { eventData.Reset(); return; } // Start the drag this.m_DragHasBegan = true; // Create the temporary icon for dragging this.CreateTemporaryIcon(eventData); // Prevent event propagation eventData.Use(); }
/// <summary> /// This event is fired when an item is dropped /// onto this slot. Will accept the item /// into the slot OR swap the item. If the item is /// `Stackable`, will attempt to stack it /// </summary> /// <param name="eventData">The `PointerEventData` of the event</param> public virtual void OnDrop(PointerEventData eventData) { if (eventData.used || Draggable.DraggedItem == null) { return; } // if this slot doesn't have an item, // add this one if (Item == null) { AddItem(Draggable.DraggedItem); } else { Stackable stackableItem = Draggable.DraggedItem.GetComponent<Items.Stackable>(); Stackable slotStackableItem = Item.GetComponent<Items.Stackable>(); // the dropped item is stackable, as is // the item in this slot. Attempt to stack. // will return if successful. if (stackableItem != null && slotStackableItem != null) { try { slotStackableItem.Add(stackableItem); Draggable.DraggedItem.OnEndDrag(eventData); Draggable.DraggedItem = null; // manually spawn the tooltip as the // `OnPointerEnter` event won't trigger // automatically TooltipTrigger tooltipTrigger = Item.GetComponent<TooltipTrigger>(); if (tooltipTrigger != null) { tooltipTrigger.OnPointerEnter( new PointerEventData(EventSystem.current) ); } // if the item isn't stackable, swap items } catch (NotStackableException e) { Slot otherSlot = Draggable.DraggedItem.OldSlot; otherSlot.AddItem(RemoveItem()); AddItem(Draggable.DraggedItem); Draggable.DraggedItem.OnEndDrag(eventData); Draggable.DraggedItem = null; } } else { // swap the item with the item // that was dropped Draggable otherItem = Draggable.DraggedItem; Slot otherSlot = otherItem.OldSlot; // if other slot is currently occupied, // the draggable item will need to be // dropped before it can be swapped if (otherSlot.Item != null) { return; } // try to swap items- will only fail // if one slot requires a specific // `ItemType` try { // don't remove the item from // this slot until it successfully // gets added to the other slot Draggable itemInThisSlot = Item; otherSlot.AddItem(itemInThisSlot); RemoveItem(); AddItem(otherItem); } catch(CannotAddItemException e) { Debug.LogWarning(e); return; } } } Item.OnEndDrag(eventData); eventData.Use(); }
/// <summary> /// When this stack is clicked, check if the /// user is holding down the key modifier. If /// so, display the `StackableSplitter` which /// allows the user to enter a number to /// remove from this stack /// </summary> /// <param name="eventData">The `PointerEventData` of the event</param> public void OnPointerClick(PointerEventData eventData) { if (Input.GetKey(keyModifier)) { StackableSplitterFactory.Create(this); eventData.Use(); } }
public override void OnPointerClick(PointerEventData eventData) { //Debug.Log("OnPointerClick (isFocused: {0}, isUsed: {1}, isDragging: {2})".Fmt(isFocused, eventData.used, eventData.dragging)); if (!interactable) { return; } if (eventData.dragging) { return; } EventSystem.current.SetSelectedGameObject(gameObject, eventData); base.OnPointerClick(eventData); if ((m_Keyboard == null || !m_Keyboard.active)) { OnSelect(eventData); } else { UpdateLabel(); eventData.Use(); } }
public override void OnEndDrag(PointerEventData eventData) { if (!interactable) { return; } //Debug.Log("OnEndDrag (isFocused: {0}, isUsed: {1})".Fmt(isFocused, eventData.used)); //base.OnEndDrag(eventData); eventData.Use(); if (_dragStartAmount != _currentValue) { DeactivateInputField(); SendOnSubmit(); } }
public void OnPointerClick(PointerEventData eventData) { ExecuteEvents.Execute<IHeatmapHandler>(eventData.pointerPress, eventData, HeatmapEvents.heatmapHandler); eventData.Use(); }