예제 #1
0
 // Update EnhanceItem state with curve fTime value
 private void UpdateEnhanceScrollView(float fValue)
 {
     for (int i = 0; i < _listEnhanceItems.Count; i++)
     {
         EnhanceItem itemScript      = _listEnhanceItems[i];
         float       xValue          = GetXPosValue(fValue, itemScript.CenterOffSet);
         float       scaleValue      = GetScaleValue(fValue, itemScript.CenterOffSet);
         float       depthCurveValue = _depthCurve.Evaluate(fValue + itemScript.CenterOffSet);
         itemScript.UpdateScrollViewItems(xValue, depthCurveValue, _depthFactor, _listEnhanceItems.Count,
                                          _yFixedPositionValue, scaleValue);
     }
     // 只处理了有4个的情况
     if (IsShowThree)
     {
         if (_listEnhanceItems.Count > 3)
         {
             _listEnhanceItems.Sort((a, b) => a.SiblingIndex - b.SiblingIndex);
             for (int i = 0; i < _listEnhanceItems.Count; i++)
             {
                 if (i == 0)
                 {
                     _listEnhanceItems[i].gameObject.SetActive(false);
                 }
                 else
                 {
                     _listEnhanceItems[i].gameObject.SetActive(true);
                 }
             }
         }
     }
 }
예제 #2
0
        private int GetMoveCurveFactorCount(EnhanceItem preCenterItem, EnhanceItem newCenterItem)
        {
            SortEnhanceItem();
            int factorCount = Mathf.Abs(newCenterItem.RealIndex) - Mathf.Abs(preCenterItem.RealIndex);

            return(Mathf.Abs(factorCount));
        }
예제 #3
0
        // On Drag End
        public void OnDragEnhanceViewEnd()
        {
            // find closed item to be centered
            int   closestIndex = 0;
            float value        = (_curHorizontalValue - (int)_curHorizontalValue);
            float min          = float.MaxValue;
            float tmp          = 0.5f * (_curHorizontalValue < 0 ? -1 : 1);

            for (int i = 0; i < _listEnhanceItems.Count; i++)
            {
                float dis = Mathf.Abs(Mathf.Abs(value) - Mathf.Abs((tmp - _listEnhanceItems[i].CenterOffSet)));
                if (dis < min)
                {
                    closestIndex = i;
                    min          = dis;
                }
            }
            _originHorizontalValue = _curHorizontalValue;
            float target = ((int)_curHorizontalValue + (tmp - _listEnhanceItems[closestIndex].CenterOffSet));

            _preCenterItem = _curCenterItem;
            _curCenterItem = _listEnhanceItems[closestIndex];
            LerpTweenToTarget(_originHorizontalValue, target, true);
            _canChangeItem = false;
        }
예제 #4
0
        public void SetHorizontalTargetItemIndex(EnhanceItem selectItem)
        {
            if (!_canChangeItem)
            {
                return;
            }

            if (_curCenterItem == selectItem)
            {
                return;
            }

            _canChangeItem = false;
            _preCenterItem = _curCenterItem;
            _curCenterItem = selectItem;

            // calculate the direction of moving
            float centerXValue = _positionCurve.Evaluate(0.5f) * _totalHorizontalWidth;
            bool  isRight      = selectItem.transform.localPosition.x > centerXValue;

            // calculate the offset * dFactor
            int   moveIndexCount = GetMoveCurveFactorCount(_preCenterItem, selectItem);
            float dvalue         = isRight ? -_dFactor * moveIndexCount : _dFactor * moveIndexCount;
            float originValue    = _curHorizontalValue;

            LerpTweenToTarget(originValue, _curHorizontalValue + dvalue, true);
        }
예제 #5
0
        public void InitData <T>(List <T> dataList)
        {
            LogManager.Assert(_itemObj != null, "预设不能为空");
            if (_itemObj == null)
            {
                return;
            }
            if (_listEnhanceItems.Count <= 0)
            {
                int num = dataList.Count;
                for (int i = 0; i < num; i++)
                {
                    GameObject go = Instantiate(_itemObj);
                    go.transform.SetParent(transform, false);
                    EnhanceItem item = go.GetComponent <EnhanceItem>();

                    item.EnhanceScrollView = this;
                    item.ListIndex         = i;
                    item.ListCount         = num;
                    _listEnhanceItems.Add(item);

                    if (IsVertical)
                    {
                        item.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, -90));
                    }
                }
            }

            for (int i = 0; i < _listEnhanceItems.Count; i++)
            {
                _listEnhanceItems[i].SetData(dataList[i]);
            }
            InitView();
        }
예제 #6
0
 // sort item with X so we can know how much distance we need to move the timeLine(curve time line)
 private int SortPosition(EnhanceItem a, EnhanceItem b)
 {
     return(a.transform.localPosition.x.CompareTo(b.transform.localPosition.x));
 }
예제 #7
0
        private void InitView()
        {
            _canChangeItem = true;
            int count = _listEnhanceItems.Count;

            if (count <= 0)
            {
                return;
            }
            _dFactor      = (Mathf.RoundToInt((1f / count) * 10000f)) * 0.0001f;
            _mCenterIndex = count / 2;
            if (count % 2 == 0)
            {
                _mCenterIndex = count / 2 - 1;
            }
            int index = 0;

            for (int i = count - 1; i >= 0; i--)
            {
                _listEnhanceItems[i].CurveOffSetIndex = i;
                if (count != 2)
                {
                    _listEnhanceItems[i].CenterOffSet = _dFactor * (_mCenterIndex - index);
                }
                else//只有2个item时,初始化时第二个item会显示在左边,是因为AnimationCurve的取值区间是[0,1],导致偏移量为1时取值0,[0,1)不知道怎么实现╮(╯▽╰)╭
                {   //当前的曲线的走向看噩梦关卡/日常活动里的PositionCurve,改成其他曲线时这里可能有坑...
                    _listEnhanceItems[1].CenterOffSet = 0.49f;
                    _listEnhanceItems[0].CenterOffSet = 0.01f;
                }
                _listEnhanceItems[i].SetSelectState(false);
                GameObject obj = _listEnhanceItems[i].gameObject;


                UDragEnhanceView script = obj.GetComponent <UDragEnhanceView>() ?? obj.AddComponent <UDragEnhanceView>();
                if (script != null)
                {
                    script.SetScrollView(this);
                }
                index++;
            }

            // set the center item with startCenterIndex
            if (_startCenterIndex < 0 || _startCenterIndex >= count)
            {
                LogManager.Error("## startCenterIndex < 0 || startCenterIndex >= listEnhanceItems.Count  out of index ##");
                _startCenterIndex = _mCenterIndex;
            }

            // sorted items
            _listSortedItems      = new List <EnhanceItem>(_listEnhanceItems.ToArray());
            _totalHorizontalWidth = _cellWidth * count;
            _curCenterItem        = _listEnhanceItems[_startCenterIndex];
            _curHorizontalValue   = 0.5f - _curCenterItem.CenterOffSet;
            LerpTweenToTarget(0f, _curHorizontalValue, false);

            if (IsVertical)
            {
                _rectTrans.anchoredPosition = new Vector2(0, -_totalHorizontalWidth / 2);
                _rectTrans.localRotation    = Quaternion.Euler(new Vector3(0, 0, 90));
            }
            else
            {
                _rectTrans.anchoredPosition = new Vector2(-_totalHorizontalWidth / 2, 0);
                _rectTrans.localRotation    = Quaternion.Euler(new Vector3(0, 0, 0));
            }
        }