/// <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); }
private void Awake() { if (Instance == null) { Instance = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } StartCoroutine(GetItemDataFromServer()); }
/// <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); }