Skip to content

Nested state machine2 #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1eeda163c70b3cb4ebb88ba92f608fd8, type: 3}
m_Name:
m_EditorClassIdentifier:
_transitionTableSO: {fileID: 11400000, guid: c106e88137c90384bb4b18ba46869b64, type: 2}
_transitionTableSO: {fileID: 11400000, guid: 97384f5b5a9cc0e47aaff3a52d666851, type: 2}
_debugger:
debugTransitions: 0
appendConditionsInfo: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3f0633ea79d4a789da71a1872f069ec5, type: 3}
m_Name: RoamingStateMachine
m_EditorClassIdentifier:
_transitionTableSO: {fileID: 11400000, guid: 78d9b7ea1925a748c89267477d971b09, type: 2}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 872cbaa965d1f6e4e98365d74e2060df, type: 3}
m_Name: RoamingTable
m_EditorClassIdentifier:
_transitions:
- FromState: {fileID: 11400000, guid: 0fe0dc68c0fc2604ca06ad36d16b1117, type: 2}
ToState: {fileID: 11400000, guid: 4b41f0e0e0982384b8f7a718509ea3a9, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 6519cfc02b3c6c34d8607ac0645ef287, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 4b41f0e0e0982384b8f7a718509ea3a9, type: 2}
ToState: {fileID: 11400000, guid: 0fe0dc68c0fc2604ca06ad36d16b1117, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 822af955c346ff5429598d4280c5ba73, type: 2}
Operator: 0

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 872cbaa965d1f6e4e98365d74e2060df, type: 3}
m_Name: SlimeRockCritter_Simplified_TransitionTable
m_EditorClassIdentifier:
_transitions:
- FromState: {fileID: 11400000, guid: 58ed5fdf35d804093aa322bf33a82f30, type: 2}
ToState: {fileID: 11400000, guid: ea7a8e48b1a87c241bb721da98d1d812, type: 2}
Conditions:
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: 72dd7a9972bd3614ead2fd62cebc6144, type: 2}
Operator: 0
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 27c06ead5f7a1ed4d89197fe9a61d0c2, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: ea7a8e48b1a87c241bb721da98d1d812, type: 2}
ToState: {fileID: 11400000, guid: 5b0e38103a74c054cb968153b3227b71, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 1ff6d66c9ad367543beb3f2455a1d06c, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: ea7a8e48b1a87c241bb721da98d1d812, type: 2}
ToState: {fileID: 11400000, guid: 05826b0374eccc245b9b1da390ab7d04, type: 2}
Conditions:
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: 72dd7a9972bd3614ead2fd62cebc6144, type: 2}
Operator: 0
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 3d30788033cfd9d4fa24fa5112d9430c, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 05826b0374eccc245b9b1da390ab7d04, type: 2}
ToState: {fileID: 11400000, guid: ea7a8e48b1a87c241bb721da98d1d812, type: 2}
Conditions:
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: 3d30788033cfd9d4fa24fa5112d9430c, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 05826b0374eccc245b9b1da390ab7d04, type: 2}
ToState: {fileID: 11400000, guid: 0fe9688a46e58a24d8a88cd363a8e472, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 5d0cf556c54f5154a9edc595f1958590, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 0fe9688a46e58a24d8a88cd363a8e472, type: 2}
ToState: {fileID: 11400000, guid: 5b0e38103a74c054cb968153b3227b71, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 1ff6d66c9ad367543beb3f2455a1d06c, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 0fe9688a46e58a24d8a88cd363a8e472, type: 2}
ToState: {fileID: 11400000, guid: 658f06f54a3654c498a26d9714beaff0, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 8d78c6cbad5610342b28e8f66a8a9d11, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 628073f665cfda9468013b5ecbc7e6c3, type: 2}
ToState: {fileID: 11400000, guid: f4a07080dd036db4392317bdcd3c20b4, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: c06b3d79b9eb00344825524cd0f6091a, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 5b0e38103a74c054cb968153b3227b71, type: 2}
ToState: {fileID: 11400000, guid: ea7a8e48b1a87c241bb721da98d1d812, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: b5098991df6fea14294cbd13e586cfd8, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 05826b0374eccc245b9b1da390ab7d04, type: 2}
ToState: {fileID: 11400000, guid: 5b0e38103a74c054cb968153b3227b71, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 1ff6d66c9ad367543beb3f2455a1d06c, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 5b0e38103a74c054cb968153b3227b71, type: 2}
ToState: {fileID: 11400000, guid: 05826b0374eccc245b9b1da390ab7d04, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: b5098991df6fea14294cbd13e586cfd8, type: 2}
Operator: 0
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 3d30788033cfd9d4fa24fa5112d9430c, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 05826b0374eccc245b9b1da390ab7d04, type: 2}
ToState: {fileID: 11400000, guid: 628073f665cfda9468013b5ecbc7e6c3, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: fa8a674126a68004888ee6cef86cb5f5, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 5b0e38103a74c054cb968153b3227b71, type: 2}
ToState: {fileID: 11400000, guid: 628073f665cfda9468013b5ecbc7e6c3, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: fa8a674126a68004888ee6cef86cb5f5, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 658f06f54a3654c498a26d9714beaff0, type: 2}
ToState: {fileID: 11400000, guid: 05826b0374eccc245b9b1da390ab7d04, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 8f1dae963c547274b808dd5db78a28e3, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 658f06f54a3654c498a26d9714beaff0, type: 2}
ToState: {fileID: 11400000, guid: 5b0e38103a74c054cb968153b3227b71, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 1ff6d66c9ad367543beb3f2455a1d06c, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 658f06f54a3654c498a26d9714beaff0, type: 2}
ToState: {fileID: 11400000, guid: 628073f665cfda9468013b5ecbc7e6c3, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: fa8a674126a68004888ee6cef86cb5f5, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: ea7a8e48b1a87c241bb721da98d1d812, type: 2}
ToState: {fileID: 11400000, guid: 58ed5fdf35d804093aa322bf33a82f30, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 72dd7a9972bd3614ead2fd62cebc6144, type: 2}
Operator: 1
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: 27c06ead5f7a1ed4d89197fe9a61d0c2, type: 2}
Operator: 0

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ MonoBehaviour:
- FromState: {fileID: 11400000, guid: 4b41f0e0e0982384b8f7a718509ea3a9, type: 2}
ToState: {fileID: 11400000, guid: ea7a8e48b1a87c241bb721da98d1d812, type: 2}
Conditions:
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: 72dd7a9972bd3614ead2fd62cebc6144, type: 2}
Operator: 0
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 27c06ead5f7a1ed4d89197fe9a61d0c2, type: 2}
Operator: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 35432205b9a6a374bbbfe6b7cac92179, type: 3}
m_Name: Roaming
m_Name: RoamingMove
m_EditorClassIdentifier:
_actions:
- {fileID: 11400000, guid: 46af8bb2ed6efed4ab26d05dfc1b560f, type: 2}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 35432205b9a6a374bbbfe6b7cac92179, type: 3}
m_Name: RoamingState
m_EditorClassIdentifier:
_actions:
- {fileID: 11400000, guid: c7c61620b878156d0be2d17161a60f6d, type: 2}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace UOP1.StateMachine.ScriptableObjects
{
using UnityEngine;
using UOP1.StateMachine;
using System;
using System.Collections.Generic;

[CreateAssetMenu(fileName = "StateMachineAction", menuName = "State Machines/Actions/StateMachine")]
public class StateMachineActionSO : StateActionSO<StateMachineAction>
{
[Tooltip("Set the initial state of this StateMachine")]
public TransitionTableSO _transitionTableSO = default;
}

public class StateMachineAction : StateAction
{
private new StateMachineActionSO _originSO => (StateMachineActionSO)base.OriginSO; // The SO this StateAction spawned from
private readonly Dictionary<Type, Component> _cachedComponents = new Dictionary<Type, Component>();
internal State _currentState;

private StateMachine _parentStateMachine = default;
private State _initialState = default;

public override void Awake(StateMachine stateMachine)
{
_parentStateMachine = stateMachine;
_initialState = _originSO._transitionTableSO.GetInitialState(stateMachine);
}

public override void OnStateEnter()
{
_currentState = _initialState;
_currentState.OnStateEnter();
}

public override void OnUpdate()
{
if (_currentState.TryGetTransition(out var transitionState))
Transition(transitionState);

_currentState.OnUpdate();
}

public override void OnStateExit()
{
_currentState.OnStateExit();
}

private void Transition(State transitionState)
{
_currentState.OnStateExit();
_currentState = transitionState;
_currentState.OnStateEnter();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.