- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace MyCollections.AI.FinitStateMachine
- {
- [CreateAssetMenu(menuName = "Finite State Machine/State")]
- public class State : ScriptableObject
- {
- [SerializeField] private List<Action> entryActions;
- [SerializeField] private List<Action> actions;
- [SerializeField] private List<Transition> transitions = new List<Transition>();
- [SerializeField] private Action exitAction;
- public List<Action> GetentryActions() => entryActions;
- public List<Action> GetActions() => actions;
- public List<Transition> GetTransitions() => transitions;
- public Action GetExitAction() => exitAction;
-
- public virtual void StartState()
- {
- }
-
- public void EnterState(FSM fsm)
- {
- StartState();
- if (entryActions.Count > 0)
- {
- foreach (Action action in entryActions)
- {
- action.Run(fsm);
- }
- }
- }
-
- public Transition GetTriggeredTransition(FSM fsm)
- {
- if (transitions.Count > 0)
- {
- foreach (Transition transition in transitions)
- {
-
- if (transition.IsTriggered(fsm))
- {
- return transition;
- }
- }
- }
- return null;
- }
- }
- }