Beispiel #1
0
        /// <summary>
        /// Attempt to move item from to the destination
        /// </summary>
        /// <param name="destination"></param>
        /// <returns></returns>
        private bool AttemptSimpleTransfer(IDragDestination <T> destination, InputButton button)
        {
            //Debug.Log("In simple transfer");
            //Get the current item and number from the source container
            var draggingItem   = m_source.GetItem();
            var draggingNumber = 0;
            var maxCanReceive  = destination.MaxAcceptable(draggingItem);

            if (button == InputButton.Left)
            {
                draggingNumber = m_source.GetNumber();
            }
            else
            {
                draggingNumber = 1;
            }

            //Determine how many of the item can be transfered based on the destination container
            //var maxCanReceive = destination.MaxAcceptable(draggingItem);
            var numToTransfer = Mathf.Min(maxCanReceive, draggingNumber);

            //If there are items to be transfered, descrease count in source and add # of items to destination.
            if (numToTransfer > 0)
            {
                m_source.RemoveItems(numToTransfer);
                destination.AddItems(draggingItem, numToTransfer);
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        private bool AttemptSimpleTransfer(IDragDestination <T> destination)
        {
            var draggingItem   = source.GetItem();
            var draggingNumber = source.GetNumber();

            var acceptable = destination.MaxAcceptable(draggingItem);
            var toTransfer = Mathf.Min(acceptable, draggingNumber);

            if (toTransfer > 0)
            {
                source.RemoveItems(toTransfer);
                destination.AddItems(draggingItem, toTransfer);
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        private bool AttemptItemTransfer(IDragDestination <T> destination)
        {
            T   draggingItem   = _itemSource.GetItem();
            int draggingNumber = _itemSource.GetNumber();

            int acceptable = destination.MaxAcceptable(draggingItem);
            int toTransfer = Mathf.Min(acceptable, draggingNumber);

            //if we have items to transfer
            if (toTransfer > 0)
            {
                //remove items from the source
                _itemSource.RemoveItems(toTransfer);

                //and add them to the destination
                destination.AddItems(draggingItem, toTransfer);
                return(false);
            }

            return(true);
        }