private IEnumerator DoAction(GoapFsm fsm, GoapAgent agent) { if (_actions.Count > 0) { var action = _actions.Peek(); if (action.IsDone()) { agent.Effects.Add(action.EffectsAdd); agent.Effects.Remove(action.EffectsRemove); action.Exit(); fsm.Pop(); fsm.Push(_idle); _actions.Dequeue(); } else { yield return(action.Update(agent)); } } else { fsm.Pop(); fsm.Push(_idle); } }
private IEnumerator Reset(GoapFsm fsm, GoapAgent agent) { _fsm.Pop(); _fsm.Push(_idle); yield return(0); }
private IEnumerator Idle(GoapFsm fsm, GoapAgent agent) { if (_actions.Count > 0) { fsm.Pop(); var action = _actions.Peek(); if (CurrentAction != action) { CurrentAction = action; GoalActionChanged?.Invoke(); } yield return(action.CheckInRange(agent)); if (action.InRange) { action.Enter(); fsm.Push(_doAction); } else { fsm.Push(_doAction); fsm.Push(_walk); } } else { if (!_manualMode) { yield return(Planer(agent)); } else { if (CurrentAction != null) { CurrentAction = null; GoalActionChanged?.Invoke(); } yield return(0); } } }
private IEnumerator Walk(GoapFsm fsm, GoapAgent agent) { fsm.Pop(); var action = _actions.Peek(); _move.SetTarget(action.Target); while (_move.pathPending() && !agent.InterruptState) { yield return(0); } while (!_move.IsDone() && !agent.InterruptState) { _move.MoveUpdate(); yield return(0); } _move.Stop(); action.Enter(); }