Browse Source

Fixed faulty indent levels when inspector is not displayed #380

master
chrisgregan 9 years ago
parent
commit
447862c86f
  1. 29
      Assets/Fungus/Flowchart/Editor/BlockEditor.cs
  2. 32
      Assets/Fungus/Flowchart/Scripts/Block.cs

29
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)

32
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++;
}
}
}
}
}

Loading…
Cancel
Save