Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to finish a drag at the given drag space position.
        /// </summary>
        public void EndDrag(DragHolder inHolder)
        {
            if (DraggingObject != null)
            {
                DragEndState endState;
                DragObject   dragObject = DraggingObject;
                DraggingObject = null;

                if (inHolder == null)
                {
                    endState = DragEndState.Empty;
                }
                else
                {
                    if (inHolder.AllowAddObject(dragObject))
                    {
                        dragObject.SetOwner(inHolder);
                        endState = DragEndState.ValidZone;
                    }
                    else
                    {
                        LastValidSeat lastSeat      = dragObject.GetComponent <LastValidSeat>();
                        bool          bValidSwap    = lastSeat != null && lastSeat.LastValidHolder != null;
                        DragObject    swappedObject = null;
                        if (bValidSwap)
                        {
                            bValidSwap = inHolder.AllowSwapObject(dragObject, out swappedObject);
                        }
                        if (bValidSwap)
                        {
                            bValidSwap = lastSeat.LastValidHolder.AllowAddObject(swappedObject);
                        }

                        if (bValidSwap)
                        {
                            swappedObject.SetOwner(lastSeat.LastValidHolder);
                            dragObject.SetOwner(inHolder);
                            endState = DragEndState.ValidZone;
                        }
                        else
                        {
                            endState = DragEndState.InvalidZone;
                        }
                    }
                }

                dragObject.DraggingStops(endState);

                if (OnDragEnd != null)
                {
                    OnDragEnd(dragObject, endState);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Cancels an existing drag.
        /// </summary>
        public void CancelDrag()
        {
            if (DraggingObject != null)
            {
                DragObject dragObject = DraggingObject;
                DraggingObject = null;

                dragObject.DraggingStops(DragEndState.Cancelled);
                if (OnDragEnd != null)
                {
                    OnDragEnd(dragObject, DragEndState.Cancelled);
                }
            }
        }