Scroll the inventory with the mouse wheel?

dansani

New member
How is this done. I have tried so many different ways and it just seems impossible.
 
Last edited:
Unfortunatly we don't have any examples for this.

Depending on your needs you could use the Unity ScrollRect rather than using our "smart" scrollable UI.
It won't be as optimized as the ItemViewSlots won't be pooled but if you don't have a ton of items in your inventoryGrid you should be fine
Unitys Scroll Rect comes built in with mouse wheel scroll

If you want to use ours then you will need to write your own code for this.

There are different approaches you can take. But it all comes down to setting the value of scrollbar as you use the scroll wheel.

You can check how Unity does it for their ScrollRect component. They use the interface: IScrollHandler and implement the "OnScroll" function.
Their code look something like this:
Code:
 public virtual void OnScroll(PointerEventData data)
        {
            if (!IsActive())
                return;

            EnsureLayoutHasRebuilt();
            UpdateBounds();

            Vector2 delta = data.scrollDelta;
            // Down is positive for scroll events, while in UI system up is positive.
            delta.y *= -1;
            if (vertical && !horizontal)
            {
                if (Mathf.Abs(delta.x) > Mathf.Abs(delta.y))
                    delta.y = delta.x;
                delta.x = 0;
            }
            if (horizontal && !vertical)
            {
                if (Mathf.Abs(delta.y) > Mathf.Abs(delta.x))
                    delta.x = delta.y;
                delta.y = 0;
            }

            if (data.IsScrolling())
                m_Scrolling = true;

            Vector2 position = m_Content.anchoredPosition;
            position += delta * m_ScrollSensitivity;
            if (m_MovementType == MovementType.Clamped)
                position += CalculateOffset(position - m_Content.anchoredPosition);

            SetContentAnchoredPosition(position);
            UpdateBounds();
        }

But you could just as well make an input for mouse scroll and then check if your mouse is over an InventoryGrid, of so modify the scrollbar scroll value.

I hope that guides you in the right direction
 
Back
Top