Skip to content

Commit 3f788cb

Browse files
committed
bug fix
1 parent e99595c commit 3f788cb

File tree

10 files changed

+1498
-11
lines changed

10 files changed

+1498
-11
lines changed

Example.meta

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

Example/ExampleState.cs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using Cysharp.Threading.Tasks;
2+
using LD.StateMachine;
3+
using UnityEngine;
4+
5+
namespace com.shlifedev.framework.scripts.core.ai.fsm.AsyncFSM.Example
6+
{
7+
public abstract class ExampleState : StateBase<int>
8+
{
9+
protected readonly ExampleView View;
10+
11+
public ExampleState(ExampleView view)
12+
{
13+
View = view;
14+
}
15+
public override UniTask OnStateEnter()
16+
{
17+
return UniTask.CompletedTask;
18+
}
19+
20+
public override UniTask OnStateUpdate()
21+
{
22+
return UniTask.CompletedTask;
23+
}
24+
25+
public override UniTask OnStateExit()
26+
{
27+
return UniTask.CompletedTask;
28+
}
29+
}
30+
31+
public class ExampleStateA : ExampleState
32+
{
33+
public override async UniTask OnStateEnter()
34+
{
35+
36+
37+
View.ViewA.Img.color = Color.green;
38+
View.ViewA.State.text = $"Enter!";
39+
40+
await UniTask.Delay(1000);
41+
}
42+
43+
public override UniTask OnStateUpdate()
44+
{
45+
View.ViewA.Img.color = Color.yellow;
46+
View.ViewA.State.text = $"Update . . .";
47+
return UniTask.CompletedTask;;
48+
}
49+
50+
public override async UniTask OnStateExit()
51+
{
52+
View.ViewA.Img.color = Color.black;
53+
for (int i = 100; i >= 0; i--)
54+
{
55+
await UniTask.Delay(1);
56+
View.ViewA.State.text = $"Exiting, Please Wait.. {i}";
57+
}
58+
59+
View.ViewA.Img.color = Color.red;
60+
61+
}
62+
63+
public ExampleStateA(ExampleView view) : base(view)
64+
{
65+
}
66+
}
67+
68+
public class ExampleStateB : ExampleState
69+
{
70+
public override async UniTask OnStateEnter()
71+
{
72+
View.ViewB.Img.color = Color.green;
73+
View.ViewB.State.text = $"Enter!";
74+
await UniTask.Delay(1000);
75+
}
76+
77+
public override UniTask OnStateUpdate()
78+
{
79+
80+
View.ViewB.Img.color = Color.yellow;
81+
View.ViewB.State.text = $"Update . . .";
82+
Debug.Log("KK");
83+
return UniTask.CompletedTask;;
84+
}
85+
86+
public override async UniTask OnStateExit()
87+
{
88+
View.ViewB.Img.color = Color.black;
89+
for (int i = 100; i >= 0; i--)
90+
{
91+
await UniTask.Delay(1);
92+
View.ViewB.State.text = $"Exiting, Please Wait.. {i}";
93+
}
94+
View.ViewB.Img.color = Color.red;
95+
}
96+
97+
public ExampleStateB(ExampleView view) : base(view)
98+
{
99+
}
100+
}
101+
102+
}

Example/ExampleState.cs.meta

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

Example/ExampleView.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using LD.StateMachine;
3+
using TMPro;
4+
using UnityEngine;
5+
using UnityEngine.UI;
6+
7+
namespace com.shlifedev.framework.scripts.core.ai.fsm.AsyncFSM.Example
8+
{
9+
public class ExampleView : MonoBehaviour
10+
{
11+
public AsyncStateMachine<int> fsm;
12+
public StateViewer ViewA, ViewB;
13+
public Button Change;
14+
private void Awake()
15+
{
16+
fsm = new AsyncStateMachine<int>(this);
17+
fsm.Add(0, new ExampleStateA(this));
18+
fsm.Add(1, new ExampleStateB(this));
19+
fsm.InitializeAndStartLoopAsync(0);
20+
21+
Change.onClick.AddListener(async () =>
22+
{
23+
if (fsm.CurState == 0)
24+
{
25+
await fsm.ChangeStateAsync(1);
26+
}
27+
else
28+
{
29+
await fsm.ChangeStateAsync(0);
30+
}
31+
});
32+
}
33+
}
34+
}

Example/ExampleView.cs.meta

Lines changed: 3 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)