Post by freznosis on May 13, 2020 0:50:34 GMT
Hi Echo!
Thank you for making a great product. It integrated perfectly with my project.
I have a small problem with using JumpToDataIndex. I have 2 buttons called "Next" and "Previous" that simply change the data index. This is the code, it's basically the quick start tutorial with two buttons on the side. of the scroller.
The code works fine, but if you scroll too fast (spam next or previous button), the requested Data Index doesn't always get scrolled to properly (The scroller will stop prematurely on the the data index before it). I took a look at your code, and it seems to be because the coroutine doesn't finish before the next coroutine is started so the previous one might be overriding the latest one? I added this piece of code to EnhancedScroller and it seems to work fine now.
It's probably not the best way to do this, and I'm sure you know how to fix it. Or maybe I am doing something wrong and you can direct me to how to do this better. Thanks!
Thank you for making a great product. It integrated perfectly with my project.
I have a small problem with using JumpToDataIndex. I have 2 buttons called "Next" and "Previous" that simply change the data index. This is the code, it's basically the quick start tutorial with two buttons on the side. of the scroller.
private int currentPart=0;
[SerializeField]
private Button scrollerLeftButton, scrollerRightButton;
//Somewhere in OnEnable
if (_enhancedScroller != null)
{
if (scrollerLeftButton != null)
{
scrollerLeftButton.onClick.AddListener(() =>
{
if (scrollerController != null)
{
if (currentPart > 0)
{
currentPart -= 1;
_enhancedScroller.JumpToDataIndex(currentPart, 0.5f, 0.5f, true,
EnhancedScroller.TweenType.easeOutQuad, 0.2f);
}
}
});
}
if (scrollerRightButton != null)
{
scrollerRightButton.onClick.AddListener(() =>
{
if (currentPart < scrollerController.GetNumberOfCells(null)-1)
{
currentPart += 1;
_enhancedScroller.JumpToDataIndex(currentPart, 0.5f, 0.5f, true,
EnhancedScroller.TweenType.easeOutQuad, 0.2f);
}
});
}
}
The code works fine, but if you scroll too fast (spam next or previous button), the requested Data Index doesn't always get scrolled to properly (The scroller will stop prematurely on the the data index before it). I took a look at your code, and it seems to be because the coroutine doesn't finish before the next coroutine is started so the previous one might be overriding the latest one? I added this piece of code to EnhancedScroller and it seems to work fine now.
/// <summary>
/// Keeps track of jump coroutine so that we can manage it.
/// </summary>
private Coroutine currentJumpCoroutine;
//Kill last coroutine if it's still active.
if (currentJumpCoroutine != null)
{
StopCoroutine(currentJumpCoroutine);
}
// start tweening
currentJumpCoroutine = StartCoroutine(TweenPosition.....
It's probably not the best way to do this, and I'm sure you know how to fix it. Or maybe I am doing something wrong and you can direct me to how to do this better. Thanks!