public void Update() { if (this._finishInit) { if (this._indexToChildDict.ContainsValue(null)) { this.Setup(); } float verticalNormalizedPosition = this._scroller.verticalNormalizedPosition; if (this.state == MonoChapterScroller.State.Swipe) { float f = (this.moveType != MonoChapterScroller.Movement.Horizontal) ? this._scroller.velocity.y : this._scroller.velocity.x; if (Mathf.Abs(f) < this.stopSwipeSpeedThreshold) { this.state = MonoChapterScroller.State.Lerp; } } if ((this.state == MonoChapterScroller.State.Lerp) || (this.state == MonoChapterScroller.State.ClickLerp)) { float b = this.CalculateCenterNormalizedPos(this.centerIndex); verticalNormalizedPosition = !this.driveByOutside ? Mathf.Lerp(this._scroller.verticalNormalizedPosition, b, Time.deltaTime * 5f) : this._scroller.verticalNormalizedPosition; this._scroller.verticalNormalizedPosition = verticalNormalizedPosition; if (Mathf.Approximately(b, verticalNormalizedPosition)) { this.OnEndLerp(); } } if (((this.boundScroller != null) && this.boundScroller.driveByOutside) && !this.driveByOutside) { this.boundScroller.SetNormalizePositionY(this._scroller.verticalNormalizedPosition); } } }
public void Setup() { this._childIndexDict = new Dictionary <Transform, int>(); this._indexToChildDict = new Dictionary <int, Transform>(); int num = 0; IEnumerator enumerator = this._contentTrans.GetEnumerator(); try { while (enumerator.MoveNext()) { Transform current = (Transform)enumerator.Current; if (current.GetComponent <MonoItemStatus>().isValid) { this._childIndexDict.Add(current, num); this._indexToChildDict.Add(num, current); num++; } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable == null) { } disposable.Dispose(); } this._selectedOffset = (1f / (this._childNum - 1f)) / 2f; this.UpdateContent(); this.state = MonoChapterScroller.State.Lerp; }
public void ClickToChangeCenter(Transform child) { this.centerIndex = this._childIndexDict[child]; this.state = MonoChapterScroller.State.ClickLerp; if (this.boundScroller != null) { this.boundScroller.driveByOutside = true; this.boundScroller.state = MonoChapterScroller.State.ClickLerp; this.boundScroller.centerIndex = this.centerIndex; this.driveByOutside = false; } }
public virtual void OnEndLerp() { this.state = MonoChapterScroller.State.Idle; if (this.boundScroller != null) { this.boundScroller.driveByOutside = false; } if (this._onLerpEndCallBack != null) { this._onLerpEndCallBack(); } this._scroller.velocity = Vector2.zero; }
public virtual void OnValueChanged(Vector2 normalizedPos) { float f = (this.moveType != MonoChapterScroller.Movement.Horizontal) ? this._scroller.velocity.y : this._scroller.velocity.x; if ((this.state == MonoChapterScroller.State.Swipe) && (Mathf.Abs(f) < this.stopSwipeSpeedThreshold)) { this.state = MonoChapterScroller.State.Lerp; } for (int i = 0; i < this._childNum; i++) { float distance = this.CalcualteCenterDistance(i); this.SetUpChildView(this._indexToChildDict[i], distance); if ((distance <= this._selectedOffset) && (this.state != MonoChapterScroller.State.ClickLerp)) { this.centerIndex = i; } } }
public void OnBeginDrag(PointerEventData eventData) { this.state = MonoChapterScroller.State.Drag; this.driveByOutside = false; if (this.boundScroller != null) { this.boundScroller.driveByOutside = true; this.boundScroller.state = MonoChapterScroller.State.Drag; } this._originalCenterIndex = this.centerIndex; this._dragDelta = 0f; if (this.moveType == MonoChapterScroller.Movement.Horizontal) { this._dragDelta += eventData.delta.x; } else { this._dragDelta += eventData.delta.y; } }