-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseLayeredPanelController.cs
More file actions
68 lines (55 loc) · 1.99 KB
/
Copy pathBaseLayeredPanelController.cs
File metadata and controls
68 lines (55 loc) · 1.99 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
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.UIElements;
using Utils;
namespace Services.UIToolkitLayeredService
{
public abstract class BaseLayeredPanelController
{
private VisualTreeAsset _asset;
protected VisualElement _root;
public VisualTreeAsset Asset => _asset;
public VisualElement Root => _root;
protected abstract string GetPath();
protected abstract void Setup();
public VisualElement Open()
{
_root = Resources.Load<VisualTreeAsset>(GetPath()).Instantiate();
_root.style.width = new StyleLength(new Length(100, LengthUnit.Percent));
_root.style.height = new StyleLength(new Length(100, LengthUnit.Percent));
Vector2 fromScale = Vector2.one * 1.2f;
LerpUtils.LerpVector2(fromScale, Vector2.one, .2f, scaleStep =>
{
_root.style.scale = new StyleScale(scaleStep);
return scaleStep;
}).Forget();
LerpUtils.LerpFloat(0, 1, .2f, fadeStep =>
{
_root.style.opacity = fadeStep;
return fadeStep;
}).Forget();
Setup();
return _root;
}
public void FadeOut(Action onComplete)
{
Vector2 toScale = Vector2.one * 1.2f;
LerpUtils.LerpVector2(Vector2.one, toScale, .2f, scaleStep =>
{
if (scaleStep.x >= toScale.x)
{
onComplete?.Invoke();
return scaleStep;
}
_root.style.scale = new StyleScale(scaleStep);
return scaleStep;
}).Forget();
LerpUtils.LerpFloat(1, 0, .2f, fadeStep =>
{
_root.style.opacity = fadeStep;
return fadeStep;
}).Forget();
}
}
}