Exemplo n.º 1
0
        public virtual void OnDragMove(BaseEventData eventData)
        {
            PointerEventData pointerData = ((PointerEventData)eventData);

            if (pointerData == null)
            {
                return;
            }

            if (DATABASE_INVENTORY != null &&
                DATABASE_INVENTORY.inventorySettings.onDragGrabItem && this.item.sprite != null)
            {
                InventoryUIManager.OnDragItem(this.item.sprite, true);
            }

            if (pointerData.pointerCurrentRaycast.gameObject == null)
            {
                return;
            }
            GameObject target      = pointerData.pointerCurrentRaycast.gameObject;
            ItemUI     otherItemUI = target.GetComponent <ItemUI>();

            if (otherItemUI != null)
            {
                Button otherButton = pointerData.pointerCurrentRaycast.gameObject.GetComponentInChildren <Button>();
                if (otherButton != null)
                {
                    this.HighlightButton(this.button, true);
                    this.HighlightButton(otherButton, true);
                }

                eventData.Use();
            }
        }
        // INITIALIZERS: --------------------------------------------------------------------------

        private void Awake()
        {
            InventoryUIManager.Instance = this;
            if (transform.childCount >= 1)
            {
                this.inventoryRoot     = transform.GetChild(0).gameObject;
                this.inventoryAnimator = this.inventoryRoot.GetComponent <Animator>();
            }

            if (this.floatingItem != null)
            {
                this.floatingItemRT = this.floatingItem.GetComponent <RectTransform>();
            }
            InventoryUIManager.OnDragItem(null, false);
        }
Exemplo n.º 3
0
        public virtual void OnDragBegin(BaseEventData eventData)
        {
            if (DATABASE_INVENTORY != null && DATABASE_INVENTORY.inventorySettings.cursorDrag != null)
            {
                Cursor.SetCursor(
                    DATABASE_INVENTORY.inventorySettings.cursorDrag,
                    DATABASE_INVENTORY.inventorySettings.cursorDragHotspot,
                    CursorMode.Auto
                    );
            }

            if (DATABASE_INVENTORY != null &&
                DATABASE_INVENTORY.inventorySettings.onDragGrabItem && this.item.sprite != null)
            {
                InventoryUIManager.OnDragItem(this.item.sprite, true);
            }

            eventData.Use();
        }
Exemplo n.º 4
0
        // INITIALIZERS: --------------------------------------------------------------------------

        private void Awake()
        {
            InventoryUIManager.Instance = this;
            this.currentItems           = new Dictionary <int, InventoryUIItem>();

            if (this.itemsContaineScrollRect == null)
            {
                this.itemsContaineScrollRect.GetComponentInChildren <ScrollRect>();
            }

            if (transform.childCount >= 1)
            {
                this.inventoryRoot     = transform.GetChild(0).gameObject;
                this.inventoryAnimator = this.inventoryRoot.GetComponent <Animator>();
            }

            if (this.floatingItem != null)
            {
                this.floatingItemRT = this.floatingItem.GetComponent <RectTransform>();
            }
            InventoryUIManager.OnDragItem(null, false);
        }
Exemplo n.º 5
0
        public virtual void OnDragEnd(BaseEventData eventData)
        {
            if (DATABASE_INVENTORY != null && DATABASE_INVENTORY.inventorySettings.cursorDrag != null)
            {
                Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
            }

            InventoryUIManager.OnDragItem(null, false);
            PointerEventData pointerData = ((PointerEventData)eventData);

            if (pointerData == null)
            {
                return;
            }
            if (pointerData.pointerCurrentRaycast.gameObject == null)
            {
                return;
            }

            GameObject      target            = pointerData.pointerCurrentRaycast.gameObject;
            IgniterDropItem targetDrop        = target.GetComponent <IgniterDropItem>();
            EquipSlotUI     targetEquipSlotUI = target.GetComponent <EquipSlotUI>();
            ItemUI          targetItemUI      = target.GetComponent <ItemUI>();

            if (targetDrop != null)
            {
                targetDrop.OnDrop(this.item);
                eventData.Use();
            }
            else if (targetEquipSlotUI != null)
            {
                targetEquipSlotUI.OnDrop(this.item);
                eventData.Use();
            }
            else if (targetItemUI == null)
            {
                bool mouseOverUI = EventSystemManager.Instance.IsPointerOverUI();
                if (!mouseOverUI && DATABASE_INVENTORY.inventorySettings.canDropItems && this.item.prefab != null)
                {
                    Vector3 position  = pointerData.pointerCurrentRaycast.worldPosition + (Vector3.up * 0.1f);
                    Vector3 direction = position - HookPlayer.Instance.transform.position;

                    if (direction.magnitude > DATABASE_INVENTORY.inventorySettings.dropItemMaxDistance)
                    {
                        position = (
                            HookPlayer.Instance.transform.position +
                            direction.normalized * DATABASE_INVENTORY.inventorySettings.dropItemMaxDistance
                            );
                    }

                    Instantiate(this.item.prefab, position, Quaternion.identity);
                    InventoryManager.Instance.SubstractItemFromInventory(this.item.uuid, 1);
                }

                eventData.Use();
            }
            else if (this.item.uuid != targetItemUI.item.uuid)
            {
                Button otherButton = pointerData.pointerCurrentRaycast.gameObject.GetComponentInChildren <Button>();
                if (otherButton != null)
                {
                    this.HighlightButton(this.button, false);
                    this.HighlightButton(otherButton, false);
                }

                InventoryManager.Instance.UseRecipe(this.item.uuid, targetItemUI.item.uuid);
                eventData.Use();
            }
        }