diff --git a/Assets/Fungus/Flowchart/Editor/BlockEditor.cs b/Assets/Fungus/Flowchart/Editor/BlockEditor.cs index 9bffe4f0..4512a079 100644 --- a/Assets/Fungus/Flowchart/Editor/BlockEditor.cs +++ b/Assets/Fungus/Flowchart/Editor/BlockEditor.cs @@ -98,7 +98,7 @@ namespace Fungus DrawEventHandlerGUI(flowchart); - UpdateIndentLevels(block); + block.UpdateIndentLevels(); // Make sure each command has a reference to its parent block foreach (Command command in block.commandList) @@ -404,33 +404,6 @@ namespace Fungus PrefabUtility.RecordPrefabInstancePropertyModifications(block); } - protected virtual void UpdateIndentLevels(Block block) - { - int indentLevel = 0; - foreach(Command command in block.commandList) - { - if (command == null) - { - continue; - } - - if (command.CloseBlock()) - { - indentLevel--; - } - - // Negative indent level is not permitted - indentLevel = Math.Max(indentLevel, 0); - - command.indentLevel = indentLevel; - - if (command.OpenBlock()) - { - indentLevel++; - } - } - } - static public void BlockField(SerializedProperty property, GUIContent label, GUIContent nullLabel, Flowchart flowchart) { if (flowchart == null) diff --git a/Assets/Fungus/Flowchart/Scripts/Block.cs b/Assets/Fungus/Flowchart/Scripts/Block.cs index 2b31ecb9..8b3c0685 100644 --- a/Assets/Fungus/Flowchart/Scripts/Block.cs +++ b/Assets/Fungus/Flowchart/Scripts/Block.cs @@ -87,6 +87,11 @@ namespace Fungus command.commandIndex = index++; } + // Ensure all commands are at their correct indent level + // This should have already happened in the editor, but may be necessary + // if commands are added to the Block at runtime. + UpdateIndentLevels(); + executionInfoSet = true; } @@ -285,5 +290,32 @@ namespace Fungus return null; } + + public virtual void UpdateIndentLevels() + { + int indentLevel = 0; + foreach(Command command in commandList) + { + if (command == null) + { + continue; + } + + if (command.CloseBlock()) + { + indentLevel--; + } + + // Negative indent level is not permitted + indentLevel = Math.Max(indentLevel, 0); + + command.indentLevel = indentLevel; + + if (command.OpenBlock()) + { + indentLevel++; + } + } + } } }