void Start() { infScrollRect = GetComponent <InfiniteScrollRect>(); switch (datasetType) { case DatasetType.MonthsPriceDataSet: DatasetUtillity.FetchRemoteDataSet <MonthlyPriceDataSet>(dataSetUrl, onDataSetAquired); break; case DatasetType.CoinPriceDataSet: DatasetUtillity.FetchRemoteDataSet <CoinPriceDataset>(dataSetUrl, onDataSetAquired); break; } scrollCells = GetComponentsInChildren <ScrollCell>(); }
void Awake() { AudioListener[] au = FindObjectsOfType <AudioListener>(); if (au == null || au.Length == 0) { gameObject.AddComponent <AudioListener>(); } InfiniteScrollRect rect = ScrollView.GetScrollRect(); Main.Ins.SoundManager.SetSoundVolume(100); rect.SetFullScrollView(false); rect.SetModifiedScale(true); for (int i = 0; i <= 600; i++) { ScrollView.Add(new AnimationCellData(i)); } ScrollView.RefreshView(); }
protected virtual void UpdateView() { Canvas.ForceUpdateCanvases(); if (Index == -1) { Index = 0; } for (int i = 0; i < ContainerList.Count; i++) { ContainerList[i].transform.SetSiblingIndex(i); } if (Spawned) { for (int i = 0; i < ContainerList.Count; i++) { Despawn(ContainerList[i].transform as RectTransform); } } if (CellDataList.Count == 0) { return; } InfiniteScrollRect scrollRect = GetScrollRect(); if (StartOnLeft && (!TwoSideHiddenContainers && CellDataList.Count < ContainerList.Count || TwoSideHiddenContainers && CellDataList.Count + 1 < ContainerList.Count)) { for (int i = 0; i < CellDataList.Count; i++) { Spawn(ContainerList[i].transform as RectTransform, CellDataList[i]); if (FiniteLogic && Index - ContainerList.Count / 2 < 0) { if (CellDataList.Count <= ContainerList.Count) { scrollRect.BlockToNext = true; } scrollRect.BlockToPrevious = true; } else if (FiniteLogic && CellDataList.Count - ContainerList.Count / 2 - 1 < Index) { if (CellDataList.Count <= ContainerList.Count) { scrollRect.BlockToPrevious = true; } scrollRect.BlockToNext = true; } } if (FiniteLogic) { scrollRect.normalizedPosition = scrollRect.horizontal ? new Vector2(0f, 0.5f) : new Vector2(0f, 0f); } } else { int containersOnSides = ContainerList.Count / 2; scrollRect.BlockToPrevious = false; scrollRect.BlockToNext = false; if (scrollRect.horizontal) { if (FiniteLogic && Index - ContainerList.Count / 2 < 0) { scrollRect.RefreshCellCount(); scrollRect.horizontalNormalizedPosition = scrollRect.NormalizedPagePositions[0]; if (Index > 0) { float width = (Content.GetChild(Content.childCount - 1) as RectTransform).rect.width; Content.anchoredPosition = new Vector2(Content.anchoredPosition.x - width * Index + width * 0.5f, Content.anchoredPosition.y); } for (int i = 0; i < ContainerList.Count; i++) { if (i < CellDataList.Count) { ContainerList[i].gameObject.SetActive(true); Spawn(ContainerList[i].transform as RectTransform, CellDataList[i]); } else { ContainerList[i].gameObject.SetActive(false); } } if (CellDataList.Count <= ContainerList.Count) { scrollRect.BlockToNext = true; } scrollRect.BlockToPrevious = true; // Index = containersOnSides; } else if (FiniteLogic && CellDataList.Count - ContainerList.Count / 2 - 1 < Index) { scrollRect.RefreshCellCount(); scrollRect.horizontalNormalizedPosition = scrollRect.NormalizedPagePositions[scrollRect.NormalizedPagePositions.Length - 1]; if (Index < CellDataList.Count) { float width = (Content.GetChild(0) as RectTransform).rect.width; Content.anchoredPosition = new Vector2(Content.anchoredPosition.x + width * (CellDataList.Count - 1 - Index) - width * 0.5f, Content.anchoredPosition.y); } for (int i = 0; i < ContainerList.Count; i++) { if (i < CellDataList.Count) { ContainerList[ContainerList.Count - 1 - i].gameObject.SetActive(true); int count = CellDataList.Count > ContainerCount ? ContainerCount : CellDataList.Count; // TODO: FIX: very highly buggy code Spawn(ContainerList[ContainerList.Count - 1 - i].transform as RectTransform, CellDataList[CellDataList.Count - count + i]); } else { ContainerList[ContainerList.Count - 1 - i].gameObject.SetActive(false); } } if (CellDataList.Count <= ContainerList.Count) { scrollRect.BlockToPrevious = true; } scrollRect.BlockToNext = true; // Index = CellDataList.Count - containersOnSides - 1; } else { // center Spawn(ContainerList[containersOnSides].transform as RectTransform, CellDataList[Index]); // right side for (int i = 0; i < containersOnSides; i++) { int containerIdx = i + containersOnSides + 1; int cellDataIdx = GetCellDataIndex(Index, i + 1); if (CellDataList.Count <= cellDataIdx) { break; } Spawn(ContainerList[containerIdx].transform as RectTransform, CellDataList[cellDataIdx]); } // left side for (int i = 0; i < containersOnSides; i++) { int cellDataIdx = GetCellDataIndex(Index, -containersOnSides + i); if (cellDataIdx < 0) { break; } Spawn(ContainerList[i].transform as RectTransform, CellDataList[cellDataIdx]); } } } else if (scrollRect.vertical) { if (FiniteLogic && Index - ContainerList.Count / 2 < 0) { scrollRect.RefreshCellCount(); scrollRect.verticalNormalizedPosition = scrollRect.NormalizedPagePositions[0]; if (Index > 0) { float height = (Content.GetChild(Content.childCount - 1) as RectTransform).rect.height; Content.anchoredPosition = new Vector2(Content.anchoredPosition.x, Content.anchoredPosition.y - height * Index + height * 0.5f); } for (int i = 0; i < ContainerList.Count; i++) { if (i < CellDataList.Count) { ContainerList[i].gameObject.SetActive(true); int count = CellDataList.Count > ContainerCount ? ContainerCount : CellDataList.Count; Spawn(ContainerList[i].transform as RectTransform, CellDataList[count - i - 1]); } else { ContainerList[i].gameObject.SetActive(false); } } if (CellDataList.Count <= ContainerList.Count) { scrollRect.BlockToNext = true; } scrollRect.BlockToPrevious = true; // Index = containersOnSides; } else if (FiniteLogic && Index + ContainerList.Count / 2 >= CellDataList.Count - 1) { scrollRect.RefreshCellCount(); scrollRect.verticalNormalizedPosition = scrollRect.NormalizedPagePositions[scrollRect.NormalizedPagePositions.Length - 1]; if (Index < CellDataList.Count) { float height = (Content.GetChild(0) as RectTransform).rect.height; Content.anchoredPosition = new Vector2(Content.anchoredPosition.x, Content.anchoredPosition.y + height * (CellDataList.Count - 1 - Index) - height * 0.5f); } for (int i = 0; i < ContainerList.Count; i++) { if (i < CellDataList.Count) { ContainerList[ContainerList.Count - 1 - i].gameObject.SetActive(true); int count = CellDataList.Count > ContainerCount ? ContainerCount : CellDataList.Count; Spawn(ContainerList[ContainerList.Count - 1 - i].transform as RectTransform, CellDataList[CellDataList.Count - count + i]); } else { ContainerList[ContainerList.Count - 1 - i].gameObject.SetActive(false); } } if (CellDataList.Count <= ContainerList.Count) { scrollRect.BlockToPrevious = true; } scrollRect.BlockToNext = true; // Index = CellDataList.Count - containersOnSides - 1; } else { // center int dataCount = CellDataList.Count; if (containersOnSides < dataCount) { Spawn(ContainerList[containersOnSides].transform as RectTransform, CellDataList[Index]); } // top side for (int i = 0; i < containersOnSides && i < dataCount; i++) { int containerIdx = containersOnSides - 1 - i; int cellDataIdx = GetCellDataIndex(Index, 1 + i); Spawn(ContainerList[containerIdx].transform as RectTransform, CellDataList[cellDataIdx]); } // bottom side for (int i = 0; i < containersOnSides && i < (dataCount - containersOnSides + 1); i++) { int containerIdx = containersOnSides + 1 + i; int cellDataIdx = GetCellDataIndex(Index, -1 - i); Spawn(ContainerList[containerIdx].transform as RectTransform, CellDataList[cellDataIdx]); } if (FiniteLogic) { scrollRect.normalizedPosition = new Vector2(0.5f, 0.5f); } } } } // if (!TwoSideHiddenContainers && CellDataList.Count < ContainerList.Count || TwoSideHiddenContainers && CellDataList.Count + 1 < ContainerList.Count) { // for (int i = 0; i < ContainerList.Count; i++) { // if (ContainerList[i].transform.childCount == 0) { // ContainerList[i].ignoreLayout = true; // } // } // } else { // for (int i = 0; i < ContainerList.Count; i++) { // ContainerList[i].ignoreLayout = false; // } // } Spawned = true; Canvas.ForceUpdateCanvases(); }