private void ChangeContentsData(int currentContent) { for (var i = 0; i < _contentsList.Count; i++) { var content = _contentsList[i]; content.SetContentData(ContentDatas.GetIndex(currentContent + i)); content.RectTransform.anchoredPosition = CalculatePosition(i, true) + (0f, ScrollOffset).ToVector2(); } }
private void UpdateContentPosition(Vector2 scrollDelta) { var toContentPosition = (0f, ScrollOffset).ToVector2() + scrollDelta; var firstContent = _contentsList.GetIndex(0); var lastContent = _contentsList.GetIndex(-1); var gainCurrentContent = 0; var debugCode = 0; if (_loop) { if (lastContent.Equals(RedundantData) && scrollDelta.y < 0 && toContentPosition.y < 0) { debugCode = 1; _contentsList.Remove(lastContent); _contentsList.Insert(0, lastContent); } else if (firstContent.Equals(RedundantData) && scrollDelta.y > 0 && toContentPosition.y > 0) { debugCode = 2; _contentsList.Remove(firstContent); _contentsList.Add(firstContent); } ScrollOffset += scrollDelta.y; if (ScrollOffset <= -_contentSize.y) { CurrentContent--; ScrollOffset += _contentSize.y; } if (ScrollOffset >= _contentSize.y) { CurrentContent++; ScrollOffset -= _contentSize.y; } } else { if (CurrentContent + ShowingContentCount < ContentDatas.Count && CurrentContent != 0 && lastContent.Equals(RedundantData) && scrollDelta.y < 0 && toContentPosition.y < 0) { debugCode = 3; _contentsList.Remove(lastContent); _contentsList.Insert(0, lastContent); } else if (CurrentContent > 0 && CurrentContent + ShowingContentCount != ContentDatas.Count && firstContent.Equals(RedundantData) && scrollDelta.y > 0 && toContentPosition.y > 0) { debugCode = 4; _contentsList.Remove(firstContent); _contentsList.Add(firstContent); } if ((0 < CurrentContent || (CurrentContent == 0 && scrollDelta.y > 0)) && (CurrentContent < ContentDatas.Count - ShowingContentCount - 1 || (CurrentContent == ContentDatas.Count - ShowingContentCount - 1 && scrollDelta.y < 0))) { ScrollOffset += scrollDelta.y; if (ScrollOffset <= -_contentSize.y) { gainCurrentContent--; ScrollOffset += _contentSize.y; if (CurrentContent + gainCurrentContent == 0) { ScrollOffset = 0; } } if (ScrollOffset >= _contentSize.y) { gainCurrentContent++; ScrollOffset -= _contentSize.y; if (CurrentContent + gainCurrentContent == ContentDatas.Count - ShowingContentCount - 1) { ScrollOffset = 0; } } } } for (var i = 0; i < _contentsList.Count; i++) { var content = _contentsList[i]; content.SetContentData(ContentDatas.GetIndex(_currentContent + i + (ScrollOffset < 0 ? -1 : 0))); content.RectTransform.anchoredPosition = CalculatePosition(i, true) + (0f, ScrollOffset < 0 ? ScrollOffset + _contentSize.y : ScrollOffset).ToVector2(); } if (gainCurrentContent != 0) { CurrentContent += gainCurrentContent; } Debug.Log(debugCode); }
protected IEnumerator MoveContentsLoop(int dir) { var fromPosition = new List <Vector2>(); var fromSizeDelta = new List <Vector2>(); for (var index = -MiddleContentIndex - 1; index <= MiddleContentIndex + 1; index++) { fromPosition.Add(CalculatePosition(index, true)); fromSizeDelta.Add(CalculateSize(index, true)); } if (dir != 1) { fromPosition.RemoveAt(fromPosition.Count - 1); fromSizeDelta.RemoveAt(fromSizeDelta.Count - 1); } else { fromPosition.RemoveAt(0); fromSizeDelta.RemoveAt(0); } _currentContent += dir; _currentContent = (ContentDatas.Count + _currentContent) % ContentDatas.Count; var toPosition = new List <Vector2>(); var toSizeDelta = new List <Vector2>(); for (var index = -MiddleContentIndex - 2; index <= MiddleContentIndex + 2; index++) { toPosition.Add(CalculatePosition(index + dir, true)); toSizeDelta.Add(CalculateSize(index + dir, true)); } if (dir != 1) { toPosition.RemoveRange(0, 3); toSizeDelta.RemoveRange(0, 3); if (!_contentsList.First().gameObject.activeSelf) { var obj = _contentsList.First(); _contentsList.Remove(obj); _contentsList.Add(obj); obj.gameObject.SetActive(true); } else { var obj = _contentsList.Last(); obj.gameObject.SetActive(true); } } else { toPosition.RemoveRange(toPosition.Count - 3, 3); toSizeDelta.RemoveRange(toSizeDelta.Count - 3, 3); if (!_contentsList.Last().gameObject.activeSelf) { var obj = _contentsList.Last(); obj.gameObject.SetActive(true); } else { var obj = _contentsList.First(); _contentsList.Remove(obj); _contentsList.Add(obj); obj.gameObject.SetActive(true); } } for (var i = -MiddleContentIndex + _currentContent; i <= MiddleContentIndex + _currentContent + 1; i++) { _contentsList.GetIndex(i + MiddleContentIndex - _currentContent + (dir < 0 ? 0 : dir)) .SetContentData(ContentDatas.GetIndex(i)); } ButtonActiveSet(MiddleContentIndex + (dir == 1 ? 0 : 1), true); for (var index = 0; index < _contentsList.Count; index++) { _contentsList[index].RectTransform.localPosition = fromPosition[index]; _contentsList[index].RectTransform.localScale = fromSizeDelta[index]; } yield return(YieldManager.GetWaitForFixedUpdate()); for (var i = 0; i < 60 / _scrollSpeed; i++) { for (var index = 0; index < _contentsList.Count; index++) { _contentsList[index].RectTransform.localPosition = Vector3.Lerp(fromPosition[index], toPosition[index], i * ScrollSpeedPerFixedDeltaTime); _contentsList[index].RectTransform.localScale = Vector3.Lerp(fromSizeDelta[index], toSizeDelta[index], i * ScrollSpeedPerFixedDeltaTime); } yield return(YieldManager.GetWaitForFixedUpdate()); } _action = null; if (dir == 1) { _contentsList.First().gameObject.SetActive(false); } else { _contentsList.Last().gameObject.SetActive(false); } ButtonActiveSet(MiddleContentIndex + (dir == 1 ? 1 : 0)); }