-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVerticalScrollBar.cs
More file actions
55 lines (46 loc) · 1.6 KB
/
VerticalScrollBar.cs
File metadata and controls
55 lines (46 loc) · 1.6 KB
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
using UnityEngine;
namespace Agricosmic.Utilities
{
/// <summary>
/// DEPRECATED - Moves its parent based on its vertical position
/// <br/>
/// TODO: @xavier needs rework :)
/// </summary>
public class VerticalScrollBar : MonoBehaviour
{
[SerializeField] private float _maxY;
[SerializeField] private float _minY;
private bool _isClicked = false;
private int _numSlotsUp;
private float _percentOnY = 0;
public float GetBarPercent() => _percentOnY;
public bool IsClicked() => _isClicked;
private void Update()
{
Vector3 localMousePosition = transform.parent.InverseTransformPoint(Input.mousePosition);
if (localMousePosition.y > _minY && localMousePosition.y < _maxY && _isClicked)
{
transform.localPosition = new Vector2(transform.localPosition.x, localMousePosition.y);
_percentOnY = (_maxY - localMousePosition.y) / (_maxY - _minY);
}
if (localMousePosition.y < _minY && _isClicked)
{
transform.localPosition = new Vector2(transform.localPosition.x, _minY);
_percentOnY = 1;
}
if (localMousePosition.y > _maxY && _isClicked)
{
transform.localPosition = new Vector2(transform.localPosition.x, _maxY);
_percentOnY = 0;
}
}
private void OnMouseUp()
{
_isClicked = false;
}
private void OnMouseDown()
{
_isClicked = true;
}
}
};