Browse Source

Added properties for fine control of Reset command

master
chrisgregan 10 years ago
parent
commit
427759830b
  1. 8
      Assets/Fungus/FungusScript/Commands/Reset.cs
  2. 22
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs

8
Assets/Fungus/FungusScript/Commands/Reset.cs

@ -6,12 +6,16 @@ namespace Fungus
{ {
[CommandInfo("Scripting", [CommandInfo("Scripting",
"Reset", "Reset",
"Resets state of all commands and variables in this Fungus Script.")] "Resets the state of all commands and local and global variables in the Fungus Script.")]
public class Reset : Command public class Reset : Command
{ {
public bool resetCommands = true;
public bool resetLocalVariables = true;
public bool resetGlobalVariables = true;
public override void OnEnter() public override void OnEnter()
{ {
GetFungusScript().Reset(); GetFungusScript().Reset(resetCommands, resetLocalVariables, resetGlobalVariables);
Continue(); Continue();
} }

22
Assets/Fungus/FungusScript/Scripts/FungusScript.cs

@ -409,17 +409,29 @@ namespace Fungus
} }
} }
public virtual void Reset() public virtual void Reset(bool resetCommands, bool resetLocalVariables, bool resetGlobalVariables)
{ {
Command[] commands = GetComponentsInChildren<Command>(); if (resetCommands)
foreach (Command command in commands)
{ {
command.OnReset(); Command[] commands = GetComponentsInChildren<Command>();
foreach (Command command in commands)
{
command.OnReset();
}
} }
foreach (Variable variable in variables) foreach (Variable variable in variables)
{ {
variable.OnReset(); if (resetLocalVariables &&
variable.scope == VariableScope.Local)
{
variable.OnReset();
}
else if (resetGlobalVariables &&
variable.scope == VariableScope.Global)
{
variable.OnReset();
}
} }
} }
} }

Loading…
Cancel
Save