コード例 #1
0
ファイル: UIItem.cs プロジェクト: JeffDev74/USystems
        public void OnBeginDrag(PointerEventData eventData)
        {
            DraggedItem           = this;
            DraggedItemStartSlot  = GetSlot();
            _tmpItemStartPosition = TheTransform.position;

            TheTransform.SetParent(MainCanvas.transform);

            TheCanvasGroup.blocksRaycasts = false;
        }
コード例 #2
0
ファイル: UIInventory.cs プロジェクト: JeffDev74/USystems
 private void SetupSlots()
 {
     // Set the slot inventory
     for (int i = 0; i < TheSlotsContainer.SlotsCount; i++)
     {
         // NOTE: if inventory is not set on start
         // the slots must be updated at some point
         UISlot slot = TheSlotsContainer.UISlotList[i];
         slot.InventoryUUID = InventoryUUID;
     }
 }
コード例 #3
0
ファイル: UIItem.cs プロジェクト: JeffDev74/USystems
        public UISlot GetSlot(bool force = false)
        {
            if (_theUISlot == null)
            {
                _theUISlot = GetComponentInParent <UISlot>();
            }

            if (force)
            {
                _theUISlot = GetComponentInParent <UISlot>();
            }

            return(_theUISlot);
        }
コード例 #4
0
ファイル: UIInventory.cs プロジェクト: JeffDev74/USystems
        private void AddItem(IItem item, bool updateUI)
        {
            if (TheInventory == null)
            {
                Debug.LogWarning("The inventory is null... Is this a network ui object??");
                return;
            }

            UISlot slot = TheSlotsContainer.GetSlot();

            if (slot)
            {
                slot.UpdateSlotItem(item, updateUI);
            }
            else
            {
                Debug.LogError("The slot is null.. is the inventory full???");
            }
        }
コード例 #5
0
ファイル: UIItem.cs プロジェクト: JeffDev74/USystems
        public void OnEndDrag(PointerEventData eventData)
        {
            if (TheTransform.parent == DraggedItemStartSlot)
            {
                TheTransform.position = _tmpItemStartPosition;
            }

            UISlot tmpSlot = GetSlot(true);

            if (tmpSlot == null)
            {
                TheTransform.SetParent(DraggedItemStartSlot.transform);
                // Remove item from inventory

                if (Item != null)
                {
                    EventSystem.EventMessenger.Instance.Raise(new Events.EventRemoveItemFromInventory(DraggedItemStartSlot.InventoryUUID, DraggedItemStartSlot.ThisUIItem.Item, false));
                }

                Item = null;
                UpdateUI();

                // check quantity ??

                // Event item was removed...
            }
            else
            {
                if (tmpSlot.InventoryUUID != DraggedItemStartSlot.InventoryUUID)
                {
                    EventSystem.EventMessenger.Instance.Raise(new Events.EventAddItemToInventory(tmpSlot.InventoryUUID, tmpSlot.ThisUIItem.Item, false));
                }
            }



            // Set Variables back to a safe value
            DraggedItem                   = null;
            DraggedItemStartSlot          = null;
            _tmpItemStartPosition         = TheTransform.position;
            TheCanvasGroup.blocksRaycasts = true;
        }
コード例 #6
0
        public void OnEndDrag(PointerEventData eventData)
        {
            if (Item == null)
            {
                return;
            }

            // If the parent slot is the same move the item back to its
            // start position
            if (transform.parent == DraggedItemStartSlot)
            {
                transform.position = _tmpItemStartPosition;
            }

            TheCanvasGroup.blocksRaycasts = true;

            // If The item is dragged outside a valid slot remove it
            if (Slot == null)
            {
                //Debug.Log("DRAGGED OUTSIDE INVENTORY");

                // Put the item back to its place
                transform.SetParent(DraggedItemStartSlot.transform);

                EventMessenger.Instance.Raise(new EventRemoveItemFromInventory(Item.BaseData.InventoryUUID, Item, false));

                // If the item was stacked the slot will be null as well
                // so we check if the quantity is greater then 0 to generate drop
                // Trigger event to generate inventory drop
                if ((Item.BaseData as IStackableData).Quantity > 0)
                {
                    Debug.LogWarning("Should send event to generate a drop");
                    // --> EventMessenger.Instance.Raise(new EventInventoryGenerateDrop(DraggedItemStartSlot.InventoryPanel.Inventory, Item));
                }

                DestroyItem();

                return;
            }

            if ((Item.BaseData as IStackableData).Quantity <= 0)
            {
                //Debug.Log("ITEM HAVE NO QUANTITY REMOVING");

                EventMessenger.Instance.Raise(new EventRemoveItemFromInventory(DraggedItemStartSlot.InventoryUUID, Item, false));

                DestroyItem();
                return;
            }

            UpdateSlotInfo();

            // We no longer need this references
            // Set back to a safe value
            DraggedItem           = null;
            DraggedItemStartSlot  = null;
            _tmpItemStartPosition = transform.position;

            ToggleQuantity(true);
            ToggleDamageBar(true);
            UpdateQuantity();
            UpdateDamageBar();
        }