Post by fatih on Oct 27, 2023 16:37:02 GMT
Hey there,
I recently build a (so far) working scrollable inventory grid (5 selectable cells per 1 cellrow), which I can store or retrieve items from on runtime.
Everytime the item list changes I call: scroller.ReloadData(scroller.ScrollPosition / scroller.ScrollSize); which successfully rebuilds the inventory as expected.
Each Cell has a selectable to submit and navigate through with unitys ui navigation stuff.
The issue is: I can't figure out a reliable way to manage the selection part. When I have a Slot selected and I remove that slot it does seemingly random things. sometimes it selects the right one sometimes it jumps to next row. I basically want it to reliably select the same Row/CellIndex, so that if I press the retrieve button over and over again it removes one item after another. The behavior kinda changes pattern when autoscrolling up or down.
In the "OnSelect()" Event method of each selectable I call "jump to data index" to autoscroll like this:
selectedRowIndex is a property which calls this method on "set":
Thanks a lot in advance!
I recently build a (so far) working scrollable inventory grid (5 selectable cells per 1 cellrow), which I can store or retrieve items from on runtime.
Everytime the item list changes I call: scroller.ReloadData(scroller.ScrollPosition / scroller.ScrollSize); which successfully rebuilds the inventory as expected.
Each Cell has a selectable to submit and navigate through with unitys ui navigation stuff.
The issue is: I can't figure out a reliable way to manage the selection part. When I have a Slot selected and I remove that slot it does seemingly random things. sometimes it selects the right one sometimes it jumps to next row. I basically want it to reliably select the same Row/CellIndex, so that if I press the retrieve button over and over again it removes one item after another. The behavior kinda changes pattern when autoscrolling up or down.
In the "OnSelect()" Event method of each selectable I call "jump to data index" to autoscroll like this:
public override void OnSelect(BaseEventData eventData)
{
base.OnSelect(eventData);
ScrollerController.instance.selectedRowIndex = cellView.cellIndex;
ScrollerController.instance.selectedCellIndex = id;
}
selectedRowIndex is a property which calls this method on "set":
private void AutoScrollBasedOnSelection(bool instant)
{
var rowIndex = _selectedRowIndex;
if (rowIndex+1 >= scroller.EndCellViewIndex)
{
if (instant)
{
scroller.JumpToDataIndex(rowIndex, .8f, .5f);
}
else
{
scroller.JumpToDataIndex(rowIndex, .8f, 1f, false ,EnhancedScroller.TweenType.easeOutSine,.05f);
}
}
else if (rowIndex-1 <= scroller.StartCellViewIndex)
{
if (instant)
{
scroller.JumpToDataIndex(rowIndex, .2f, .5f);
}
else
{
scroller.JumpToDataIndex(rowIndex, .2f, .0f,false ,EnhancedScroller.TweenType.easeOutSine,.05f);
}
}
}
Thanks a lot in advance!