void Update() { bool selectionChanged = false; if (Input.GetKeyDown(KeyCode.UpArrow) && _selectedIndex >= numberOfCellsPerRow) { // the up arrow was used, so we move the selected index up _selectedIndex = Mathf.Clamp(_selectedIndex - numberOfCellsPerRow, 0, _data.Count - 1); selectionChanged = true; } else if (Input.GetKeyDown(KeyCode.DownArrow) && _selectedIndex < _data.Count - numberOfCellsPerRow) { // the down arrow was used, so we move the selected index down _selectedIndex = Mathf.Clamp(_selectedIndex + numberOfCellsPerRow, 0, _data.Count - 1); selectionChanged = true; } else if (Input.GetKeyDown(KeyCode.LeftArrow)) { // the down arrow was used, so we move the selected index down _selectedIndex = Mathf.Clamp(_selectedIndex - 1, 0, _data.Count - 1); selectionChanged = true; } else if (Input.GetKeyDown(KeyCode.RightArrow)) { // the down arrow was used, so we move the selected index down _selectedIndex = Mathf.Clamp(_selectedIndex + 1, 0, _data.Count - 1); selectionChanged = true; } if (selectionChanged) { // the selected index was changed, so we update the underlying data for (var i = 0; i < _data.Count; i++) { _data[i].isSelected = i == _selectedIndex; } // refresh the visible cell views to update the selection highlight scroller.RefreshActiveCellViews(); var rowIndex = (_selectedIndex / numberOfCellsPerRow); if (rowIndex >= scroller.EndCellViewIndex) { // the selected index is at the bottom or beyond, so we need to scroll down. // note that we set the scroll offset to 1 (the end of the scroller) // and also set the cell offset to 1 so that the entire last cell is visible. scroller.JumpToDataIndex(rowIndex, 1.0f, 1.0f); } else if (rowIndex <= scroller.StartCellViewIndex) { // the selected index is at the top or beyond, so we need to scroll up. // note that we set the scroll offset to 0 (the start of the scroller) // and also set the cell offset to 0 so that the entire first cell is visible. scroller.JumpToDataIndex(rowIndex, 0.0f, 0.0f); } } }
public void OnUpButtonClick() { if (scroller.IsTweening == true) { return; } scroller.JumpToDataIndex(scroller.StartCellViewIndex - pageCount, 0, 0.05f, true, EnhancedScroller.TweenType.linear, 0.5f); }
/// <summary> /// Populates the data with a lot of records /// </summary> private void LoadData(int pageStartIndex) { // grab the last index of the data to jump to when we are finished var previousLastIndex = _data.Count; // calculate the last index of the new list var lastIndex = _data.Count + pageCount; // add data to the list for (var i = pageStartIndex; i < lastIndex; i++) { _data.Add(new Data() { someText = "Cell Data Index " + i.ToString() }); } // tell the scroller to reload now that we have the data. scroller.ReloadData(); // jump to the previous last index to make it look like the scroller did not move scroller.JumpToDataIndex(previousLastIndex, 1, 1); // toggle off loading new so that we can load again at the bottom of the scroller _loadingNew = false; }
public void AddNewRow(DataChat.CellType cellType, string text) { // first, clear out the cells in the scroller so the new text transforms will be reset scroller.ClearAll(); _oldScrollPosition = scroller.ScrollPosition; // reset the scroller's position so that it is not outside of the new bounds scroller.ScrollPosition = 0; // second, reset the data's cell view sizes for (var i = 1; i < _data.Count; i++) { _data[i].cellSize = 0; } // now we can add the data row _data.Add(new DataChat() { cellType = cellType, cellSize = 0, someText = text }); ResizeScroller(); // jump to the end of the scroller to see the new content. // once the jump is completed, reset the spacer's size scroller.JumpToDataIndex(_data.Count - 1, 1f, 1f, tweenType: EnhancedScroller.TweenType.easeInOutSine, tweenTime: 0.5f, jumpComplete: ResetSpacer); }
/// <summary> /// This function adds a new record, resizing the scroller and calculating the sizes of all cells /// </summary> public void AddNewRow() { // first, clear out the cells in the scroller so the new text transforms will be reset scroller.ClearAll(); // reset the scroller's position so that it is not outside of the new bounds scroller.ScrollPosition = 0; // second, reset the data's cell view sizes foreach (var item in _data) { item.cellSize = 0; } // now we can add the data row _data.Add(new Data() { cellSize = 0, someText = _data.Count.ToString() + " New Row Added!" }); ResizeScroller(); // optional: jump to the end of the scroller to see the new content scroller.JumpToDataIndex(_data.Count - 1, 1f, 1f); }
private void LoadData() { _data = mapConfig.stageList; scroller.Delegate = this; scroller.ReloadData(); scroller.JumpToDataIndex(CampaignStageData.GetStageIndex(playerCampaign.GetLastStagePass()) - 1); }
public void JumpButton_OnClick() { int jumpDataIndex; // extract the integer from the input text if (int.TryParse(jumpIndexInput.text, out jumpDataIndex)) { // jump to the index vScroller.JumpToDataIndex(jumpDataIndex, scrollerOffsetSlider.value, cellOffsetSlider.value, useSpacingToggle.isOn, vScrollerTweenType, vScrollerTweenTime, null, EnhancedScroller.LoopJumpDirectionEnum.Down); hScroller.JumpToDataIndex(jumpDataIndex, scrollerOffsetSlider.value, cellOffsetSlider.value, useSpacingToggle.isOn, hScrollerTweenType, hScrollerTweenTime); } else { Debug.LogWarning("The jump value you entered is not a number."); } }
private void JumpToLevelID(int levelId, float time = 0f) { int idx = _levelList.IndexFromLevelId(levelId); if (idx == -1) { Debug.Log("levelId dont exist"); return; } // jump to the index myScroller.JumpToDataIndex(idx, 0.5f, 0.5f, true, EnhancedScroller.TweenType.linear, time, () => { _levelList.SelectSingleLevel(_levelList[idx]); } ); }
private void ShowStarted() { _customReminderScreen.gameObject.SetActive(false); _tempNewReminderData.fireDate = DateTime.Today.Date + _tempNewReminderData.fireDate.TimeOfDay; // initialize all reminders SetScroller(ReminderManager.Instance.GetAllReminders(AppManager.Instance.currentAppMode)); // of there is such reminder int index = _data.IndexOf(_defaultSelection); if (index > -1) { scroller.JumpToDataIndex(index); _selectedItem = scroller.GetCellViewAtDataIndex(index) as ReminderUiItem; SetState(State.Edit); } else { // set New state by default SetState(State.New); } }
IEnumerator _ReloadDataAndJumping(int inventoryId) { UpdateData(); var index = 0; for (int i = 0; i < itemDatas.Count; i++) { if (itemDatas[i].inventoryId == inventoryId) { index = i; break; } } yield return(new WaitForEndOfFrame()); masterScroller.ReloadData(); var jumpIndex = index / COLUMN; jumpIndex = jumpIndex == 0 ? jumpIndex : jumpIndex - 1; masterScroller.JumpToDataIndex(jumpIndex); }
/// <summary> /// This is called when a cell is clicked /// </summary> /// <param name="dataIndex"></param> private void TweenEnd(int dataIndex) { // toggle the expanded value _data[dataIndex].isExpanded = !_data[dataIndex].isExpanded; if (dataIndex % 2 == 1) { // single expanded cell. collapse others for (var i = 0; i < _data.Count; i++) { if (i != dataIndex) { _data[i].isExpanded = false; } } } // Since the size of the scroller will be changing, we can't simply pass in the normalized // scroll position to the ReloadData method. Instead we will do some math to get the current offset // of the first or last visible cell and use that in the JumpToDataIndex call after the ReloadData call. // This can accommodate any changes in the sizes of multiple cell views. var jumpDataIndex = 0; var jumpPosition = 0f; var jumpCellSize = 0f; var cellOffset = 0f; if (_tweeningFirstPadder) { // get the end data index so that we can jump to this after the reload jumpDataIndex = scroller.EndDataIndex; // the actual start position of this end data index so we can calculate a cell offset when we jump jumpPosition = scroller.GetScrollPositionForDataIndex(jumpDataIndex, EnhancedScroller.CellViewPositionEnum.Before); // get the size of the cell at the end data index jumpCellSize = _data[jumpDataIndex].isExpanded ? _data[jumpDataIndex].expandedSize : _data[jumpDataIndex].collapsedSize; // get the cell offset by taking the difference of the bottom of the scroller and cell view start position (minus the bottom padding) and dividing it by the size of the cell cellOffset = (scroller.ScrollPosition + scroller.ScrollRectSize - jumpPosition - scroller.padding.bottom) / jumpCellSize; } else { // get the start data index so that we can jump to this after the reload jumpDataIndex = scroller.StartDataIndex; // the actual start position of this start data index so we can calculate a cell offset when we jump jumpPosition = scroller.GetScrollPositionForDataIndex(jumpDataIndex, EnhancedScroller.CellViewPositionEnum.Before); // get the size of the cell at the start data index jumpCellSize = _data[jumpDataIndex].isExpanded ? _data[jumpDataIndex].expandedSize : _data[jumpDataIndex].collapsedSize; // get the cell offset by taking the difference of the scroll position and cell view start position and dividing it by the size of the cell cellOffset = (scroller.ScrollPosition - jumpPosition) / jumpCellSize; } // if we are expanding the cell view, add a look ahead to the beginning and end of the // scroller so that it loads in extra cells. This is necessary because when we // start to collapse, we will need these extra cells so that the others do // not get stretched by the layout element of the ScrollRect container. scroller.lookAheadBefore = _data[dataIndex].isExpanded ? 200.0f : 0.0f; scroller.lookAheadAfter = _data[dataIndex].isExpanded ? 200.0f : 0.0f; // reload the scroller to set the new positions and sizes scroller.ReloadData(); if (_tweeningFirstPadder) { // jump back to the original end data index that we cached above to make it // appear the scroller did not reset. // we use the cell offset calculated above and ignore the spacing. scroller offset is at the bottom scroller.JumpToDataIndex(jumpDataIndex, scrollerOffset: 1f, cellOffset: cellOffset, useSpacing: false); } else { // jump back to the original start data index that we cached above to make it // appear the scroller did not reset. // we use the cell offset calculated above and ignore the spacing scroller.JumpToDataIndex(jumpDataIndex, scrollerOffset: 0f, cellOffset: cellOffset, useSpacing: false); } }
private void OnItemSelected(int index, Action actionComplete = null) { scroller.JumpToDataIndex(index, 0.5f, 0.5f, true, scrollerTweenType, scrollerTweenTime, actionComplete); currentIndexItem = index; }
private void ReloadData(int index = 0) { scroller.ReloadData(); scroller.JumpToDataIndex(index); }