void UpdateStickeyHeadPos() { bool isHeadItemVisible = mStickeyHeadItem.gameObject.activeSelf; int count = mLoopListView.ShownItemCount; if (count == 0) { if (isHeadItemVisible) { mStickeyHeadItem.gameObject.SetActive(false); } return; } LoopListViewItem2 item0 = mLoopListView.GetShownItemByIndex(0); Vector3 topPos0 = mLoopListView.GetItemCornerPosInViewPort(item0, ItemCornerEnum.LeftTop); LoopListViewItem2 targetItem = null; float start = topPos0.y; float end = start - item0.ItemSizeWithPadding; int targetItemShownIndex = -1; if (start <= 0) { if (isHeadItemVisible) { mStickeyHeadItem.gameObject.SetActive(false); } return; } if (end < 0) { targetItem = item0; targetItemShownIndex = 0; } else { for (int i = 1; i < count; ++i) { LoopListViewItem2 item = mLoopListView.GetShownItemByIndexWithoutCheck(i); start = end; end = start - item.ItemSizeWithPadding; if (start >= 0 && end <= 0) { targetItem = item; targetItemShownIndex = i; break; } } } if (targetItem == null) { if (isHeadItemVisible) { mStickeyHeadItem.gameObject.SetActive(false); } return; } int itemIndex = targetItem.UserIntData1; int childIndex = targetItem.UserIntData2; TreeViewItemCountData countData = mTreeItemCountMgr.GetTreeItem(itemIndex); if (countData == null) { if (isHeadItemVisible) { mStickeyHeadItem.gameObject.SetActive(false); } return; } if (countData.mIsExpand == false || countData.mChildCount == 0) { if (isHeadItemVisible) { mStickeyHeadItem.gameObject.SetActive(false); } return; } if (isHeadItemVisible == false) { mStickeyHeadItem.gameObject.SetActive(true); } if (mStickeyHeadItem.TreeItemIndex != itemIndex) { TreeViewItemData treeViewItemData = TreeViewDataSourceMgr.Get.GetItemDataByIndex(itemIndex); mStickeyHeadItem.mText.text = treeViewItemData.mName; mStickeyHeadItem.SetItemData(itemIndex, countData.mIsExpand); } mStickeyHeadItem.gameObject.transform.localPosition = Vector3.zero; float lastChildPosAbs = -end; float lastPadding = targetItem.Padding; if (lastChildPosAbs - lastPadding >= mStickeyHeadItemHeight) { return; } for (int i = targetItemShownIndex + 1; i < count; ++i) { LoopListViewItem2 item = mLoopListView.GetShownItemByIndexWithoutCheck(i); if (item.UserIntData1 != itemIndex) { break; } lastChildPosAbs += item.ItemSizeWithPadding; lastPadding = item.Padding; if (lastChildPosAbs - lastPadding >= mStickeyHeadItemHeight) { return; } } float y = mStickeyHeadItemHeight - (lastChildPosAbs - lastPadding); mStickeyHeadItemRf.anchoredPosition3D = new Vector3(0, y, 0); }