/// <summary> /// Resize content panel, keep the current position and reload. /// </summary> private void _KeepPositionAndReload(int itemQuantity, float contentSize) { Vector3[] itemPositions = new Vector3[mContentRealItemQuantity]; for (int i = 0; i < mContentRealItemQuantity; i++) { itemPositions[i] = mContentItems[i].transform.position; } Vector3 contentPosition = mContent.position; mContent.SetInsetAndSizeFromParentEdge(mIsHorizontalMode ? RectTransform.Edge.Left : RectTransform.Edge.Top, 0, contentSize); mContent.position = contentPosition; for (int i = 0; i < mContentRealItemQuantity; i++) { MyUGUIReusableListItem item = mContentItems[i]; item.transform.position = itemPositions[i]; if (item.Index < itemQuantity) { item.gameObject.SetActive(true); item.OnReload(); } else { item.gameObject.SetActive(false); } } }
/// <summary> /// Reload item. /// </summary> private void _ReloadItem(GameObject item, int realIndex = -1) { MyUGUIReusableListItem itemScript = item.GetComponent <MyUGUIReusableListItem>(); if (realIndex >= 0) { itemScript.Index = realIndex; } itemScript.OnReload(); }
/// <summary> /// Keep content panel size, keep the current position and reload. /// </summary> private void _KeepPositionAndReload() { for (int i = 0; i < mContentRealItemQuantity; i++) { MyUGUIReusableListItem item = mContentItems[i]; if (item.gameObject.activeSelf) { item.OnReload(); } } }
/// <summary> /// Resize content panel, move to top and reload. /// </summary> private void _MoveToTopAndReload(int itemQuantity, float contentSize) { mScrollRect.StopMovement(); mContent.SetInsetAndSizeFromParentEdge(mIsHorizontalMode ? RectTransform.Edge.Left : RectTransform.Edge.Top, 0, contentSize); mContentRealHeadIndex = 0; mContentRealTailIndex = itemQuantity < mContentRealDisplayItemQuantity ? itemQuantity - 1 : mContentRealItemQuantity - 1; mContentHeadIndex = mContentRealHeadIndex; mContentTailIndex = mContentRealTailIndex; for (int i = 0; i < mContentRealItemQuantity; i++) { MyUGUIReusableListItem item = mContentItems[i]; int row = mIsHorizontalMode ? i % mItemFixedLine : i / mItemFixedLine; int col = mIsHorizontalMode ? i / mItemFixedLine : i % mItemFixedLine; Vector2 pos = Vector2.zero; pos.x = (col * mItemSize.x) + (col * mItemSpacing.x); pos.y = -((row * mItemSize.y) + (row * mItemSpacing.y)); RectTransform itemRect = item.GetComponent <RectTransform>(); MyUtilities.Anchor(ref itemRect, MyUtilities.EAnchorPreset.TopLeft, MyUtilities.EAnchorPivot.TopLeft, mItemSize.x, mItemSize.y, pos.x, pos.y); item.Index = i; if (i < itemQuantity) { item.gameObject.SetActive(true); item.OnReload(); } else { item.gameObject.SetActive(false); } } mContentHeadItem = mContentItems[mContentRealHeadIndex].GetComponent <RectTransform>(); mContentTailItem = mContentItems[mContentRealTailIndex].GetComponent <RectTransform>(); if (mIsHorizontalMode) { mContentZone.x = mCanvas.InverseTransformPoint(mContentHeadItem.position).x - (mItemSize.x + mItemSpacing.x) * 1.5f; mContentZone.y = mCanvas.InverseTransformPoint(mContentTailItem.position).x; } else { mContentZone.x = mCanvas.InverseTransformPoint(mContentHeadItem.position).y + (mItemSize.y + mItemSpacing.y) * 1.5f; mContentZone.y = mCanvas.InverseTransformPoint(mContentTailItem.position).y; } }
/// <summary> /// Resize content panel, move to bot and reload. /// </summary> private void _MoveToBotAndReload(int itemQuantity, float contentSize) { Vector3 contentPosition = mContent.position; mContent.SetInsetAndSizeFromParentEdge(mIsHorizontalMode ? RectTransform.Edge.Left : RectTransform.Edge.Top, 0, contentSize); contentPosition.y = contentSize - mContentParent.rect.height; mContent.position = contentPosition; mContentLastPosition = contentPosition; int realTailIndex = mContentRealTailIndex; int index = mContentTailIndex; for (int i = 0; i < mContentRealItemQuantity; i++) { int realIndex = (realTailIndex - i + mContentRealItemQuantity) % mContentRealItemQuantity; MyUGUIReusableListItem item = mContentItems[realIndex]; int row = mIsHorizontalMode ? index % mItemFixedLine : index / mItemFixedLine; int col = mIsHorizontalMode ? index / mItemFixedLine : index % mItemFixedLine; Vector2 pos = Vector2.zero; pos.x = (col * mItemSize.x) + (col * mItemSpacing.x); pos.y = -((row * mItemSize.y) + (row * mItemSpacing.y)); RectTransform itemRect = item.GetComponent <RectTransform>(); MyUtilities.Anchor(ref itemRect, MyUtilities.EAnchorPreset.TopLeft, MyUtilities.EAnchorPivot.TopLeft, mItemSize.x, mItemSize.y, pos.x, pos.y); mContentHeadIndex = index; item.Index = index; if (index < itemQuantity) { item.gameObject.SetActive(true); item.OnReload(); } else { item.gameObject.SetActive(false); } index--; if (index < 0) { index += mContentRealItemQuantity; } } mContentHeadItem = mContentItems[mContentRealHeadIndex].GetComponent <RectTransform>(); mContentTailItem = mContentItems[mContentRealTailIndex].GetComponent <RectTransform>(); }