From e9ea621b93fbb58d9edfca8375918791637bbd52 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 30 Dec 2020 20:59:04 +0800 Subject: +init --- Client/Assembly-CSharp/SlideBar.cs | 78 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Client/Assembly-CSharp/SlideBar.cs (limited to 'Client/Assembly-CSharp/SlideBar.cs') diff --git a/Client/Assembly-CSharp/SlideBar.cs b/Client/Assembly-CSharp/SlideBar.cs new file mode 100644 index 0000000..da36f58 --- /dev/null +++ b/Client/Assembly-CSharp/SlideBar.cs @@ -0,0 +1,78 @@ +using System; +using UnityEngine; +using UnityEngine.Events; + +public class SlideBar : MonoBehaviour +{ + public TextRenderer Title; + + public SpriteRenderer Bar; + + public Collider2D HitBox; + + public SpriteRenderer Dot; + + public FloatRange Range; + + public bool Vertical; + + public float Value; + + public UnityEvent OnValueChange; + + public void OnEnable() + { + if (this.Title) + { + this.Title.Color = Color.white; + } + this.Bar.color = Color.white; + this.Dot.color = Color.white; + } + + public void OnDisable() + { + if (this.Title) + { + this.Title.Color = Color.gray; + } + this.Bar.color = Color.gray; + this.Dot.color = Color.gray; + } + + public void Update() + { + Vector3 localPosition = this.Dot.transform.localPosition; + switch (DestroyableSingleton.Instance.Controller.CheckDrag(this.HitBox, false)) + { + case DragState.Dragging: + { + Vector2 vector = DestroyableSingleton.Instance.Controller.DragPosition - this.Bar.transform.position; + if (this.Vertical) + { + localPosition.y = this.Range.Clamp(vector.y); + this.Value = this.Range.ReverseLerp(localPosition.y); + } + else + { + localPosition.x = this.Range.Clamp(vector.x); + this.Value = this.Range.ReverseLerp(localPosition.x); + } + this.OnValueChange.Invoke(); + break; + } + case DragState.Released: + this.OnValueChange.Invoke(); + break; + } + if (this.Vertical) + { + localPosition.y = this.Range.Lerp(this.Value); + } + else + { + localPosition.x = this.Range.Lerp(this.Value); + } + this.Dot.transform.localPosition = localPosition; + } +} -- cgit v1.1-26-g67d0