diff --git a/Assets/Fungus/Flowchart/Editor/BlockEditor.cs b/Assets/Fungus/Flowchart/Editor/BlockEditor.cs index cac216e3..31d91d37 100644 --- a/Assets/Fungus/Flowchart/Editor/BlockEditor.cs +++ b/Assets/Fungus/Flowchart/Editor/BlockEditor.cs @@ -829,11 +829,7 @@ namespace Fungus if (showPlay) { - commandMenu.AddItem(new GUIContent("Play from Selected Command"), false, PlayCommand); - } - else - { - commandMenu.AddDisabledItem(new GUIContent("Play from Selected Command")); + commandMenu.AddItem(new GUIContent("Play from selected"), false, PlayCommand); } commandMenu.AddSeparator(""); @@ -1027,16 +1023,25 @@ namespace Fungus Block targetBlock = target as Block; Flowchart flowchart = targetBlock.GetFlowchart(); Command command = flowchart.selectedCommands[0]; - if (!targetBlock.IsExecuting()) + if (targetBlock.IsExecuting()) { - flowchart.ExecuteBlock(targetBlock, command.commandIndex); + // The Block is already executing. + // Tell the Block to stop, wait a little while so the executing command has a + // chance to stop, and then start execution again from the new command. + targetBlock.Stop(); + flowchart.StartCoroutine(RunBlock(flowchart, targetBlock, command.commandIndex, 0.2f)); } else { - targetBlock.jumpToCommandIndex = command.commandIndex; - flowchart.ExecuteBlock(targetBlock); + // Block isn't executing yet so can start it now. + flowchart.ExecuteBlock(targetBlock, command.commandIndex); } + } + protected IEnumerator RunBlock(Flowchart flowchart, Block targetBlock, int commandIndex, float delay) + { + yield return new WaitForSeconds(delay); + flowchart.ExecuteBlock(targetBlock, commandIndex); } protected void SelectPrevious()