protected override void LateUpdate() { if (!IsActive()) { return; } if (!Dragging_ && TargetIndex_ != -1) { UpdateBounds(); var Offset = InternalCalculatePositionWithIndex(TargetIndex_).y; var AnchoredPositionY = Mathf.SmoothDamp(Content.anchoredPosition.y, Offset, ref CurrentVelocity_, Elasticity, float.PositiveInfinity, Time.unscaledDeltaTime); if (Mathf.Abs(AnchoredPositionY - Offset) < 5) { OnPageIndexChanged?.Invoke(TargetIndex_); AnchoredPositionY = Offset; TargetIndex_ = -1; } SetContentAnchoredPosition(new Vector2(Content.anchoredPosition.x, AnchoredPositionY)); PrevPosition_ = Content.anchoredPosition; } else { base.LateUpdate(); } }
/// <summary> /// 设置页索引 /// </summary> /// <param name="index">索引</param> public void SetPageIndex(int index) { if (m_PageIndex != index) { ResetPage(m_PageIndex); int old = m_PageIndex; m_PageIndex = index; ResetAllActionState(); OnPageIndexChangePre?.Invoke(old, m_PageIndex); OnPageIndexChanged?.Invoke(old, m_PageIndex); } }
protected override void FillItemList() { base.FillItemList(); OnPageIndexChanged?.Invoke(CurrentIndex_); }