Browse Source

Flowchart.Execute block can't be used with UI events #112

Changed ExecuteBlock to return void.
Added Flowchart.FindBlock so you can check if a Block is executing
before you try to execute it.
master
chrisgregan 10 years ago
parent
commit
f7ac1c45a5
  1. 25
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs

25
Assets/Fungus/Flowchart/Scripts/Flowchart.cs

@ -251,23 +251,38 @@ namespace Fungus
return b; return b;
} }
/**
* Returns the named Block in the flowchart, or null if not found.
*/
public virtual Block FindBlock(string blockName)
{
Block [] blocks = GetComponentsInChildren<Block>();
foreach (Block block in blocks)
{
if (block.blockName == blockName)
{
return block;
}
}
return null;
}
/** /**
* Start running another Flowchart by executing a specific child block. * Start running another Flowchart by executing a specific child block.
* The block must be in an idle state to be executed. * The block must be in an idle state to be executed.
* Returns true if the Block started execution. * You can use this method in a UI event. e.g. to handle a button click.
*/ */
public virtual bool ExecuteBlock(string blockName) public virtual void ExecuteBlock(string blockName)
{ {
Block [] blocks = GetComponentsInChildren<Block>(); Block [] blocks = GetComponentsInChildren<Block>();
foreach (Block block in blocks) foreach (Block block in blocks)
{ {
if (block.blockName == blockName) if (block.blockName == blockName)
{ {
return ExecuteBlock(block); ExecuteBlock(block);
} }
} }
return false;
} }
/** /**

Loading…
Cancel
Save