void OnConditionComplete(NativeActivityContext context, ActivityInstance completedInstance, bool result)
{
StateMachineEventManager eventManager = this.EventManager.Get(context);
int triggerId = eventManager.CurrentBeingProcessedEvent.TriggedId;
if (result)
{
this.TakeTransition(context, eventManager, triggerId);
}
else
{
// condition failed: reschedule trigger
int currentConditionIndex = eventManager.CurrentConditionIndex;
Fx.Assert(eventManager.CurrentConditionIndex >= 0, "Conditional Transition must have non-negative index.");
InternalTransition transition = this.GetInternalTransition(triggerId);
currentConditionIndex++;
if (currentConditionIndex < transition.TransitionDataList.Count)
{
eventManager.CurrentConditionIndex = currentConditionIndex;
context.ScheduleActivity<bool>(transition.TransitionDataList[currentConditionIndex].Condition, this.onConditionComplete, null);
}
else
{
// Schedule current trigger again firstly.
context.ScheduleActivity(transition.Trigger, this.onTriggerComplete);
this.currentRunningTriggers.Set(context, this.currentRunningTriggers.Get(context) + 1);
// check whether there is any other trigger completed.
ProcessNextTriggerCompletedEvent(context, eventManager);
}
}
}