Browse Source

Added Flowchart.StopAllBlocks() and command callback

master
chrisgregan 9 years ago
parent
commit
b14da8fcda
  1. 6
      Assets/Fungus/Flowchart/Scripts/Block.cs
  2. 11
      Assets/Fungus/Flowchart/Scripts/Command.cs
  3. 2
      Assets/Fungus/Flowchart/Scripts/Commands/Call.cs
  4. 4
      Assets/Fungus/Flowchart/Scripts/Commands/Else.cs
  5. 4
      Assets/Fungus/Flowchart/Scripts/Commands/ElseIf.cs
  6. 6
      Assets/Fungus/Flowchart/Scripts/Commands/If.cs
  7. 4
      Assets/Fungus/Flowchart/Scripts/Commands/InvokeMethod.cs
  8. 4
      Assets/Fungus/Flowchart/Scripts/Commands/Stop.cs
  9. 15
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs

6
Assets/Fungus/Flowchart/Scripts/Block.cs

@ -237,6 +237,12 @@ namespace Fungus
public virtual void Stop() public virtual void Stop()
{ {
// Tell the executing command to stop immediately
if (activeCommand != null)
{
activeCommand.OnStopExecuting();
}
// This will cause the execution loop to break on the next iteration // This will cause the execution loop to break on the next iteration
jumpToCommandIndex = int.MaxValue; jumpToCommandIndex = int.MaxValue;
} }

11
Assets/Fungus/Flowchart/Scripts/Command.cs

@ -95,7 +95,7 @@ namespace Fungus
} }
} }
public virtual void Stop() public virtual void StopParentBlock()
{ {
OnExit(); OnExit();
if (parentBlock != null) if (parentBlock != null)
@ -104,6 +104,15 @@ namespace Fungus
} }
} }
/**
* Called when the parent block has been requested to stop executing, and
* this command is the currently executing command.
* Use this callback to terminate any asynchronous operations and
* cleanup state so that the command is ready to execute again later on.
*/
public virtual void OnStopExecuting()
{}
/** /**
* Called when the new command is added to a block in the editor. * Called when the new command is added to a block in the editor.
*/ */

2
Assets/Fungus/Flowchart/Scripts/Commands/Call.cs

@ -75,7 +75,7 @@ namespace Fungus
if (callMode == CallMode.Stop) if (callMode == CallMode.Stop)
{ {
Stop(); StopParentBlock();
} }
else if (callMode == CallMode.Continue) else if (callMode == CallMode.Continue)
{ {

4
Assets/Fungus/Flowchart/Scripts/Commands/Else.cs

@ -20,7 +20,7 @@ namespace Fungus
// Stop if this is the last command in the list // Stop if this is the last command in the list
if (commandIndex >= parentBlock.commandList.Count - 1) if (commandIndex >= parentBlock.commandList.Count - 1)
{ {
Stop(); StopParentBlock();
return; return;
} }
@ -43,7 +43,7 @@ namespace Fungus
} }
// No End command found // No End command found
Stop(); StopParentBlock();
} }
public override bool OpenBlock() public override bool OpenBlock()

4
Assets/Fungus/Flowchart/Scripts/Commands/ElseIf.cs

@ -31,7 +31,7 @@ namespace Fungus
// Stop if this is the last command in the list // Stop if this is the last command in the list
if (commandIndex >= parentBlock.commandList.Count - 1) if (commandIndex >= parentBlock.commandList.Count - 1)
{ {
Stop(); StopParentBlock();
return; return;
} }
@ -54,7 +54,7 @@ namespace Fungus
} }
// No End command found // No End command found
Stop(); StopParentBlock();
} }
} }

6
Assets/Fungus/Flowchart/Scripts/Commands/If.cs

@ -97,7 +97,7 @@ namespace Fungus
// Last command in block // Last command in block
if (commandIndex >= parentBlock.commandList.Count) if (commandIndex >= parentBlock.commandList.Count)
{ {
Stop(); StopParentBlock();
return; return;
} }
@ -128,7 +128,7 @@ namespace Fungus
if (i >= parentBlock.commandList.Count - 1) if (i >= parentBlock.commandList.Count - 1)
{ {
// Last command in Block, so stop // Last command in Block, so stop
Stop(); StopParentBlock();
} }
else else
{ {
@ -147,7 +147,7 @@ namespace Fungus
} }
// No matching End command found, so just stop the block // No matching End command found, so just stop the block
Stop(); StopParentBlock();
} }
public override string GetSummary() public override string GetSummary()

4
Assets/Fungus/Flowchart/Scripts/Commands/InvokeMethod.cs

@ -1,4 +1,4 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using System.Reflection; using System.Reflection;
using System.Linq; using System.Linq;
@ -120,7 +120,7 @@ namespace Fungus
} }
else if(callMode == Call.CallMode.Stop) else if(callMode == Call.CallMode.Stop)
{ {
Stop(); StopParentBlock();
} }
} }
} }

4
Assets/Fungus/Flowchart/Scripts/Commands/Stop.cs

@ -6,13 +6,13 @@ namespace Fungus
{ {
[CommandInfo("Flow", [CommandInfo("Flow",
"Stop", "Stop",
"Stop executing the current Flowchart.")] "Stop executing the Block that contains this command.")]
[AddComponentMenu("")] [AddComponentMenu("")]
public class Stop : Command public class Stop : Command
{ {
public override void OnEnter() public override void OnEnter()
{ {
Stop(); StopParentBlock();
} }
public override Color GetButtonColor() public override Color GetButtonColor()

15
Assets/Fungus/Flowchart/Scripts/Flowchart.cs

@ -425,6 +425,21 @@ namespace Fungus
return true; return true;
} }
/**
* Stop all executing Blocks in this Flowchart.
*/
public virtual void StopAllBlocks()
{
Block [] blocks = GetComponentsInChildren<Block>();
foreach (Block block in blocks)
{
if (block.IsExecuting())
{
block.Stop();
}
}
}
/** /**
* Returns a new variable key that is guaranteed not to clash with any existing variable in the list. * Returns a new variable key that is guaranteed not to clash with any existing variable in the list.
*/ */

Loading…
Cancel
Save