Пример #1
0
        protected IEnumerator MoveContents(int to)
        {
            if (!_contentsList.First().gameObject.activeSelf)
            {
                _contentsList.Add(_contentsList.First());
                _contentsList.RemoveAt(0);
            }
            var fromPosition  = new List <Vector2>();
            var fromSizeDelta = new List <Vector2>();

            for (var index = 0; index < _contentsList.Count; index++)
            {
                fromPosition.Add(CalculatePosition(index));
                fromSizeDelta.Add(CalculateSize(index));
            }

            _currentContent = to;

            var toPosition  = new List <Vector2>();
            var toSizeDelta = new List <Vector2>();

            for (var index = 0; index < _contentsList.Count; index++)
            {
                toPosition.Add(CalculatePosition(index));
                toSizeDelta.Add(CalculateSize(index));
            }

            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;
            ButtonActiveSet();
        }
Пример #2
0
        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));
        }