lcy
2025-12-03 b9a6e7e896b451e9c915e782a1789b2afe079cc9
Main/Component/UI/EnhancedScroller/EnhancedScroller.cs
@@ -462,8 +462,10 @@
            }
        }
        public int ActiveCellCnt {
            get {
        public int ActiveCellCnt
        {
            get
            {
                return _activeCellViews.Count;
            }
        }
@@ -881,9 +883,12 @@
        /// Cached reference to the scrollRect
        /// </summary>
        private ScrollRect m_ScrollRect;
        public ScrollRect scrollRect {
            get {
                if (m_ScrollRect == null) {
        public ScrollRect scrollRect
        {
            get
            {
                if (m_ScrollRect == null)
                {
                    m_ScrollRect = this.GetComponent<ScrollRect>();
                }
                return m_ScrollRect;
@@ -1102,6 +1107,85 @@
            }
        }
        // 仅聊天功能使用
        public void AddHeight(bool keepPosition, float height)
        {
            // 如果启用循环,回退到完整的 _Resize,因为循环逻辑复杂
            if (loop)
            {
                _Resize(keepPosition);
                return;
            }
            // 缓存原始位置
            var originalScrollPosition = _scrollPosition;
            int cellCount = NumberOfCells;
            if (cellCount == 0)
            {
                // 没有单元格,调用 _Resize 处理
                _Resize(keepPosition);
                return;
            }
            int newCellIndex = cellCount - 1; // 新单元格的索引
            // 检查内部数组是否一致:_cellViewSizeArray 应该已经包含了除新单元格外的所有单元格
            if (_cellViewSizeArray.Count != newCellIndex)
            {
                // 不一致,回退到完整重置
                _Resize(keepPosition);
                return;
            }
            // 计算新单元格的大小(包括间距)
            float newSize = height;
            newSize += spacing;
            // 添加到大小数组
            _cellViewSizeArray.Add(newSize);
            // 更新偏移数组
            float previousOffset = (_cellViewOffsetArray.Count > 0) ? _cellViewOffsetArray.Last() : 0;
            _cellViewOffsetArray.Add(previousOffset + newSize);
            // 设置活动单元格容器的大小
            if (scrollDirection == ScrollDirectionEnum.Vertical)
                _container.sizeDelta = new Vector2(_container.sizeDelta.x, _cellViewOffsetArray.Last() + padding.top + padding.bottom);
            else
                _container.sizeDelta = new Vector2(_cellViewOffsetArray.Last() + padding.left + padding.right, _container.sizeDelta.y);
            // 重建可见单元格
            _ResetVisibleCellViews();
            if (this.Delegate != null)
            {
                this.Delegate.OnRebuildComplete();
            }
            // 如果需要保持原始位置
            if (keepPosition)
            {
                ScrollPosition = originalScrollPosition;
            }
            else
            {
                ScrollPosition = 0;
            }
            // 设置滚动条可见性
            ScrollbarVisibility = scrollbarVisibility;
            if (!m_IsLoadAll)
            {
                m_IsLoadAll = true;
                if (OnFirstLoadAllEvent != null)
                {
                    OnFirstLoadAllEvent();
                }
            }
        }
        /// <summary>
        /// This function will create an internal list of sizes and offsets to be used in all calculations.
        /// It also sets up the loop triggers and positions and initializes the cell views.