-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStateBase.cs
31 lines (28 loc) · 847 Bytes
/
StateBase.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
using System;
namespace Game.FSM
{
/// <summary>
/// Base class for states.
/// </summary>
public abstract class StateBase : StateContext, IState
{
/// <inheritdoc/>
public abstract void Enter();
/// <inheritdoc/>
public abstract void Exit();
/// <inheritdoc/>
public override bool TriggerEvent<T>(T stateEvent, bool allowTransition = true)
{
bool isHandled = base.TriggerEvent(stateEvent, allowTransition);
if (!isHandled && this is IEventHandler<T> eventHandler)
{
isHandled = eventHandler.HandleEvent(stateEvent);
if (allowTransition && ExecuteNextTransition())
{
isHandled = true;
}
}
return isHandled;
}
}
}