diff --git a/.idea/.idea.SpringJam2026/.idea/workspace.xml b/.idea/.idea.SpringJam2026/.idea/workspace.xml index 232051c..03da7ee 100644 --- a/.idea/.idea.SpringJam2026/.idea/workspace.xml +++ b/.idea/.idea.SpringJam2026/.idea/workspace.xml @@ -5,9 +5,7 @@ - - - + diff --git a/Assets/Scripts/State.meta b/Assets/Scripts/State.meta new file mode 100644 index 0000000..3d13d18 --- /dev/null +++ b/Assets/Scripts/State.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 67f88045e5c39dd42af3559790c4c117 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/State/GameState.cs b/Assets/Scripts/State/GameState.cs new file mode 100644 index 0000000..46d3300 --- /dev/null +++ b/Assets/Scripts/State/GameState.cs @@ -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) {} + } +} diff --git a/Assets/Scripts/State/GameState.cs.meta b/Assets/Scripts/State/GameState.cs.meta new file mode 100644 index 0000000..ae58e8e --- /dev/null +++ b/Assets/Scripts/State/GameState.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: aece5e36c5691b84592b559518dc979c \ No newline at end of file diff --git a/Assets/Scripts/State/Machine.cs b/Assets/Scripts/State/Machine.cs new file mode 100644 index 0000000..b28ffea --- /dev/null +++ b/Assets/Scripts/State/Machine.cs @@ -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); + } + } +} diff --git a/Assets/Scripts/State/Machine.cs.meta b/Assets/Scripts/State/Machine.cs.meta new file mode 100644 index 0000000..9cf93a7 --- /dev/null +++ b/Assets/Scripts/State/Machine.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: c58c43f9d69af404f997461c6348049d \ No newline at end of file