Browse Source

Fixed logic for setting GameStarted block in new Flowcharts

Also added safety cleanup code to remove null items in variable list in
cleanup.
master
chrisgregan 10 years ago
parent
commit
00b6b910bc
  1. 8
      Assets/Fungus/Flowchart/Editor/FlowchartMenuItems.cs
  2. 15
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs

8
Assets/Fungus/Flowchart/Editor/FlowchartMenuItems.cs

@ -13,6 +13,14 @@ namespace Fungus
{
GameObject go = SpawnPrefab("Flowchart");
go.transform.position = Vector3.zero;
// Only the first created Flowchart in the scene should have a default GameStarted block
if (GameObject.FindObjectsOfType<Flowchart>().Length > 1)
{
Block block = go.GetComponent<Block>();
block.eventHandler = null;
GameObject.DestroyImmediate(block.eventHandler);
}
}
[MenuItem("Tools/Fungus/Create/Fungus Logo", false, 1000)]

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

@ -246,7 +246,11 @@ namespace Fungus
// they waste memory so should be cleared out periodically.
Block[] blocks = GetComponentsInChildren<Block>();
// Remove any null entries in the variables list
// It shouldn't happen but it seemed to occur for a user on the forum
variables.RemoveAll(item => item == null);
foreach (Variable variable in GetComponents<Variable>())
{
if (!variables.Contains(variable))
@ -310,14 +314,7 @@ namespace Fungus
}
protected virtual void Initialize()
{
// If there are other flowcharts in the scene and the selected block has the default name, then this is probably a new block.
// Reset the event handler of the new flowchart's default block to avoid crashes.
if (selectedBlock && cachedFlowcharts.Count > 1 && selectedBlock.blockName == DEFAULT_BLOCK_NAME)
{
selectedBlock.eventHandler = null;
}
}
{}
protected virtual Block CreateBlockComponent(GameObject parent)
{

Loading…
Cancel
Save