using System.Collections; using System.Collections.Generic; namespace EnemyAI { public class BehaviorController { public Blackboard blackboard; internal enum Behaviors { RechargeBehavior, ChaseBehavior } private Behaviors currentBehavior; Dictionary allBehaviors = new Dictionary(); public BehaviorController() { blackboard = new Blackboard(); allBehaviors.Add(Behaviors.RechargeBehavior, new RechargeBehavior()); allBehaviors.Add(Behaviors.ChaseBehavior, new ChaseBehavior()); currentBehavior = Behaviors.RechargeBehavior; } public void Update() { EnemyAI.Result result = allBehaviors[currentBehavior].Run(ref blackboard); if (result != Result.Running) { switch (currentBehavior) { case Behaviors.RechargeBehavior: switch (result) { case Result.Success: currentBehavior = Behaviors.ChaseBehavior; break; case Result.Failure: break; } break; case Behaviors.ChaseBehavior: switch (result) { case Result.Success: break; case Result.Failure: currentBehavior = Behaviors.RechargeBehavior; break; } break; } } } } }