TowerDefenseGame/Assets/Scripts/Runtime/AI/Base/StateManager.cs
Nico 719c1d0ba0 Added State Management code
Added AI code for enemies utilizing State Management
Created simple enemy prefab with the AI
2025-06-29 00:14:04 -07:00

35 lines
815 B
C#

using Unity.IO.LowLevel.Unsafe;
using UnityEngine;
namespace AI.Base {
abstract public class StateManager : MonoBehaviour {
protected IState CurrentState;
virtual protected void Update() {
CurrentState?.Tick();
IState next = GetNextState();
if (next != null && next != CurrentState) {
CurrentState.Stop();
CurrentState = next;
CurrentState.Start();
}
}
abstract protected IState GetNextState();
}
public class StateNode : ScriptableObject, IState {
protected Transform Owner;
virtual public void Initialize(Transform ownerTransform) {
Owner = ownerTransform;
}
virtual public void Start() {}
virtual public void Stop() {}
virtual public void Tick() {}
virtual public IState GetNextState() => this;
}
}