summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/SlideBar.cs
blob: da36f580b65fd2bfbb1d7eb53af0bc696ab63859 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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<PassiveButtonManager>.Instance.Controller.CheckDrag(this.HitBox, false))
		{
		case DragState.Dragging:
		{
			Vector2 vector = DestroyableSingleton<PassiveButtonManager>.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;
	}
}