This merge request involves a comprehensive refactor of the existing codebase governing the artificial intelligence (AI) behaviors of in-game enemies within our Unity game. The primary objective is to enhance the flexibility and maintainability of the AI system by implementing a Hierarchical Finite State Machine (HFSM). This architectural shift allows for the seamless integration of nested states and provides access to previous states, particularly beneficial for actions requiring historical context.
## Details
### Code Modification
The primary focus of this refactor involves migrating from the current state management approach to a more sophisticated Hierarchical Finite State Machine.
Utilized the UnityHFSM library (https://github.com/Inspiaaa/UnityHFSM) as a foundational framework for building the HFSM.
#### State Machine Creation
Initialized the state machine by instantiating a StateMachine object.
```chsarp
fsm = new StateMachine();
```
#### State Addition
Added states to the state machine using the AddState method. Each state is represented by a StateBase object, allowing the utilization of built-in state classes or custom classes inheriting from StateBase for defining state logic.
```csharp
fsm.AddState(
name,
new State(
onEnter,
onLogic,
onExit
)
);
```
#### Transition Handling
Established transitions using TransitionBase objects, defining conditions for state transitions. This includes the option to use built-in transition types or create custom transition classes by inheriting from TransitionBase.
```csharp
fsm.AddTransition(new Transition(
from,
to,
condition
));
```
#### Initialization
Set the initial state and initialized the state machine to prepare for execution.
```csharp
fsm.SetStartState(id);
fsm.Init();
```
#### Executio
Integrated the state machine into the game's update loop for continuous logic processing.
```csharp
void Update() {
fsm.OnLogic();
}
```