Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- public class CharacterFSM<Conditions>
- {
- public CharState<Conditions> currentState;
- public void Update()
- {
- currentState.OnUpdate();
- }
- public void FirstState(CharState<Conditions> first)
- {
- currentState = first;
- currentState.OnEnter();
- }
- public void Feed(Conditions cond)
- {
- CharState<Conditions> nextState = currentState.GetTransition(cond);
- if (nextState != null)
- {
- currentState.OnExit();
- currentState = nextState;
- currentState.OnEnter();
- }
- }
- public void CheckIfExists()
- {
- Debug.Log("I Exist");
- }
- }
- public class CharState<Conditions>
- {
- public string name;
- public CharacterBase myself;
- public Action OnEnter = delegate { };
- public Action OnUpdate = delegate { };
- public Action OnExit = delegate { };
- private Dictionary<Conditions, CharState<Conditions>> transitions = new Dictionary<Conditions, CharState<Conditions>>();
- public CharState(string name, CharacterBase self)
- {
- this.name = name;
- }
- public CharState<Conditions> GetTransition(Conditions cond)
- {
- if (transitions.ContainsKey(cond))
- {
- Debug.Log(transitions[cond].name);
- return transitions[cond];
- }
- else Debug.Log("no hay transition");
- return null;
- }
- public void AddTransition(Conditions cond, CharState<Conditions> next)
- {
- transitions[cond] = next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement