void UpdatePosition() { if (!this.mNeedUpdate) { return; } if (this.mPressTouch == null && !this.Approximately(this.mLastDelta, Vector3.zero)) { this.mLastDelta *= this.inertia; this.mLastDelta = this.AdjustDeltaInRange(this.mLastDelta); this.mDestination += this.mLastDelta; } Vector3 force = XMath.Elastic(this.mDestination, this.itemRoot.localPosition, this.dragForce, 0, 0); if (Mathf.Approximately(force.sqrMagnitude, 0)) { this.mNeedUpdate = false; } this.AddForce(force); }
void LayoutItems(bool kinematic) { if (!this.mNeedLayout) { return; } bool completed = true; Vector3 pos = Vector3.zero; this.mHead.transform.localPosition = pos; for (int i = 0; i < this.mItems.Count; i++) { var cur = this.mItems[i]; var curpos = cur.localPosition; pos += this.mDirection * cur.radius; if (kinematic) { cur.transform.localPosition = pos; } else if (!this.Approximately(curpos, pos)) { completed = false; Vector3 force = XMath.Elastic(pos, curpos, this.resilence, 0, 0); this.AddForce(cur, force); } pos += this.mDirection * cur.radius; } this.mTail.transform.localPosition = pos; if (completed) { this.mNeedLayout = false; } }
void AdjustPositionInRange() { if (this.mItems.Count == 0) { return; } Vector3 head = this.transform.InverseTransformPoint(this.mHead.position); Vector3 tail = this.transform.InverseTransformPoint(this.mTail.position); Vector3 min = this.transform.InverseTransformPoint(this.min.position); Vector3 max = this.transform.InverseTransformPoint(this.max.position); if (this.mHead == this.mTail) { this.mNeedUpdate = false; Vector3 force = XMath.Elastic(min, head, this.resilence, 0, 0); this.AddForce(force); return; } Vector3 min_head = head - min; Vector3 max_tail = tail - max; bool head_force = min_head.sqrMagnitude > 0.01f && Vector3.Angle(min_head, this.mDirection) <= 90; bool tail_force = max_tail.sqrMagnitude > 0.01f && Vector3.Angle(max_tail, this.mDirection) > 90; if (!head_force && !tail_force) { return; } this.mNeedUpdate = false; if (head_force != tail_force) { Vector3 min_max = max - min; Vector3 head_tail = tail - head; if (head_tail.sqrMagnitude > min_max.sqrMagnitude) { if (head_force) { Vector3 force = XMath.Elastic(min, head, this.resilence, 0, 0); this.AddForce(force); } else if (tail_force) { Vector3 force = XMath.Elastic(max, tail, this.resilence, 0, 0); this.AddForce(force); } } else { if (head_force) { Vector3 force = XMath.Elastic(min, head, this.resilence, 0, 0); this.AddForce(force); } } } else { Vector3 force = XMath.Elastic(min, head, this.resilence, 0, 0); this.AddForce(force); } }