public float GetMaxWidthHeightValue(UltimateSlot slot) { float positionValue = UtilityMethod.GetAxisValue(slot.Position, UltimateScrollView.Direction.TopDown), sizeValue = UtilityMethod.GetAxisValue(slot.slotStat.GetSize(), UltimateScrollView.Direction.TopDown); return(positionValue - (sizeValue * 0.5f)); }
private int FindCurrentIndex(int startIndex, float viewNavPoint) { int _currentIndex = startIndex; if (_currentIndex >= 0 && _currentIndex < _slotListCount) { float slotPosValue = UtilityMethod.GetAxisValue(_slotList[_currentIndex].Position, directionStat); float slotSizeValue = UtilityMethod.GetAxisValue(_slotList[_currentIndex].slotStat.GetSize(), directionStat); float currentIndexMin = _baseOrientation.GetIndexMin(slotPosValue, slotSizeValue); float currentIndexMax = _baseOrientation.GetIndexMax(slotPosValue, slotSizeValue); if (viewNavPoint <= currentIndexMax && viewNavPoint >= currentIndexMin) { return(_currentIndex); } if (viewNavPoint > currentIndexMax && currentIndex + 1 < _slotListCount) { return(FindCurrentIndex(_currentIndex + 1, viewNavPoint)); } if (viewNavPoint < currentIndexMin && currentIndex - 1 >= 0) { return(FindCurrentIndex(_currentIndex - 1, viewNavPoint)); } } return(_currentIndex); }
private void UpdateViewportPos() { if (isDragging) { return; } float viewTrackPos = UtilityMethod.GetAxisValue(_scrollRect.content.anchoredPosition, directionStat); float viewportSize = UtilityMethod.GetRectValue(_scrollRect.viewport.rect, directionStat); //Debug.Log("_scrollViewLength " + _scrollViewLength); //Debug.Log("viewTrackPos " + viewTrackPos); //Debug.Log("viewportSize " + viewportSize); //Align ScrollRect On top, if condition meet if (_baseOrientation.AlignTopValidation(viewTrackPos, _scrollViewLength, viewportSize)) { _scrollRect.content.anchoredPosition = _baseOrientation.AlignTopTargetPos(_scrollViewLength, viewportSize, viewTrackPos); return; } //Align ScrollRect On bottom, if condition meet if (_baseOrientation.AlignBottomValidation(viewTrackPos, _scrollViewLength, viewportSize)) { _scrollRect.content.anchoredPosition = _baseOrientation.AlignBottomTargetPos(_scrollViewLength, viewportSize, viewTrackPos); if (OnLastScrollSlot != null) { OnLastScrollSlot(); } return; } }
private void UpdateElementPos(int startIndex) { if (startIndex < 0 || startIndex >= _slotListCount) { return; } var ultiSlot = _slotList[startIndex]; var slotSize = ultiSlot.slotStat.GetSize(); float slotSizeValue = UtilityMethod.GetAxisValue(slotSize, directionStat); float visibleSizeValue = UtilityMethod.GetAxisValue(visibleSize, directionStat); //Beginning position for every slot float startPosition = _baseOrientation.GetStartPosition(visibleSizeValue, slotSizeValue); float latestHeight = (startIndex == 0) ? startPosition : _baseOrientation.GetMaxWidthHeightValue(_slotList[startIndex - 1]); float positionValue = _baseOrientation.GetElementMainPos(startIndex, latestHeight, slotSize, this.space); ultiSlot.SetPosition(_baseOrientation.GetElementPosVector(positionValue, visibleSize)); ultiSlot.SetIndex(startIndex); _scrollViewLength = Mathf.Abs(latestHeight - slotSizeValue - startPosition); //ScrollBar now only support topdown _scrollContent.sizeDelta = new Vector2(0, _scrollViewLength); }
public float GetElementMainPos(int index, float latestHeight, Vector2 slotSize, float space) { float slotWidth = UtilityMethod.GetAxisValue(slotSize, UltimateScrollView.Direction.RightLeft); float positionValue = (latestHeight + (slotWidth * 0.5f)); if (index > 0) { positionValue += space; } return(positionValue); }
void Update() { if (this.gameObject.activeInHierarchy && _slotList != null) { float viewNavPoint = UtilityMethod.GetAxisValue(_scrollRect.content.anchoredPosition, directionStat); if (currentIndex >= 0 && currentIndex < _slotListCount) { currentIndex = FindCurrentIndex(currentIndex, viewNavPoint); UpdateElementVisibility(); UpdateViewportPos(); } } UpdateOnScreenResize(); }