예제 #1
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 < _items.Count; i++)
            {
                float dis = Mathf.Abs(Mathf.Abs(value) - Mathf.Abs((tmp - _items[i].CenterOffSet)));
                if (dis < min)
                {
                    closestIndex = i;
                    min          = dis;
                }
            }
            originHorizontalValue = curHorizontalValue;
            float target = ((int)curHorizontalValue + (tmp - _items[closestIndex].CenterOffSet));

            preCenterItem = curCenterItem;
            curCenterItem = _items[closestIndex];
            LerpTweenToTarget(originHorizontalValue, target, true);
            canChangeItem = false;
        }
예제 #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
 ///
 /// Update EnhanceItem state with curve fTime value
 ///
 public void UpdateEnhanceScrollView(float fValue)
 {
     for (int i = 0; i < _items.Count; i++)
     {
         EnhanceItem itemScript      = _items[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,
             _items.Count,
             yFixedPositionValue,
             scaleValue);
     }
 }
예제 #4
0
        void Start()
        {
            canChangeItem = true;
            int count = _items.Count;

            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--)
            {
                _items[i].CurveOffSetIndex = i;
                _items[i].CenterOffSet     = dFactor * (mCenterIndex - index);
                _items[i].SetSelectState(false);

                GameObject       obj    = _items[i].gameObject;
                UDragEnhanceView script = obj.GetComponent <UDragEnhanceView>();
                if (script != null)
                {
                    script.SetScrollView(this);
                }
                index++;
            }

            // set the center item with startCenterIndex
            if (startCenterIndex < 0 || startCenterIndex >= count)
            {
                Debug.LogError("## startCenterIndex < 0 || startCenterIndex >= listEnhanceItems.Count  out of index ##");
                startCenterIndex = mCenterIndex;
            }

            // sorted items
            listSortedItems      = new List <EnhanceItem>(_items.ToArray());
            totalHorizontalWidth = cellWidth * count;
            curCenterItem        = _items[startCenterIndex];
            curHorizontalValue   = 0.5f - curCenterItem.CenterOffSet;
            LerpTweenToTarget(0f, curHorizontalValue, false);
        }
예제 #5
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         = 0.0f;

            if (isRight)
            {
                dvalue = -dFactor * moveIndexCount;
            }
            else
            {
                dvalue = dFactor * moveIndexCount;
            }
            float originValue = curHorizontalValue;

            LerpTweenToTarget(originValue, curHorizontalValue + dvalue, true);
        }
예제 #6
0
 // sort item with X so we can know how much distance we need to move the timeLine(curve time line)
 public static int SortPosition(EnhanceItem a, EnhanceItem b)
 {
     return(a.transform.localPosition.x.CompareTo(b.transform.localPosition.x));
 }