added state machine

This commit is contained in:
Jeremy Smitherman 2026-04-24 12:48:50 -05:00
parent 86490807d9
commit a75f8a7a6a
6 changed files with 58 additions and 5 deletions

View File

@ -5,9 +5,7 @@
</component>
<component name="ChangeListManager">
<list default="true" id="60468364-7d9c-427f-83f9-f6cd83ef8783" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/Assets/Scenes/SampleScene.unity" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scenes/SampleScene.unity.meta" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/ProjectSettings/EditorBuildSettings.asset" beforeDir="false" afterPath="$PROJECT_DIR$/ProjectSettings/EditorBuildSettings.asset" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.SpringJam2026/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.SpringJam2026/.idea/workspace.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -34,7 +32,7 @@
"ModuleVcsDetector.initialDetectionPerformed": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
"git-widget-placeholder": "feature/services",
"git-widget-placeholder": "main",
"ignore.virus.scanning.warn.message": "true",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
@ -108,7 +106,7 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1777050991106</updated>
<workItem from="1777050993247" duration="1296000" />
<workItem from="1777050993247" duration="1899000" />
</task>
<servers />
</component>

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 67f88045e5c39dd42af3559790c4c117
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
using UnityEngine;
namespace State
{
public class GameState
{
protected Machine StateMachine;
public virtual void OnEnter(Machine machine)
{
StateMachine = machine;
}
public virtual void OnExit() {}
public virtual void OnUpdate(float deltaTime) {}
public virtual void OnFixedUpdate(float deltaTime) {}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: aece5e36c5691b84592b559518dc979c

View File

@ -0,0 +1,26 @@
using UnityEngine;
namespace State
{
public class Machine : MonoBehaviour
{
private GameState _currentState;
public void Update()
{
_currentState?.OnUpdate(Time.deltaTime);
}
public void FixedUpdate()
{
_currentState?.OnFixedUpdate(Time.fixedDeltaTime);
}
public void ChangeState(GameState newState)
{
_currentState?.OnExit();
_currentState = newState;
_currentState.OnEnter(this);
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c58c43f9d69af404f997461c6348049d