float _nowUpdateViewTime = 0; //更新視角時間 bool UpdateAnimate() { //更新UI移動 if (_lastIndex != _index) { UpdateMenuPosition(_nowAnimateTime); UpdateScale(_nowAnimateTime); _nowAnimateTime = _nowAnimateTime + Time.deltaTime; //如果時間到惹 if (_nowAnimateTime >= AnimationCurveManager.GetDifferenceTime(_moveCurve)) { _lastIndex = _index; _nowAnimateTime = 0; } } //更新視角 if (_focusViewToIndex) { //if (_lastViewPosition != _shouldViewPosition) if (_lastIndex != _index) { //更新位置,index,ladtIndex,Time? CalculatePrecentageOfWidthAndHeight(_index); _nowUpdateViewTime++; } //如果時間到了 } return(false); }
//更新放大大小 void UpdateScale(float time) { for (int i = 0; i <= _menuList.Count; i++) //如果是單行,i就只會是0 { float scale; if (i == _index) { //物件放大 scale = AnimationCurveManager.GetValueBetweenTwoParameter(1, _scale, _scaleCurve, time); } else { //物件大小正常 scale = 1; } //設定大小 SetMenuScale(i, scale); } }
//更新Menu縮放 void UpdateMenuPosition(float time) { //先弄出一個陣列,然後算出相對上一個的距離 Vector3[,] array; if (_menuList.Count < _numberInRow) { array = new Vector3[1, _menuList.Count];//設定陣列範圍 } else { array = new Vector3[(_menuList.Count / _numberInRow) + 1, _numberInRow]; } for (int i = 0; i <= (_menuList.Count / _numberInRow); i++) //如果是單行,i就只會是0 { for (int k = 0; k < _numberInRow; k++) { int nowIndex = i * _numberInRow + k; if (nowIndex < _menuList.Count) { float horizontalPosition = 0; //距離左邊位置 float verticlPosition = 0; //距離上方位置 //如果是index那行或是+1,就表示要放大(或是跑動畫) if (IsInIndexColumn(nowIndex)) { //表示是剛剛是往上下移動才會有動畫 if (IndexMovePosition().left == true || IndexMovePosition().right == true) { horizontalPosition = AnimationCurveManager.GetValueBetweenTwoParameter(_menuHorizontalDistance, _horizontalDistenceBetweenIndexToMenu, _moveCurve, time); } else { horizontalPosition = _horizontalDistenceBetweenIndexToMenu; } } else { horizontalPosition = _menuHorizontalDistance;//正常大小 } //計算出橫的的距離,表示目前index為橫的 if (IsInIndexRow(nowIndex)) { //如果是index那一列或是+1,就表示要放大(或是跑動畫) if (IndexMovePosition().up == true || IndexMovePosition().down == true) { verticlPosition = AnimationCurveManager.GetValueBetweenTwoParameter(_menuVerticalDistance, _verticalDistenceBetweenIndexToMenu, _moveCurve, time); } else { verticlPosition = _verticalDistenceBetweenIndexToMenu; } } else { //正常大小 verticlPosition = _menuVerticalDistance; } array[i, k].x = horizontalPosition;//水平 array[i, k].y = verticlPosition; } } } float nowTotlWidth = 0; //距離左邊的距離 (( horizontalPosition float nowTotalHeight = 0; //距離上面的距離 (( verticlPosition if (!_vertical) { //然後填入位置 for (int i = 0; i <= (_menuList.Count / _numberInRow); i++) //如果是單行,i就只會是0 { nowTotlWidth = 0; for (int k = 0; k < _numberInRow; k++) { int nowIndex = i * _numberInRow + k; if (nowIndex < _menuList.Count) { if (_focusViewToIndex) { //設定位置 SetMenuPosition(nowIndex, nowTotlWidth + array[i, k].x - array[_index / _numberInRow, _index % _numberInRow].x, nowTotalHeight + array[i, k].y - array[_index / _numberInRow, _index % _numberInRow].y); //幫下一個加好 nowTotlWidth = nowTotlWidth + array[i, k].x; } else { //設定位置 SetMenuPosition(nowIndex, nowTotlWidth + array[i, k].x, nowTotalHeight + array[i, k].y); //幫下一個加好 nowTotlWidth = nowTotlWidth + array[i, k].x; } } } nowTotalHeight = nowTotalHeight + array[i, 0].y; } } else { //然後填入位置 for (int i = 0; i <= (_menuList.Count / _numberInRow); i++) //如果是單行,i就只會是0 { nowTotalHeight = 0; for (int k = 0; k < _numberInRow; k++) { int nowIndex = i * _numberInRow + k; if (nowIndex < _menuList.Count) { if (_focusViewToIndex) { Debug.Log("_focusViewToIndex" + array[_index / _numberInRow, _index % _numberInRow].y); //設定位置 SetMenuPosition(nowIndex, nowTotlWidth + array[i, k].x - array[_index / _numberInRow, _index % _numberInRow].x, nowTotalHeight + array[i, k].y - array[_index / _numberInRow, _index % _numberInRow].y); //設定大小 SetMenuScale(nowIndex, array[i, k].z); //幫下一個加好 nowTotalHeight = nowTotalHeight + array[i, k].y; } else { //設定位置 SetMenuPosition(nowIndex, nowTotlWidth + array[i, k].x, nowTotalHeight + array[i, k].y); //設定大小 SetMenuScale(nowIndex, array[i, k].z); //幫下一個加好 nowTotalHeight = nowTotalHeight + array[i, k].y; } } } nowTotlWidth = nowTotlWidth + array[i, 0].x; } } }