Forum rules - please read before posting.

Inventory buttons: can't drag between "pages"

Hello Chris,
I'm trying to find a middle ground between the button interactions in my inventory. As of now, the whole inventory works on Unity UI and looks great... but, since each page is 6 slots wide, when trying to drag one item from one page to the other, so as to combine them, I basically can't.

The buttons respond to pointer click. The idea would be that, when dragging one item, it could automatically jump to the next page (pointer enter) when hovering over an arrow. But only on that scenario, not always. If there's not draggable, then let it be "pointer click".

Interface settings are: Point & Click, context sensitive and drag & drop interface.

I've found that another user had this problem and you shared two scripts.
https://adventurecreator.org/forum/discussion/6088/inventory-shift-right-when-item-drag-and-hover-over-shift-right-button

This one works for me: https://adventure-creator.fandom.com/wiki/Shifting_inventory_with_drag-and-drop
but there is a really weird bug when hovering over an arrow for the second time. It's like it's stuck on "is over" and continuously goes back and forth without any input from my side. Maybe because it's an almost 3 years old script?

https://imgur.com/a/k8COP8I
v1.74.5
Unity 2020.3.27f1

Thanks a lot!

Comments

  • What do you mean by "back and forth"?

    The script is designed to work by timer - so keeping the cursor over the button causes it to "click" and reset the timer before it can do so again. If you want it to only work once, change the script to set isOver to false instead of true after invoking the button's onClick event.

  • Hello Chris! Fixed. back and forth means that after you drag the item to the arrow, and continue pressing down the left click, it would go to the previous page and then next indefinetly after 0.5 seconds or so. It's stuck on "isOver" and happens until you release the mouse buttom. This one won't do that.

    using System;
    using UnityEngine;
    using UnityEngine.EventSystems;
    using AC;

    public class DragAndDropInventoryButtons : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
    {

    public UnityEngine.UI.Button uiButton;
    public float totalHoldTime = 0.4f;
    public bool isOver = false;
    public float currentHold;
    
    private void Awake ()
    {
        if (uiButton == null)
        {
            uiButton = GetComponent <UnityEngine.UI.Button>();
        }
    }
    
    public void OnPointerEnter (PointerEventData eventData)
    {
        if (!isOver && uiButton != null && AC.KickStarter.playerInput.GetDragState () == DragState.Inventory)
        {
            StartWait ();
        }
    }
    
    
    public void OnPointerExit (PointerEventData eventData)
    {
        isOver = false;
    }
    
    private void Update ()
    {
        if (isOver)
        {
            if (KickStarter.playerInput.GetMouseState () != MouseState.HeldDown)
            {
                isOver = false;
            }
    
            if (currentHold > 0f)
            {
                currentHold -= Time.deltaTime;
    
                if (currentHold <= 0f)
                {
                    uiButton.onClick.Invoke ();
                    isOver = false;
                    //StartWait ();
                }
            }
        }
    }
    
    private void StartWait ()
    {
        isOver = true;
        currentHold = totalHoldTime;
    }
    

    }

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.