コード例 #1
0
        public virtual void OnBeginDrag(PointerEventData eventData)
        {
            if (itemCollection == null || item == null || itemCollection.canDragInCollection == false)
            {
                return;
            }

            if (item != null && itemCollection.canDragInCollection)
            {
                InventoryUIDragUtility.OnBeginDrag(this, eventData);
            }
        }
コード例 #2
0
        public virtual void OnDrag(PointerEventData eventData)
        {
            if (itemCollection == null || item == null || itemCollection.canDragInCollection == false)
            {
                return;
            }


            InventoryUIDragUtility.OnDrag(eventData);

            //if (eventData.button == PointerEventData.InputButton.Left || (eventData.button == PointerEventData.InputButton.Right && InventorySettingsManager.instance.unstackItemButton == PointerEventData.InputButton.Right))
        }
コード例 #3
0
        protected virtual void OnDisable()
        {
            if (useCustomUpdate)
            {
                StopCustomUpdate();
            }

            if (currentlyHoveringSlot == this)
            {
                currentlyHoveringSlot = null;
            }

            if (pointerDownOnUIElement == this)
            {
                pointerDownOnUIElement = null;
            }

            if (InventoryUIDragUtility.isDraggingItem)
            {
                InventoryUIDragUtility.OnEndDrag(new PointerEventData(EventSystem.current));
            }
        }
コード例 #4
0
        public virtual void OnEndDrag(PointerEventData eventData)
        {
            if (itemCollection == null || item == null || itemCollection.canDragInCollection == false)
            {
                return;
            }

            var lookup = InventoryUIDragUtility.OnEndDrag(eventData);

            if (lookup == null)
            {
                return; // No drag handler.
            }
            // for mobile...
            var endOnData = UIUtility.PointerOverUIObject(InventoryManager.instance.uiRoot, InventoryUIUtility.mouseOrTouchPosition);

            foreach (var d in endOnData)
            {
                var slot = d.gameObject.GetComponent <ItemCollectionSlotUIBase>();
                if (slot != null)
                {
                    lookup.endItemCollection = slot.itemCollection;
                    lookup.endIndex          = (int)slot.index;

                    break;
                }
            }

            if (lookup.endOnSlot)
            {
                #region Slot movement

                // When is large and dragged the end drag event can happen on the slots that's being dragged.
                // from     x       x
                // x        to      x
                // x        x       x
                // From -> To -> 1 down -> 1 to the right

                // Offset things for the layout
                var i = lookup.endItemCollection[lookup.endIndex].item;
                if (i != null)
                {
                    if (i == item && item.layoutSize > 1)
                    {
                        // Ended on self, and we're larger than 1x1 -- Try to move item to the side
                        var rect     = transform.GetComponent <RectTransform>();
                        var tempItem = lookup.endItemCollection[lookup.endIndex].item;

                        var singleSize = rect.sizeDelta;
                        singleSize.x /= tempItem.layoutSizeCols;
                        singleSize.y /= tempItem.layoutSizeRows;

                        var dif       = eventData.pressPosition - eventData.position;
                        var stepsCols = Mathf.RoundToInt(-dif.x / singleSize.x);
                        var stepsRows = Mathf.RoundToInt(dif.y / singleSize.y);

                        lookup.endIndex += (int)(stepsCols + (stepsRows * lookup.endItemCollection.colsCount));
                        lookup.endIndex  = Mathf.Clamp(lookup.endIndex, 0, lookup.endItemCollection.items.Length - 1);
                    }
                }

                #endregion

                // Place on a slot
                if (InventorySettingsManager.instance.settings.useUnstackDrag && lookup.endItemCollection.useReferences == false && lookup.endItemCollection.canUnstackItemsInCollection)
                {
                    if (InventorySettingsManager.instance.settings.unstackKeys.AllPressed(eventData, InventoryActionInput.EventType.All))
                    {
                        TriggerUnstack(lookup.endItemCollection, lookup.endIndex);
                        return; // Stop the rest otherwise we'll do 2 actions at once.
                    }
                }

                lookup.startItemCollection.SwapOrMerge((uint)lookup.startIndex, lookup.endItemCollection, (uint)lookup.endIndex);
            }
            else if (lookup.startItemCollection.useReferences)
            {
                lookup.startItemCollection.SetItem((uint)lookup.startIndex, null);
                lookup.startItemCollection[lookup.startIndex].Repaint();
            }
            else if (UIUtility.isHoveringUIElement == false)
            {
                TriggerDrop();
            }
        }