/// <summary> /// Expands current node with given cursor. /// First enquedAction is taking place then any valid transition. /// Cursor is being transitioned to result of expansion. /// Override this for custom behavior. /// </summary> protected virtual void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet <MyStringId> enquedActions, int passThrough) { MyStateMachineTransition nextTransition; do { // Try to find best transition across enquedActions // Does not need to be evaluated one. nextTransition = null; var transitions = cursor.Node.OutTransitions; if (enquedActions.Count > 0) { int bestPriority = int.MaxValue; for (var i = 0; i < transitions.Count; i++) { int transitionPriority = transitions[i].Priority ?? int.MaxValue; if (enquedActions.Contains(transitions[i].Name) && transitionPriority <= bestPriority && (transitions[i].Conditions.Count == 0 || transitions[i].Evaluate())) { nextTransition = transitions[i]; bestPriority = transitionPriority; } } } if (nextTransition == null) { // Try to find valid transition to next state nextTransition = cursor.Node.QueryNextTransition(); } // Transition into next state if (nextTransition != null) { cursor.FollowTransition(nextTransition); } } while (nextTransition != null && cursor.Node.PassThrough && passThrough-- > 0); }
/// <summary> /// Expands current node with given cursor. /// First enquedAction is taking place then any valid transition. /// Cursor is being transitioned to result of expansion. /// Override this for custom behavior. /// </summary> protected virtual void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet<MyStringId> enquedActions, int passThrough) { MyStateMachineTransition nextTransition; do { // Try to find best transition across enquedActions // Does not need to be evaluated one. nextTransition = null; var transitions = cursor.Node.OutTransitions; if (enquedActions.Count > 0) { int bestPriority = int.MaxValue; for (var i = 0; i < transitions.Count; i++) { int transitionPriority = transitions[i].Priority ?? int.MaxValue; if (enquedActions.Contains(transitions[i].Name) && transitionPriority <= bestPriority && (transitions[i].Conditions.Count == 0 || transitions[i].Evaluate())) { nextTransition = transitions[i]; bestPriority = transitionPriority; } } } if (nextTransition == null) { // Try to find valid transition to next state nextTransition = cursor.Node.QueryNextTransition(); } // Transition into next state if (nextTransition != null) cursor.FollowTransition(nextTransition); } while (nextTransition != null && cursor.Node.PassThrough && passThrough-- > 0); }