|
|
@ -371,59 +371,48 @@ namespace Fungus |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Start running another Flowchart by executing a specific child block. |
|
|
|
* Execute a child block in the Flowchart. |
|
|
|
* The block must be in an idle state to be executed. |
|
|
|
|
|
|
|
* You can use this method in a UI event. e.g. to handle a button click. |
|
|
|
* You can use this method in a UI event. e.g. to handle a button click. |
|
|
|
|
|
|
|
* Returns true if the Block started execution. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public virtual void ExecuteBlock(string blockName) |
|
|
|
public virtual bool ExecuteBlock(string blockName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Block [] blocks = GetComponentsInChildren<Block>(); |
|
|
|
Block block = null; |
|
|
|
foreach (Block block in blocks) |
|
|
|
foreach (Block b in GetComponentsInChildren<Block>()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (block.blockName == blockName) |
|
|
|
if (b.blockName == blockName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ExecuteBlock(block); |
|
|
|
block = b; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
if (block == null) |
|
|
|
* Sends a message to this Flowchart only. |
|
|
|
|
|
|
|
* Any block with a matching MessageReceived event handler will start executing. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public virtual void SendFungusMessage(string messageName) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
MessageReceived[] eventHandlers = GetComponentsInChildren<MessageReceived>(); |
|
|
|
|
|
|
|
foreach (MessageReceived eventHandler in eventHandlers) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
eventHandler.OnSendFungusMessage(messageName); |
|
|
|
Debug.LogError("Block " + blockName + "does not exist"); |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
return ExecuteBlock(block); |
|
|
|
* Sends a message to all Flowchart objects in the current scene. |
|
|
|
|
|
|
|
* Any block with a matching MessageReceived event handler will start executing. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static void BroadcastFungusMessage(string messageName) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
MessageReceived[] eventHandlers = GameObject.FindObjectsOfType<MessageReceived>(); |
|
|
|
|
|
|
|
foreach (MessageReceived eventHandler in eventHandlers) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
eventHandler.OnSendFungusMessage(messageName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Start executing a specific child block in the flowchart. |
|
|
|
* Execute a child block in the flowchart. |
|
|
|
* The block must be in an idle state to be executed. |
|
|
|
* The block must be in an idle state to be executed. |
|
|
|
|
|
|
|
* This version provides extra options to control how the block is executed. |
|
|
|
* Returns true if the Block started execution. |
|
|
|
* Returns true if the Block started execution. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public virtual bool ExecuteBlock(Block block, Action onComplete = null) |
|
|
|
public virtual bool ExecuteBlock(Block block, int commandIndex = 0, Action onComplete = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Block must be a component of the Flowchart game object |
|
|
|
if (block == null) |
|
|
|
if (block == null || |
|
|
|
|
|
|
|
block.gameObject != gameObject) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
Debug.LogError("Block must not be null"); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (block.gameObject != gameObject) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Debug.LogError("Block must belong to the same gameobject as this Flowchart"); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -433,8 +422,8 @@ namespace Fungus |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Execute the first command in the command list |
|
|
|
// Start executing the Block as a new coroutine |
|
|
|
block.Execute(onComplete); |
|
|
|
StartCoroutine(block.Execute(commandIndex, onComplete)); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -454,6 +443,32 @@ namespace Fungus |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Sends a message to this Flowchart only. |
|
|
|
|
|
|
|
* Any block with a matching MessageReceived event handler will start executing. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public virtual void SendFungusMessage(string messageName) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
MessageReceived[] eventHandlers = GetComponentsInChildren<MessageReceived>(); |
|
|
|
|
|
|
|
foreach (MessageReceived eventHandler in eventHandlers) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
eventHandler.OnSendFungusMessage(messageName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Sends a message to all Flowchart objects in the current scene. |
|
|
|
|
|
|
|
* Any block with a matching MessageReceived event handler will start executing. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static void BroadcastFungusMessage(string messageName) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
MessageReceived[] eventHandlers = GameObject.FindObjectsOfType<MessageReceived>(); |
|
|
|
|
|
|
|
foreach (MessageReceived eventHandler in eventHandlers) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
eventHandler.OnSendFungusMessage(messageName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 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. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -590,6 +605,26 @@ namespace Fungus |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Returns the variable with the specified key, or null if the key is not found. |
|
|
|
|
|
|
|
* You will need to cast the returned variable to the correct sub-type. |
|
|
|
|
|
|
|
* You can then access the variable's value using the Value property. e.g. |
|
|
|
|
|
|
|
* BooleanVariable boolVar = flowchart.GetVariable("MyBool") as BooleanVariable; |
|
|
|
|
|
|
|
* boolVar.Value = false; |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Variable GetVariable(string key) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach (Variable variable in variables) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (variable != null && variable.key == key) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return variable; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns the variable with the specified key, or null if the key is not found. |
|
|
|
* Returns the variable with the specified key, or null if the key is not found. |
|
|
|
* You can then access the variable's value using the Value property. e.g. |
|
|
|
* You can then access the variable's value using the Value property. e.g. |
|
|
|