From 16e4ba425f957b7a34aa9f16574435acacdb8388 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 21 Oct 2016 16:52:28 +0100 Subject: [PATCH] Added accessors for GameObject and Transform variables in Flowchart.cs --- Assets/Fungus/Scripts/Components/Flowchart.cs | 82 ++++++++++++++++--- 1 file changed, 70 insertions(+), 12 deletions(-) diff --git a/Assets/Fungus/Scripts/Components/Flowchart.cs b/Assets/Fungus/Scripts/Components/Flowchart.cs index ed563167..34e590c8 100644 --- a/Assets/Fungus/Scripts/Components/Flowchart.cs +++ b/Assets/Fungus/Scripts/Components/Flowchart.cs @@ -797,8 +797,7 @@ namespace Fungus /// public virtual bool GetBooleanVariable(string key) { - BooleanVariable variable = GetVariable(key); - + var variable = GetVariable(key); if(variable != null) { return GetVariable(key).Value; @@ -815,7 +814,7 @@ namespace Fungus /// public virtual void SetBooleanVariable(string key, bool value) { - BooleanVariable variable = GetVariable(key); + var variable = GetVariable(key); if(variable != null) { variable.Value = value; @@ -828,8 +827,7 @@ namespace Fungus /// public virtual int GetIntegerVariable(string key) { - IntegerVariable variable = GetVariable(key); - + var variable = GetVariable(key); if (variable != null) { return GetVariable(key).Value; @@ -846,7 +844,7 @@ namespace Fungus /// public virtual void SetIntegerVariable(string key, int value) { - IntegerVariable variable = GetVariable(key); + var variable = GetVariable(key); if (variable != null) { variable.Value = value; @@ -859,8 +857,7 @@ namespace Fungus /// public virtual float GetFloatVariable(string key) { - FloatVariable variable = GetVariable(key); - + var variable = GetVariable(key); if (variable != null) { return GetVariable(key).Value; @@ -877,7 +874,7 @@ namespace Fungus /// public virtual void SetFloatVariable(string key, float value) { - FloatVariable variable = GetVariable(key); + var variable = GetVariable(key); if (variable != null) { variable.Value = value; @@ -890,8 +887,7 @@ namespace Fungus /// public virtual string GetStringVariable(string key) { - StringVariable variable = GetVariable(key); - + var variable = GetVariable(key); if (variable != null) { return GetVariable(key).Value; @@ -908,7 +904,69 @@ namespace Fungus /// public virtual void SetStringVariable(string key, string value) { - StringVariable variable = GetVariable(key); + var variable = GetVariable(key); + if (variable != null) + { + variable.Value = value; + } + } + + /// + /// Gets the value of a GameObject variable. + /// Returns null if the variable key does not exist. + /// + public virtual GameObject GetGameObjectVariable(string key) + { + var variable = GetVariable(key); + + if (variable != null) + { + return GetVariable(key).Value; + } + else + { + return null; + } + } + + /// + /// Sets the value of a GameObject variable. + /// The variable must already be added to the list of variables for this Flowchart. + /// + public virtual void SetGameObjectVariable(string key, GameObject value) + { + var variable = GetVariable(key); + if (variable != null) + { + variable.Value = value; + } + } + + /// + /// Gets the value of a Transform variable. + /// Returns null if the variable key does not exist. + /// + public virtual Transform GetTransformVariable(string key) + { + var variable = GetVariable(key); + + if (variable != null) + { + return GetVariable(key).Value; + } + else + { + return null; + } + } + + /// + /// Sets the value of a Transform variable. + /// The variable must already be added to the list of variables for this Flowchart. + /// + public virtual void SetTransformVariable(string key, Transform value) + { + var variable = GetVariable(key); if (variable != null) { variable.Value = value;