Skip to content

Commit 2ed1198

Browse files
committed
fix WaitCommand
1 parent 7b31d7a commit 2ed1198

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

Assets/CatCode/Commands/WaitCommand.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,14 @@ private async Awaitable WaitAsync()
3737
{ }
3838
finally
3939
{
40-
_cts.Dispose();
40+
_cts?.Dispose();
4141
_cts = null;
4242
}
4343
}
4444

4545
private void Cancel()
46-
{
47-
if (_cts == null)
48-
return;
49-
_cts.Cancel();
50-
_cts.Dispose();
51-
_cts = null;
46+
{
47+
_cts?.Cancel();
5248
}
5349
}
5450
}

Assets/CommandTester.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using CatCode.Commands;
2+
using UnityEngine;
3+
4+
public class CommandTester : MonoBehaviour
5+
{
6+
[SerializeField] private WaitCommand _command;
7+
8+
private void Awake()
9+
{
10+
_command = new WaitCommand(5)
11+
.AddOnStarted(() => Debug.Log("Started"))
12+
.AddOnFinished(() => Debug.Log("Finished"))
13+
.AddOnStopped(() => Debug.Log("Stopped"));
14+
}
15+
private void OnEnable()
16+
{
17+
_command.Execute();
18+
}
19+
20+
private void OnDisable()
21+
{
22+
_command.Stop();
23+
}
24+
}

Assets/CommandTester.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)