From 427759830b37acf6f0f5eb3431d9cff77e286a35 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Tue, 28 Oct 2014 12:42:24 +0000 Subject: [PATCH] Added properties for fine control of Reset command --- Assets/Fungus/FungusScript/Commands/Reset.cs | 8 +++++-- .../FungusScript/Scripts/FungusScript.cs | 22 ++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Assets/Fungus/FungusScript/Commands/Reset.cs b/Assets/Fungus/FungusScript/Commands/Reset.cs index fd5c7441..903ac723 100644 --- a/Assets/Fungus/FungusScript/Commands/Reset.cs +++ b/Assets/Fungus/FungusScript/Commands/Reset.cs @@ -6,12 +6,16 @@ namespace Fungus { [CommandInfo("Scripting", "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 bool resetCommands = true; + public bool resetLocalVariables = true; + public bool resetGlobalVariables = true; + public override void OnEnter() { - GetFungusScript().Reset(); + GetFungusScript().Reset(resetCommands, resetLocalVariables, resetGlobalVariables); Continue(); } diff --git a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs index 16d88595..139d0cce 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs +++ b/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(); - foreach (Command command in commands) + if (resetCommands) { - command.OnReset(); + Command[] commands = GetComponentsInChildren(); + foreach (Command command in commands) + { + command.OnReset(); + } } foreach (Variable variable in variables) { - variable.OnReset(); + if (resetLocalVariables && + variable.scope == VariableScope.Local) + { + variable.OnReset(); + } + else if (resetGlobalVariables && + variable.scope == VariableScope.Global) + { + variable.OnReset(); + } } } }