diff --git a/Tests/TestParallelStates.cs b/Tests/TestParallelStates.cs index 87623c9..adb9b03 100644 --- a/Tests/TestParallelStates.cs +++ b/Tests/TestParallelStates.cs @@ -287,5 +287,28 @@ public void Test_ps_child_state_can_use_different_type_for_id() fsm.Init(); fsm.OnLogic(); } + + [Test] + public void Test_ps_reacts_to_global_trigger() + { + var a = new StateMachine(); + a.AddState("A"); + a.AddState("B"); + a.AddTriggerTransition("T", "A", "B"); + + var b = new StateMachine(); + b.AddState("C"); + b.AddState("D"); + b.AddTriggerTransition("T", "C", "D"); + + fsm.AddState("root", new ParallelStates(a, b)); + fsm.Init(); + + fsm.Trigger("T"); + Assert.AreEqual("B", a.ActiveStateName); + Assert.AreEqual("D", b.ActiveStateName); + + + } } } \ No newline at end of file diff --git a/src/States/ParallelStates.cs b/src/States/ParallelStates.cs index e069347..149e642 100644 --- a/src/States/ParallelStates.cs +++ b/src/States/ParallelStates.cs @@ -14,7 +14,7 @@ namespace UnityHFSM /// This will ignore the needsExitTime and StateCanExit() calls of the child states. It works the same as the /// canExit feature of the State class. /// - public class ParallelStates : StateBase, IActionable, IStateMachine + public class ParallelStates : StateBase, IActionable, IStateMachine, ITriggerable { private List> states = new List>(); @@ -185,6 +185,14 @@ public void StateCanExit() fsm.StateCanExit(); } } + + public void Trigger(TEvent trigger) + { + foreach (var state in states) + { + (state as ITriggerable)?.Trigger(trigger); + } + } public override string GetActiveHierarchyPath() {