/// <summary>
        /// Remove the item that resides in this specific slot.
        /// </summary>
        /// <param name="slot">The `Slot` to remove
        /// an item from</param>
        /// <returns>The `GameObject` in the slot, or null</returns>
        public override GameObject Remove(Slot slot)
        {
            if (slot.Item == null) {
                return null;
            }

            return slot.RemoveItem().gameObject;
        }
Beispiel #2
0
 public abstract GameObject Remove(Slot slot);
Beispiel #3
0
        /// <summary>
        /// This event is automatically fired automatically
        /// as this object is a MonoBehaviour. If the event
        /// is already used, or there is an item already 
        /// being dragged, will do nothing.
        /// </summary>
        /// <param name="eventData">The `PointerEventData` of the event</param>
        public void OnBeginDrag(PointerEventData eventData)
        {
            if ((eventData != null && eventData.used) || DraggedItem != null) {
                return;
            }

            if (OnBeginDragCallback != null) {
                OnBeginDragCallback(eventData);
            }

            DraggedItem = this;
            canvasGroup.blocksRaycasts = false;

            oldSlot = GetComponentInParent<Slot>();
            oldSlot.RemoveItem();

            //  place it in the parent canvas so
            //  it renders above everything else
            transform.SetParent(canvas.transform);

            beingDragged = true;

            //  trigger the item did get picked up event
            ItemEventManager.TriggerItemDidPickup(gameObject, eventData);
        }
Beispiel #4
0
 /// <summary>
 /// Trigger an invalid item drop
 /// </summary>
 /// <param name="item">The `GameObject` being dropped</param>
 /// <param name="slot">The former parent `Slot` (may be null)</param>
 /// <param name="data">The `PointerEventData` of the event</param>
 public static void TriggerItemDidInvalidDrop(GameObject item, Slot slot, PointerEventData data)
 {
     if (OnItemDidInvalidDrop != null) {
         OnItemDidInvalidDrop(item, slot, data);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Called when the item stops being dragged.
        /// Will get called _after_ `OnDrop` (which `Slot`
        /// implements). Will trigger the `ItemDidInvalidDrop`
        /// event if the item wasn't dropped successfully.
        /// </summary>
        /// <param name="eventData">The `PointerEventData` of the event</param>
        public void OnEndDrag(PointerEventData eventData)
        {
            //  OnEndDrag can be triggered via mouse down
            //  or mouse up, if there is no currently dragged
            //  item the event has already been fired
            if (DraggedItem == null) {
                return;
            }

            DraggedItem = null;

            //  if this item is still in the canvas transform
            //  that means the drop was unsuccessful- trigger
            //  the ItemDidDrop event
            if (transform.parent == canvas.transform) {

                transform.position = oldSlot.transform.position;
                transform.SetParent(oldSlot.transform);
                oldSlot.AddItem(this);

                if (!eventData.used) {
                    ItemEventManager.TriggerItemDidInvalidDrop(gameObject, oldSlot, eventData);
                }
            }

            oldSlot = null;
            canvasGroup.blocksRaycasts = true;

            beingDragged = false;

            //  trigger necessary events
            if (OnEndDragCallback != null) {
                OnEndDragCallback(eventData);
            }

            ItemEventManager.TriggerItemDidDrop(gameObject, eventData);
        }