private bool isUpdatingList = false;
private float gridCellWidth = -1f;
private int invisibleCount = 0;
private readonly int SKIP_COUNT = 3;
public IEnumerator ItemIsInvisible(int itemNumber) {
bool skip = false;
if(invisibleCount > 0) {
if(invisibleCount < SKIP_COUNT) {
skip = true;
}
if(scrollPanel.currentMomentum.x < 0) {
invisibleCount = 0;
}
}
else if(invisibleCount < 0) {
if(-invisibleCount < SKIP_COUNT) {
skip = true;
}
if(scrollPanel.currentMomentum.x > 0) {
invisibleCount = 0;
}
}
if(scrollPanel.currentMomentum.x > 0) {
invisibleCount++;
}
else if(scrollPanel.currentMomentum.x < 0) {
invisibleCount--;
}
if(!skipItemIsInvisibleCall && !skip) {
if(isUpdatingList) yield return null;
isUpdatingList = true;
if(dataList.Count > poolSize) {
scrollPanel.UpdatePosition();
if(gridCellWidth == -1f) {
GameObject firstObject = itemsPool[0];
GameObject secondObject = itemsPool[1];
gridCellWidth = secondObject.transform.position.x - firstObject.transform.position.x;
}
if(scrollPanel.currentMomentum.x > 0) {
GameObject firstItem = itemsPool[0];
FlingerItem flingerItem = firstItem.GetComponent<FlingerItem>();
int itemDataIndex = flingerItem.itemDataIndex;
if(itemDataIndex == 0) {
isUpdatingList = false;
return false;
itemDataIndex = dataList.Count;
}
int dotIndex = 0;
int j = 0;
while(j < itemDataIndex && dotIndex < dotCount - 1) {
j+=itemsPerDot;
if(j < itemDataIndex) {
dotIndex++;
}
}
if(dotIndex != curDotIndex) {
curDotIndex = dotIndex;
for(int i = 0; i < pagingDots.Count; i++) {
bool value = (i == curDotIndex);
pagingDots[i].GetComponent<DotItem>().dotToggleBtn.value = value;
}
}
GameObject lastItem = itemsPool[itemsPool.Count - 1];
Vector2 newPos = firstItem.transform.position;
newPos.x -= gridCellWidth;
lastItem.transform.position = newPos;
lastItem.GetComponent<FlingerItem>().InitFlingerItem(dataList[itemDataIndex - 1]);
lastItem.GetComponent<FlingerItem>().itemDataIndex = itemDataIndex - 1;
for(int i = poolSize - 2; i >= 0; i--) {
itemsPool[i].GetComponent<FlingerItem>().itemNumber++;
itemsPool[i+1] = itemsPool[i];
}
itemsPool[0] = lastItem;
lastItem.GetComponent<FlingerItem>().itemNumber = 0;
}
else if(scrollPanel.currentMomentum.x < 0) {
GameObject lastItem = itemsPool[poolSize - 1];
FlingerItem flingerItem = lastItem.GetComponent<FlingerItem>();
int itemDataIndex = flingerItem.itemDataIndex;
if(itemDataIndex == dataList.Count - 1) {
isUpdatingList = false;
return false;
itemDataIndex = -1;
}
int dotIndex = 0;
int j = 0;
while(j < itemDataIndex && dotIndex < dotCount - 1) {
j+=itemsPerDot;
if(j < itemDataIndex) {
dotIndex++;
}
}
if(dotIndex != curDotIndex) {
curDotIndex = dotIndex;
for(int i = 0; i < pagingDots.Count; i++) {
bool value = (i == curDotIndex);
pagingDots[i].GetComponent<DotItem>().dotToggleBtn.value = value;
}
}
GameObject firstItem = itemsPool[0];
Vector2 newPos = lastItem.transform.position;
newPos.x += gridCellWidth;
firstItem.transform.position = newPos;
firstItem.GetComponent<FlingerItem>().InitFlingerItem(dataList[itemDataIndex + 1]);
firstItem.GetComponent<FlingerItem>().itemDataIndex = itemDataIndex + 1;
for(int i = 1; i < poolSize; i++) {
itemsPool[i].GetComponent<FlingerItem>().itemNumber--;
itemsPool[i-1] = itemsPool[i];
}
itemsPool[poolSize - 1] = firstItem;
firstItem.GetComponent<FlingerItem>().itemNumber = poolSize - 1;
}
// scrollPanel.ResetPosition();
scrollPanel.UpdatePosition();
}
isUpdatingList = false;
}
}