-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathTest.cs
65 lines (56 loc) · 1.8 KB
/
Test.cs
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
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using zFrame.Event;
public class Test : MonoBehaviour
{
public Animator animator;
public Button button;
public Text text, text2;
public int delay = 5;
float countcached = 0;
private bool isCounting = false;
EventState callbackExp, callbackClps;
void Start()
{
button.onClick.AddListener(OnButtonClicked);
text.text = "expand";
}
private void Update()
{
if (isCounting)
{
countcached += Time.deltaTime;
text2.text = countcached.ToString("f0");
}
}
private async void OnButtonClicked()
{
// 等待折叠
{
button.interactable = false;
Debug.Log($"{nameof(Test)}: Default is expand , Now start collapse!");
var r = await animator.SetBoolAsync("Expand","Expand", false); // todo: 必须细分到 layer.state 这种级别,否则误触会很伤
Debug.Log($"{nameof(Test)}: collapse Completed , clip name = {r.animatorClipInfo.clip.name}!");
text.text = "collapsed";
}
//做一个延迟
{
Debug.Log($"{nameof(Test)}: wait for {delay} second!");
isCounting = true;
await Task.Delay(delay * 1000);
isCounting = false;
countcached = 0;
text2.text = string.Empty;
Debug.Log($"{nameof(Test)}: waiting finish!");
}
// 等待展开
{
Debug.Log($"{nameof(Test)}: Now is collapse , expanding !");
await animator.SetBoolAsync("Expand", "Expand", true);
text.text = "expand";
Debug.Log($"{nameof(Test)}: expand Completed!");
button.interactable = true;
}
}
}