-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathShowHideGroup.cs
More file actions
47 lines (44 loc) · 1.04 KB
/
ShowHideGroup.cs
File metadata and controls
47 lines (44 loc) · 1.04 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
using UnityEngine;
[RequireComponent(typeof(CanvasGroup))]
public class ShowHideGroup : MonoBehaviour
{
[SerializeField]
private float fadeTime = 1f;
[SerializeField]
private bool stateOnAwake;
private CanvasGroup _group;
private bool _isVisible;
private void Awake()
{
_group = GetComponent<CanvasGroup>();
_isVisible = stateOnAwake;
_group.alpha = stateOnAwake ? 1f : 0f;
}
public void On()
{
if (_isVisible) return;
_isVisible = true;
_group.interactable = true;
_group.blocksRaycasts = true;
Wrj.Utils.MapToCurve.Linear.FadeAlpha(_group, 1f, fadeTime);
}
public void Off()
{
if (!_isVisible) return;
_isVisible = false;
_group.interactable = false;
_group.blocksRaycasts = false;
Wrj.Utils.MapToCurve.Linear.FadeAlpha(_group, 0f, fadeTime);
}
public void Toggle()
{
if (_isVisible)
{
Off();
}
else
{
On();
}
}
}