-
Notifications
You must be signed in to change notification settings - Fork 1
/
Transition.cs
58 lines (52 loc) · 1.6 KB
/
Transition.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
/* Copyright (c) 2018-2024 Nuno Fachada and contributors
* Distributed under the MIT License (See accompanying file LICENSE or copy
* at http://opensource.org/licenses/MIT) */
using System;
namespace LibGameAI.FSMs
{
/// <summary>
/// A transition between states.
/// </summary>
public class Transition
{
/// <summary>
/// Actions associated with this transition.
/// </summary>
public Action Actions { get; }
/// <summary>
/// Target state for this transition.
/// </summary>
public State TargetState { get; }
// The condition for triggering this transition
private Func<bool> condition;
/// <summary>
/// Is this transition triggered?
/// </summary>
/// <returns>
/// <c>true</c> if transition is triggered, <c>false</c> otherwise.
/// </returns>
public bool IsTriggered()
{
return condition();
}
/// <summary>
/// Create a new transition.
/// </summary>
/// <param name="condition">
/// Condition for triggering this transition.
/// </param>
/// <param name="actions">
/// Actions associated with this transition.
/// </param>
/// <param name="targetState">
/// Target state for this transition.
/// </param>
public Transition(
Func<bool> condition, Action actions, State targetState)
{
this.condition = condition;
Actions = actions;
TargetState = targetState;
}
}
}