diff options
Diffstat (limited to 'Client/Assembly-CSharp/Scroller.cs')
-rw-r--r-- | Client/Assembly-CSharp/Scroller.cs | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/Scroller.cs b/Client/Assembly-CSharp/Scroller.cs new file mode 100644 index 0000000..e38a9cb --- /dev/null +++ b/Client/Assembly-CSharp/Scroller.cs @@ -0,0 +1,85 @@ +using System; +using UnityEngine; + +public class Scroller : MonoBehaviour +{ + public bool AtTop + { + get + { + return this.Inner.localPosition.y <= this.YBounds.min + 0.25f; + } + } + + public bool AtBottom + { + get + { + return this.Inner.localPosition.y >= this.YBounds.max - 0.25f; + } + } + + public Transform Inner; + + public Collider2D HitBox; + + private Controller myController = new Controller(); + + private Vector3 origin; + + public bool allowX; + + public FloatRange XBounds = new FloatRange(-10f, 10f); + + public bool allowY; + + public FloatRange YBounds = new FloatRange(-10f, 10f); + + public float YBoundPerItem; + + public void FixedUpdate() + { + if (!this.Inner) + { + return; + } + Vector2 mouseScrollDelta = Input.mouseScrollDelta; + mouseScrollDelta.y = -mouseScrollDelta.y; + this.DoScroll(this.Inner.transform.localPosition, mouseScrollDelta); + this.myController.Update(); + DragState dragState = this.myController.CheckDrag(this.HitBox, false); + if (dragState == DragState.TouchStart) + { + this.origin = this.Inner.transform.localPosition; + return; + } + if (dragState != DragState.Dragging) + { + return; + } + Vector2 del = this.myController.DragPosition - this.myController.DragStartPosition; + this.DoScroll(this.origin, del); + } + + private void DoScroll(Vector3 origin, Vector2 del) + { + if (del.magnitude < 0.05f) + { + return; + } + if (!this.allowX) + { + del.x = 0f; + } + if (!this.allowY) + { + del.y = 0f; + } + Vector3 vector = origin + del; + vector.x = this.XBounds.Clamp(vector.x); + int childCount = this.Inner.transform.childCount; + float max = Mathf.Max(this.YBounds.min, this.YBounds.max + this.YBoundPerItem * (float)childCount); + vector.y = Mathf.Clamp(vector.y, this.YBounds.min, max); + this.Inner.transform.localPosition = vector; + } +} |