/// <summary> /// Runs through and invokes every action registered to this state. /// </summary> /// <param name="controller">Controller that will be affected.</param> private void DoActions(AI_Controller controller) { for (int i = actions.Count - 1; i >= 0; i--) { actions[i].Act(controller); } }
/// <summary> /// Runs through all transitions registered and changes the calling AI's current state. /// </summary> /// <param name="controller">Controller that will be affected.</param> private void CheckTransitions(AI_Controller controller) { for (int i = transitions.Count - 1; i >= 0; i--) { if (transitions[i].Decide(controller)) { controller.ChangeState(transitions[i].TrueState); break; } else { controller.ChangeState(transitions[i].FalseState); } } }
IEnumerator WaitForTime(AI_Controller controller) { m_check.Add(controller, false); float localTimer = time + Random.Range(-(time * timeRange), time * timeRange); while (localTimer > 0f) { // When paused, wait till not pause then continue reducing yield return(new WaitUntil(CanSpawn)); localTimer -= Time.deltaTime; yield return(new WaitForEndOfFrame()); } m_check[controller] = true; }
public override bool Decide(AI_Controller controller) { // null check if (m_CanStartSpawn == null) { return(false); } if (!m_check.ContainsKey(controller)) { controller.StartCoroutine(WaitForTime(controller)); } else { if (m_check[controller]) { m_check.Remove(controller); return(true); } } return(false); }
/// <summary> /// Implements the decision that the affect the current state of an AI. /// </summary> /// <param name="controller">Return value will be determined by attributes of this controller.</param> public abstract bool Decide(AI_Controller controller);
/// <summary> /// Invokes the referenced decision. /// </summary> /// <param name="controller">Controller that is calling this function.</param> public bool Decide(AI_Controller controller) { return(decision.Decide(controller)); }
/// <summary> /// Implements the action that the AI will make. /// </summary> /// <param name="controller">Controller that will be affected by this action.</param> public abstract void Act(AI_Controller controller);
/// <summary> /// Update call to this state. /// </summary> /// <param name="controller">Controller that is calling this update.</param> public void UpdateState(AI_Controller controller) { DoActions(controller); CheckTransitions(controller); }
private bool Wait(AI_Controller controller) { time -= Time.deltaTime; return(time <= 0f); }