private void CreatePerformActionState() { _performState = (fsm, gameObject) => { Debug.Log("Performing --"); // Perform the action if (!HasActionPlan()) { // no actions left _fsm.PopState(); _fsm.PushState(_idleState); _dataProvider.ActionsCompleted(); return; } var action = _currentActions.Peek(); if (action.IsDone()) { // action completed, remove and continue w/ sequence _currentActions.Dequeue(); } if (HasActionPlan()) { action = _currentActions.Peek(); bool inRange = !action.RequiresInRange || action.IsInRange; if (inRange) { bool actionSuccess = action.Perform(gameObject); if (!actionSuccess) { // action failed, plan again _fsm.PopState(); _fsm.PushState(_idleState); _dataProvider.PlanAborted(action); } } else { // we ened to move there first? // what? _fsm.PushState(_moveState); } } else { // no actions left _fsm.PopState(); _fsm.PushState(_idleState); _dataProvider.ActionsCompleted(); } }; }