From 5329caa624a88e1c08e79e2711474931fb0bd7e9 Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Sun, 13 Jan 2019 20:36:03 +1000 Subject: [PATCH 1/3] Mathf Command more consistent implementation of HasReference and more Detailed Summaries --- Assets/Fungus/Scripts/Commands/Math/Abs.cs | 5 ---- .../Commands/Math/BaseUnaryMathCommand.cs | 10 +++++++ Assets/Fungus/Scripts/Commands/Math/Clamp.cs | 11 ++++++- Assets/Fungus/Scripts/Commands/Math/Curve.cs | 5 ---- Assets/Fungus/Scripts/Commands/Math/Exp.cs | 5 ---- Assets/Fungus/Scripts/Commands/Math/Inv.cs | 5 ---- .../Fungus/Scripts/Commands/Math/InvLerp.cs | 11 ++++++- Assets/Fungus/Scripts/Commands/Math/Lerp.cs | 6 ++++ Assets/Fungus/Scripts/Commands/Math/Log.cs | 12 +------- Assets/Fungus/Scripts/Commands/Math/Map.cs | 7 +++++ Assets/Fungus/Scripts/Commands/Math/MinMax.cs | 11 +++++-- Assets/Fungus/Scripts/Commands/Math/Neg.cs | 5 ---- Assets/Fungus/Scripts/Commands/Math/Pow.cs | 10 ++++++- Assets/Fungus/Scripts/Commands/Math/Round.cs | 2 +- Assets/Fungus/Scripts/Commands/Math/Sign.cs | 5 ---- Assets/Fungus/Scripts/Commands/Math/Sqrt.cs | 5 ---- Assets/Fungus/Scripts/Commands/Math/ToInt.cs | 30 +++++++++++-------- Assets/Fungus/Scripts/Commands/Math/Trig.cs | 11 ++----- 18 files changed, 82 insertions(+), 74 deletions(-) diff --git a/Assets/Fungus/Scripts/Commands/Math/Abs.cs b/Assets/Fungus/Scripts/Commands/Math/Abs.cs index 8b9bc27e..0859907b 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Abs.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Abs.cs @@ -17,10 +17,5 @@ namespace Fungus Continue(); } - - public override string GetSummary() - { - return "Abs"; - } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/BaseUnaryMathCommand.cs b/Assets/Fungus/Scripts/Commands/Math/BaseUnaryMathCommand.cs index 253d834e..4a59709b 100644 --- a/Assets/Fungus/Scripts/Commands/Math/BaseUnaryMathCommand.cs +++ b/Assets/Fungus/Scripts/Commands/Math/BaseUnaryMathCommand.cs @@ -21,5 +21,15 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override string GetSummary() + { + return "in: " + (inValue.floatRef != null ? inValue.floatRef.Key : inValue.Value.ToString()) + + ", out: " + (outValue.floatRef != null ? outValue.floatRef.Key : outValue.Value.ToString()); + } + + public override bool HasReference(Variable variable) + { + return variable == inValue.floatRef || variable == outValue.floatRef; + } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Clamp.cs b/Assets/Fungus/Scripts/Commands/Math/Clamp.cs index 75ce2934..181e3bf5 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Clamp.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Clamp.cs @@ -55,7 +55,16 @@ namespace Fungus public override string GetSummary() { - return Mode.Clamp.ToString() + (mode != Mode.Clamp ? " & " + mode.ToString() : ""); + if (outValue.floatRef == null) + return "Error: no output value selected"; + + return outValue.floatRef.Key + " = " + Mode.Clamp.ToString() + (mode != Mode.Clamp ? " & " + mode.ToString() : ""); + } + + public override bool HasReference(Variable variable) + { + return lower.floatRef == variable || upper.floatRef == variable || value.floatRef == variable || + outValue.floatRef == variable; } public override Color GetButtonColor() diff --git a/Assets/Fungus/Scripts/Commands/Math/Curve.cs b/Assets/Fungus/Scripts/Commands/Math/Curve.cs index 69c8d76a..9d15bece 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Curve.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Curve.cs @@ -20,10 +20,5 @@ namespace Fungus Continue(); } - - public override string GetSummary() - { - return "Curve"; - } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Exp.cs b/Assets/Fungus/Scripts/Commands/Math/Exp.cs index 6e5c4723..5489c1a6 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Exp.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Exp.cs @@ -17,10 +17,5 @@ namespace Fungus Continue(); } - - public override string GetSummary() - { - return "Exp"; - } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Inv.cs b/Assets/Fungus/Scripts/Commands/Math/Inv.cs index fcd6a5d3..029761c3 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Inv.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Inv.cs @@ -19,10 +19,5 @@ namespace Fungus Continue(); } - - public override string GetSummary() - { - return "Inverse 1/f"; - } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/InvLerp.cs b/Assets/Fungus/Scripts/Commands/Math/InvLerp.cs index a593dc0d..a0f86c83 100644 --- a/Assets/Fungus/Scripts/Commands/Math/InvLerp.cs +++ b/Assets/Fungus/Scripts/Commands/Math/InvLerp.cs @@ -35,7 +35,16 @@ namespace Fungus public override string GetSummary() { - return "InvLerp [" + a.Value.ToString() + "-" + b.Value.ToString() + "]"; + if (outValue.floatRef == null) + return "Error: no out value selected"; + + return outValue.floatRef.Key + " = [" + a.Value.ToString() + "-" + b.Value.ToString() + "]"; + } + + public override bool HasReference(Variable variable) + { + return a.floatRef == variable || b.floatRef == variable || value.floatRef == variable || + outValue.floatRef == variable; } public override Color GetButtonColor() diff --git a/Assets/Fungus/Scripts/Commands/Math/Lerp.cs b/Assets/Fungus/Scripts/Commands/Math/Lerp.cs index 5caedf46..e98055ae 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Lerp.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Lerp.cs @@ -54,6 +54,12 @@ namespace Fungus return mode.ToString() + " [" + a.Value.ToString() + "-" + b.Value.ToString() + "]"; } + public override bool HasReference(Variable variable) + { + return a.floatRef == variable || b.floatRef == variable || percentage.floatRef == variable || + outValue.floatRef == variable; + } + public override Color GetButtonColor() { return new Color32(235, 191, 217, 255); diff --git a/Assets/Fungus/Scripts/Commands/Math/Log.cs b/Assets/Fungus/Scripts/Commands/Math/Log.cs index 2c7da4bb..8875f974 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Log.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Log.cs @@ -40,17 +40,7 @@ namespace Fungus public override string GetSummary() { - switch (mode) - { - case Mode.Base10: - return "Log Base 10"; - case Mode.Natural: - return "Natural Log"; - default: - break; - } - - return "Log"; + return mode.ToString() + " " + base.GetSummary(); } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Map.cs b/Assets/Fungus/Scripts/Commands/Math/Map.cs index 61f7fb23..3f653ad4 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Map.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Map.cs @@ -40,6 +40,13 @@ namespace Fungus newRangeLower.Value.ToString() + "-" + newRangeUpper.Value.ToString() + "]"; } + public override bool HasReference(Variable variable) + { + return initialRangeLower.floatRef == variable || initialRangeUpper.floatRef == variable || value.floatRef == variable || + newRangeLower.floatRef == variable || newRangeUpper.floatRef == variable || + outValue.floatRef == variable; + } + public override Color GetButtonColor() { return new Color32(235, 191, 217, 255); diff --git a/Assets/Fungus/Scripts/Commands/Math/MinMax.cs b/Assets/Fungus/Scripts/Commands/Math/MinMax.cs index 9efeb0a0..7294454f 100644 --- a/Assets/Fungus/Scripts/Commands/Math/MinMax.cs +++ b/Assets/Fungus/Scripts/Commands/Math/MinMax.cs @@ -43,19 +43,24 @@ namespace Fungus break; } - Continue(); } public override string GetSummary() { - return function.ToString(); + return function.ToString() + " " + + "out: " + (outValue.floatRef != null ? outValue.floatRef.Key : outValue.Value.ToString()) + + " [" + inLHSValue.Value.ToString() + " - " + inRHSValue.Value.ToString() + "]"; + } + + public override bool HasReference(Variable variable) + { + return inLHSValue.floatRef == variable || inRHSValue.floatRef == variable || outValue.floatRef == variable; } public override Color GetButtonColor() { return new Color32(235, 191, 217, 255); } - } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Neg.cs b/Assets/Fungus/Scripts/Commands/Math/Neg.cs index 883ef7de..1f063868 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Neg.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Neg.cs @@ -17,10 +17,5 @@ namespace Fungus Continue(); } - - public override string GetSummary() - { - return "Negate"; - } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Pow.cs b/Assets/Fungus/Scripts/Commands/Math/Pow.cs index e20db290..586c43c5 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Pow.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Pow.cs @@ -27,7 +27,10 @@ namespace Fungus public override string GetSummary() { - return "Pow"; + if (outValue.floatRef == null) + return "Error: No out value selected"; + + return outValue.floatRef.Key + " = " + baseValue.Value.ToString() + "^" + exponentValue.Value.ToString(); } public override Color GetButtonColor() @@ -35,5 +38,10 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return baseValue.floatRef == variable || exponentValue.floatRef == variable || + outValue.floatRef == variable; + } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Round.cs b/Assets/Fungus/Scripts/Commands/Math/Round.cs index 418893f7..d7ddc301 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Round.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Round.cs @@ -44,7 +44,7 @@ namespace Fungus public override string GetSummary() { - return function.ToString(); + return function.ToString() + " " + base.GetSummary(); } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Sign.cs b/Assets/Fungus/Scripts/Commands/Math/Sign.cs index d3b3ebb9..89fea7b8 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Sign.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Sign.cs @@ -17,10 +17,5 @@ namespace Fungus Continue(); } - - public override string GetSummary() - { - return "Sign"; - } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Sqrt.cs b/Assets/Fungus/Scripts/Commands/Math/Sqrt.cs index 57500efe..d8e9485c 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Sqrt.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Sqrt.cs @@ -17,10 +17,5 @@ namespace Fungus Continue(); } - - public override string GetSummary() - { - return "Sqrt"; - } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/ToInt.cs b/Assets/Fungus/Scripts/Commands/Math/ToInt.cs index e4a15b24..cf8596ca 100644 --- a/Assets/Fungus/Scripts/Commands/Math/ToInt.cs +++ b/Assets/Fungus/Scripts/Commands/Math/ToInt.cs @@ -35,17 +35,17 @@ namespace Fungus { switch (function) { - case Mode.RoundToInt: - outValue.Value = Mathf.RoundToInt(inValue.Value); - break; - case Mode.FloorToInt: - outValue.Value = Mathf.FloorToInt(inValue.Value); - break; - case Mode.CeilToInt: - outValue.Value = Mathf.CeilToInt(inValue.Value); - break; - default: - break; + case Mode.RoundToInt: + outValue.Value = Mathf.RoundToInt(inValue.Value); + break; + case Mode.FloorToInt: + outValue.Value = Mathf.FloorToInt(inValue.Value); + break; + case Mode.CeilToInt: + outValue.Value = Mathf.CeilToInt(inValue.Value); + break; + default: + break; } Continue(); @@ -53,7 +53,9 @@ namespace Fungus public override string GetSummary() { - return function.ToString(); + return function.ToString() + + " in: " + (inValue.floatRef != null ? inValue.floatRef.Key : inValue.Value.ToString()) + + ", out: " + (outValue.integerRef != null ? outValue.integerRef.Key : outValue.Value.ToString()); ; } public override Color GetButtonColor() @@ -61,5 +63,9 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return variable == inValue.floatRef || variable == outValue.integerRef; + } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Trig.cs b/Assets/Fungus/Scripts/Commands/Math/Trig.cs index 998cf902..2ef5b78a 100644 --- a/Assets/Fungus/Scripts/Commands/Math/Trig.cs +++ b/Assets/Fungus/Scripts/Commands/Math/Trig.cs @@ -22,8 +22,7 @@ namespace Fungus Sin, Tan } - - + [Tooltip("Trigonometric function to run.")] [SerializeField] protected Function function = Function.Sin; @@ -65,13 +64,7 @@ namespace Fungus public override string GetSummary() { - return function.ToString(); + return function.ToString() + " " + base.GetSummary(); } - - public override Color GetButtonColor() - { - return new Color32(235, 191, 217, 255); - } - } } \ No newline at end of file From e73121ea5c24c80aaf4a91b4f3b0db9dbc4adb4a Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Mon, 14 Jan 2019 21:50:56 +1000 Subject: [PATCH 2/3] Command can now cache a list of referenced variables that are checked by the variablelistadapter for highlighting - Flowchart can identify add variables found via the substitute regex - Commands that use SubstituteVariables on their string data use the new caching method so they can highlight variables that will be used during substitution --- .../Fungus/Scripts/Commands/Conversation.cs | 14 ++++++++ Assets/Fungus/Scripts/Commands/DebugLog.cs | 13 +++++++ .../Fungus/Scripts/Commands/DeleteSaveKey.cs | 15 +++++++- .../Fungus/Scripts/Commands/LoadVariable.cs | 14 +++++++- Assets/Fungus/Scripts/Commands/Menu.cs | 13 +++++++ .../Fungus/Scripts/Commands/SaveVariable.cs | 14 +++++++- Assets/Fungus/Scripts/Commands/SetText.cs | 14 ++++++++ Assets/Fungus/Scripts/Commands/SetVariable.cs | 13 +++++++ Assets/Fungus/Scripts/Components/Command.cs | 34 +++++++++++++++++++ Assets/Fungus/Scripts/Components/Flowchart.cs | 17 ++++++++++ .../Scripts/Editor/VariableListAdaptor.cs | 4 +-- 11 files changed, 160 insertions(+), 5 deletions(-) diff --git a/Assets/Fungus/Scripts/Commands/Conversation.cs b/Assets/Fungus/Scripts/Commands/Conversation.cs index 42e1da4a..34410fba 100644 --- a/Assets/Fungus/Scripts/Commands/Conversation.cs +++ b/Assets/Fungus/Scripts/Commands/Conversation.cs @@ -64,5 +64,19 @@ namespace Fungus } #endregion + + + #region Editor caches +#if UNITY_EDITOR + protected override void RefreshVariableCache() + { + base.RefreshVariableCache(); + + var f = GetFlowchart(); + + f.DetermineSubstituteVariables(conversationText, referencedVariables); + } +#endif + #endregion Editor caches } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/DebugLog.cs b/Assets/Fungus/Scripts/Commands/DebugLog.cs index fce1c374..35285992 100644 --- a/Assets/Fungus/Scripts/Commands/DebugLog.cs +++ b/Assets/Fungus/Scripts/Commands/DebugLog.cs @@ -67,5 +67,18 @@ namespace Fungus } #endregion + + #region Editor caches +#if UNITY_EDITOR + protected override void RefreshVariableCache() + { + base.RefreshVariableCache(); + + var f = GetFlowchart(); + + f.DetermineSubstituteVariables(logMessage.Value, referencedVariables); + } +#endif + #endregion Editor caches } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/DeleteSaveKey.cs b/Assets/Fungus/Scripts/Commands/DeleteSaveKey.cs index 6b7559ac..e9a6e6b5 100644 --- a/Assets/Fungus/Scripts/Commands/DeleteSaveKey.cs +++ b/Assets/Fungus/Scripts/Commands/DeleteSaveKey.cs @@ -53,5 +53,18 @@ namespace Fungus } #endregion - } + + #region Editor caches +#if UNITY_EDITOR + protected override void RefreshVariableCache() + { + base.RefreshVariableCache(); + + var f = GetFlowchart(); + + f.DetermineSubstituteVariables(key, referencedVariables); + } +#endif + #endregion Editor caches + } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LoadVariable.cs b/Assets/Fungus/Scripts/Commands/LoadVariable.cs index ecea1bab..5c074ea3 100644 --- a/Assets/Fungus/Scripts/Commands/LoadVariable.cs +++ b/Assets/Fungus/Scripts/Commands/LoadVariable.cs @@ -100,5 +100,17 @@ namespace Fungus } #endregion - } + #region Editor caches +#if UNITY_EDITOR + protected override void RefreshVariableCache() + { + base.RefreshVariableCache(); + + var f = GetFlowchart(); + + f.DetermineSubstituteVariables(key, referencedVariables); + } +#endif + #endregion Editor caches + } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Menu.cs b/Assets/Fungus/Scripts/Commands/Menu.cs index c8ac058a..6babd89c 100644 --- a/Assets/Fungus/Scripts/Commands/Menu.cs +++ b/Assets/Fungus/Scripts/Commands/Menu.cs @@ -121,5 +121,18 @@ namespace Fungus } #endregion + + #region Editor caches +#if UNITY_EDITOR + protected override void RefreshVariableCache() + { + base.RefreshVariableCache(); + + var f = GetFlowchart(); + + f.DetermineSubstituteVariables(text, referencedVariables); + } +#endif + #endregion Editor caches } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/SaveVariable.cs b/Assets/Fungus/Scripts/Commands/SaveVariable.cs index 43933880..5b9f9e5e 100644 --- a/Assets/Fungus/Scripts/Commands/SaveVariable.cs +++ b/Assets/Fungus/Scripts/Commands/SaveVariable.cs @@ -104,5 +104,17 @@ namespace Fungus } #endregion - } + #region Editor caches +#if UNITY_EDITOR + protected override void RefreshVariableCache() + { + base.RefreshVariableCache(); + + var f = GetFlowchart(); + + f.DetermineSubstituteVariables(key, referencedVariables); + } +#endif + #endregion Editor caches + } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/SetText.cs b/Assets/Fungus/Scripts/Commands/SetText.cs index 0f87a67b..6fdb0fe5 100644 --- a/Assets/Fungus/Scripts/Commands/SetText.cs +++ b/Assets/Fungus/Scripts/Commands/SetText.cs @@ -82,6 +82,20 @@ namespace Fungus #endregion + + #region Editor caches +#if UNITY_EDITOR + protected override void RefreshVariableCache() + { + base.RefreshVariableCache(); + + var f = GetFlowchart(); + + f.DetermineSubstituteVariables(text, referencedVariables); + } +#endif + #endregion Editor caches + #region ILocalizable implementation public virtual string GetStandardText() diff --git a/Assets/Fungus/Scripts/Commands/SetVariable.cs b/Assets/Fungus/Scripts/Commands/SetVariable.cs index 98e3f3ba..a696a3ee 100644 --- a/Assets/Fungus/Scripts/Commands/SetVariable.cs +++ b/Assets/Fungus/Scripts/Commands/SetVariable.cs @@ -319,5 +319,18 @@ namespace Fungus } #endregion + + #region Editor caches +#if UNITY_EDITOR + protected override void RefreshVariableCache() + { + base.RefreshVariableCache(); + + var f = GetFlowchart(); + + f.DetermineSubstituteVariables(stringData.Value, referencedVariables); + } +#endif + #endregion Editor caches } } diff --git a/Assets/Fungus/Scripts/Components/Command.cs b/Assets/Fungus/Scripts/Components/Command.cs index 0c63df11..6188f3ea 100644 --- a/Assets/Fungus/Scripts/Components/Command.cs +++ b/Assets/Fungus/Scripts/Components/Command.cs @@ -50,6 +50,30 @@ namespace Fungus protected string errorMessage = ""; + #region Editor caches +#if UNITY_EDITOR + // + protected List referencedVariables = new List(); + + //used by var list adapter to highlight variables + public bool IsVariableReferenced(Variable variable) + { + return referencedVariables.Contains(variable) || HasReference(variable); + } + + /// + /// Called by OnValidate + /// + /// Child classes to specialise to add variable references to referencedVariables, either directly or + /// via the use of Flowchart.DetermineSubstituteVariables + /// + protected virtual void RefreshVariableCache() + { + referencedVariables.Clear(); + } +#endif + #endregion Editor caches + #region Public members /// @@ -204,6 +228,16 @@ namespace Fungus return false; } + /// + /// Called by unity when script is loaded or its data changed by editor + /// + public virtual void OnValidate() + { +#if UNITY_EDITOR + RefreshVariableCache(); +#endif + } + /// /// Returns the summary text to display in the command inspector. /// diff --git a/Assets/Fungus/Scripts/Components/Flowchart.cs b/Assets/Fungus/Scripts/Components/Flowchart.cs index 28355e20..25b11047 100644 --- a/Assets/Fungus/Scripts/Components/Flowchart.cs +++ b/Assets/Fungus/Scripts/Components/Flowchart.cs @@ -1264,6 +1264,23 @@ namespace Fungus } } + public virtual void DetermineSubstituteVariables(string str, List vars) + { + Regex r = new Regex(Flowchart.SubstituteVariableRegexString); + + // Match the regular expression pattern against a text string. + var results = r.Matches(str); + for (int i = 0; i < results.Count; i++) + { + var match = results[i]; + var v = GetVariable(match.Value.Substring(2, match.Value.Length - 3)); + if (v != null) + { + vars.Add(v); + } + } + } + #endregion #region IStringSubstituter implementation diff --git a/Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs b/Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs index 3b3698cc..8dcfaf8c 100644 --- a/Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs +++ b/Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs @@ -178,7 +178,7 @@ namespace Fungus.EditorUtils { if (Application.isPlaying && flowchart.SelectedBlock.IsExecuting()) { - highlight = flowchart.SelectedBlock.ActiveCommand.HasReference(variable); + highlight = flowchart.SelectedBlock.ActiveCommand.IsVariableReferenced(variable); } else if (!Application.isPlaying && flowchart.SelectedCommands.Count > 0) { @@ -189,7 +189,7 @@ namespace Fungus.EditorUtils continue; } - if (selectedCommand.HasReference(variable)) + if (selectedCommand.IsVariableReferenced(variable)) { highlight = true; break; From f0213e083530b5b2d0e38877e145c1477423e1d5 Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Tue, 15 Jan 2019 20:20:49 +1000 Subject: [PATCH 3/3] HasReference added to many commands that lacked them or had only partially checked vars --- Assets/Fungus/Scripts/Commands/Call.cs | 5 + .../Fungus/Scripts/Commands/ControlAudio.cs | 5 + .../Fungus/Scripts/Commands/Conversation.cs | 7 + Assets/Fungus/Scripts/Commands/DebugLog.cs | 5 + Assets/Fungus/Scripts/Commands/ExecuteLua.cs | 5 + Assets/Fungus/Scripts/Commands/FadeSprite.cs | 6 + Assets/Fungus/Scripts/Commands/FadeUI.cs | 6 + Assets/Fungus/Scripts/Commands/GetText.cs | 6 + .../Fungus/Scripts/Commands/GetToggleState.cs | 6 + Assets/Fungus/Scripts/Commands/InvokeEvent.cs | 7 + Assets/Fungus/Scripts/Commands/Jump.cs | 6 + .../LeanTween/BaseLeanTweenCommand.cs | 5 + .../Scripts/Commands/LeanTween/MoveLean.cs | 6 +- .../Scripts/Commands/LeanTween/RotateLean.cs | 5 + .../Scripts/Commands/LeanTween/ScaleLean.cs | 5 + .../Commands/LeanTween/StopTweensLean.cs | 5 + Assets/Fungus/Scripts/Commands/LoadScene.cs | 6 + .../Fungus/Scripts/Commands/LoadVariable.cs | 6 + Assets/Fungus/Scripts/Commands/LookFrom.cs | 6 + Assets/Fungus/Scripts/Commands/LookTo.cs | 6 + Assets/Fungus/Scripts/Commands/Menu.cs | 6 + Assets/Fungus/Scripts/Commands/MenuTimer.cs | 6 + Assets/Fungus/Scripts/Commands/MoveAdd.cs | 6 + Assets/Fungus/Scripts/Commands/MoveFrom.cs | 6 + Assets/Fungus/Scripts/Commands/MoveTo.cs | 6 + Assets/Fungus/Scripts/Commands/OpenURL.cs | 5 + .../Fungus/Scripts/Commands/PlayAnimState.cs | 7 + .../Fungus/Scripts/Commands/PlayUsfxrSound.cs | 5 + .../Commands/Priority/FungusPriorityCount.cs | 5 + .../Fungus/Scripts/Commands/PunchPosition.cs | 5 + .../Fungus/Scripts/Commands/PunchRotation.cs | 5 + Assets/Fungus/Scripts/Commands/PunchScale.cs | 5 + Assets/Fungus/Scripts/Commands/RandomFloat.cs | 2 +- .../Fungus/Scripts/Commands/RandomInteger.cs | 2 +- .../Scripts/Commands/ResetAnimTrigger.cs | 6 + Assets/Fungus/Scripts/Commands/RotateAdd.cs | 6 + Assets/Fungus/Scripts/Commands/RotateFrom.cs | 6 + Assets/Fungus/Scripts/Commands/RotateTo.cs | 6 + .../Fungus/Scripts/Commands/SaveVariable.cs | 5 + Assets/Fungus/Scripts/Commands/ScaleAdd.cs | 6 + Assets/Fungus/Scripts/Commands/ScaleFrom.cs | 6 + Assets/Fungus/Scripts/Commands/ScaleTo.cs | 6 + Assets/Fungus/Scripts/Commands/SendMessage.cs | 5 + Assets/Fungus/Scripts/Commands/SetActive.cs | 6 + Assets/Fungus/Scripts/Commands/SetAnimBool.cs | 6 + .../Fungus/Scripts/Commands/SetAnimFloat.cs | 6 + .../Fungus/Scripts/Commands/SetAnimInteger.cs | 6 + .../Fungus/Scripts/Commands/SetAnimTrigger.cs | 5 + .../Fungus/Scripts/Commands/SetClickable2D.cs | 7 +- Assets/Fungus/Scripts/Commands/SetCollider.cs | 5 + .../Fungus/Scripts/Commands/SetDraggable2D.cs | 5 + .../Scripts/Commands/SetInteractable.cs | 5 + Assets/Fungus/Scripts/Commands/SetLanguage.cs | 5 + .../Fungus/Scripts/Commands/SetSliderValue.cs | 5 + .../Fungus/Scripts/Commands/SetSpriteOrder.cs | 5 + Assets/Fungus/Scripts/Commands/SetText.cs | 5 + .../Fungus/Scripts/Commands/SetToggleState.cs | 5 + Assets/Fungus/Scripts/Commands/SetVariable.cs | 141 ++++++++++++++---- .../Fungus/Scripts/Commands/ShakePosition.cs | 5 + .../Fungus/Scripts/Commands/ShakeRotation.cs | 5 + Assets/Fungus/Scripts/Commands/ShakeScale.cs | 5 + Assets/Fungus/Scripts/Commands/ShowSprite.cs | 5 + Assets/Fungus/Scripts/Commands/StopBlock.cs | 5 + Assets/Fungus/Scripts/Commands/StopTween.cs | 5 + Assets/Fungus/Scripts/Commands/TweenUI.cs | 5 + .../Scripts/Commands/VariableCondition.cs | 140 +++++++++++++---- Assets/Fungus/Scripts/Commands/Wait.cs | 5 + Assets/Fungus/Scripts/Commands/WaitFrames.cs | 5 + Assets/Fungus/Scripts/Commands/Write.cs | 5 + .../Fungus/Scripts/Commands/iTweenCommand.cs | 6 + 70 files changed, 580 insertions(+), 70 deletions(-) diff --git a/Assets/Fungus/Scripts/Commands/Call.cs b/Assets/Fungus/Scripts/Commands/Call.cs index 93246a1d..d7076715 100644 --- a/Assets/Fungus/Scripts/Commands/Call.cs +++ b/Assets/Fungus/Scripts/Commands/Call.cs @@ -161,6 +161,11 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return startLabel.stringRef == variable || base.HasReference(variable); + } + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/ControlAudio.cs b/Assets/Fungus/Scripts/Commands/ControlAudio.cs index 8a5ad5fe..d4100ead 100644 --- a/Assets/Fungus/Scripts/Commands/ControlAudio.cs +++ b/Assets/Fungus/Scripts/Commands/ControlAudio.cs @@ -284,6 +284,11 @@ namespace Fungus return new Color32(242, 209, 176, 255); } + public override bool HasReference(Variable variable) + { + return _audioSource.audioSourceRef == variable || base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/Conversation.cs b/Assets/Fungus/Scripts/Commands/Conversation.cs index 34410fba..e7cdbd0c 100644 --- a/Assets/Fungus/Scripts/Commands/Conversation.cs +++ b/Assets/Fungus/Scripts/Commands/Conversation.cs @@ -63,6 +63,13 @@ namespace Fungus return new Color32(184, 210, 235, 255); } + public override bool HasReference(Variable variable) + { + return clearPrevious.booleanRef == variable || waitForInput.booleanRef == variable || + waitForSeconds.floatRef == variable || fadeWhenDone.booleanRef == variable || + base.HasReference(variable); + } + #endregion diff --git a/Assets/Fungus/Scripts/Commands/DebugLog.cs b/Assets/Fungus/Scripts/Commands/DebugLog.cs index 35285992..6c39772b 100644 --- a/Assets/Fungus/Scripts/Commands/DebugLog.cs +++ b/Assets/Fungus/Scripts/Commands/DebugLog.cs @@ -66,6 +66,11 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return logMessage.stringRef == variable || base.HasReference(variable); + } + #endregion #region Editor caches diff --git a/Assets/Fungus/Scripts/Commands/ExecuteLua.cs b/Assets/Fungus/Scripts/Commands/ExecuteLua.cs index 501c45c4..cf538c75 100644 --- a/Assets/Fungus/Scripts/Commands/ExecuteLua.cs +++ b/Assets/Fungus/Scripts/Commands/ExecuteLua.cs @@ -203,6 +203,11 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return returnVariable == variable || base.HasReference(variable); + } + #endregion } } diff --git a/Assets/Fungus/Scripts/Commands/FadeSprite.cs b/Assets/Fungus/Scripts/Commands/FadeSprite.cs index 0d41b643..af68b7b5 100644 --- a/Assets/Fungus/Scripts/Commands/FadeSprite.cs +++ b/Assets/Fungus/Scripts/Commands/FadeSprite.cs @@ -66,6 +66,12 @@ namespace Fungus return new Color32(221, 184, 169, 255); } + public override bool HasReference(Variable variable) + { + return _duration.floatRef == variable || _targetColor.colorRef == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/FadeUI.cs b/Assets/Fungus/Scripts/Commands/FadeUI.cs index d344c79d..7263e9df 100644 --- a/Assets/Fungus/Scripts/Commands/FadeUI.cs +++ b/Assets/Fungus/Scripts/Commands/FadeUI.cs @@ -163,6 +163,12 @@ namespace Fungus return true; } + public override bool HasReference(Variable variable) + { + return targetColor.colorRef == variable || targetAlpha.floatRef == variable || + base.HasReference(variable); + } + #endregion } } diff --git a/Assets/Fungus/Scripts/Commands/GetText.cs b/Assets/Fungus/Scripts/Commands/GetText.cs index adc01e7d..b9c2b057 100644 --- a/Assets/Fungus/Scripts/Commands/GetText.cs +++ b/Assets/Fungus/Scripts/Commands/GetText.cs @@ -82,6 +82,12 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return stringVariable == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/GetToggleState.cs b/Assets/Fungus/Scripts/Commands/GetToggleState.cs index 5dfe9972..17ad1242 100644 --- a/Assets/Fungus/Scripts/Commands/GetToggleState.cs +++ b/Assets/Fungus/Scripts/Commands/GetToggleState.cs @@ -54,6 +54,12 @@ namespace Fungus return toggle.name; } + public override bool HasReference(Variable variable) + { + return toggleState == variable || + base.HasReference(variable); + } + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/InvokeEvent.cs b/Assets/Fungus/Scripts/Commands/InvokeEvent.cs index 55c3e402..6cdc5bee 100644 --- a/Assets/Fungus/Scripts/Commands/InvokeEvent.cs +++ b/Assets/Fungus/Scripts/Commands/InvokeEvent.cs @@ -153,6 +153,13 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return booleanParameter.booleanRef == variable || integerParameter.integerRef == variable || + floatParameter.floatRef == variable || stringParameter.stringRef == variable || + base.HasReference(variable); + } + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Jump.cs b/Assets/Fungus/Scripts/Commands/Jump.cs index ebaa4b4d..340841ce 100644 --- a/Assets/Fungus/Scripts/Commands/Jump.cs +++ b/Assets/Fungus/Scripts/Commands/Jump.cs @@ -61,6 +61,12 @@ namespace Fungus return new Color32(253, 253, 150, 255); } + public override bool HasReference(Variable variable) + { + return _targetLabel.stringRef == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs b/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs index e617d284..9607eb0f 100644 --- a/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs +++ b/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs @@ -110,6 +110,11 @@ namespace Fungus return new Color32(233, 163, 180, 255); } + public override bool HasReference(Variable variable) + { + return variable == _targetObject.gameObjectRef || variable == _duration.floatRef; + } + #endregion } diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs b/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs index 319bb21a..1ab79b07 100644 --- a/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs +++ b/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs @@ -50,6 +50,10 @@ namespace Fungus else return LeanTween.move(_targetObject.Value, loc, _duration); } - + + public override bool HasReference(Variable variable) + { + return _toTransform.transformRef == variable || _toPosition.vector3Ref == variable || base.HasReference(variable); + } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs b/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs index eaa26761..ed8c7975 100644 --- a/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs +++ b/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs @@ -70,5 +70,10 @@ namespace Fungus else return LeanTween.rotate(_targetObject.Value, rot, _duration); } + + public override bool HasReference(Variable variable) + { + return variable == _toTransform.transformRef || _toRotation.vector3Ref == variable || base.HasReference(variable); + } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs b/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs index cc26391f..603869e7 100644 --- a/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs +++ b/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs @@ -42,5 +42,10 @@ namespace Fungus return LeanTween.scale(_targetObject.Value, sc, _duration); } + + public override bool HasReference(Variable variable) + { + return variable == _toTransform.transformRef || _toScale.vector3Ref == variable || base.HasReference(variable); + } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs b/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs index 19bf64d7..24957c7d 100644 --- a/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs +++ b/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs @@ -43,5 +43,10 @@ namespace Fungus { return new Color32(233, 163, 180, 255); } + + public override bool HasReference(Variable variable) + { + return _targetObject.gameObjectRef == variable; + } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LoadScene.cs b/Assets/Fungus/Scripts/Commands/LoadScene.cs index 36208348..e99660b5 100644 --- a/Assets/Fungus/Scripts/Commands/LoadScene.cs +++ b/Assets/Fungus/Scripts/Commands/LoadScene.cs @@ -50,6 +50,12 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return _sceneName.stringRef == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/LoadVariable.cs b/Assets/Fungus/Scripts/Commands/LoadVariable.cs index 5c074ea3..8e4f45ea 100644 --- a/Assets/Fungus/Scripts/Commands/LoadVariable.cs +++ b/Assets/Fungus/Scripts/Commands/LoadVariable.cs @@ -99,6 +99,12 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable in_variable) + { + return this.variable == in_variable || + base.HasReference(in_variable); + } + #endregion #region Editor caches #if UNITY_EDITOR diff --git a/Assets/Fungus/Scripts/Commands/LookFrom.cs b/Assets/Fungus/Scripts/Commands/LookFrom.cs index d3af3c15..875f7d35 100644 --- a/Assets/Fungus/Scripts/Commands/LookFrom.cs +++ b/Assets/Fungus/Scripts/Commands/LookFrom.cs @@ -61,6 +61,12 @@ namespace Fungus iTween.LookFrom(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _fromTransform.transformRef == variable || _fromPosition.vector3Ref == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/LookTo.cs b/Assets/Fungus/Scripts/Commands/LookTo.cs index c785bcce..f5a7ca59 100644 --- a/Assets/Fungus/Scripts/Commands/LookTo.cs +++ b/Assets/Fungus/Scripts/Commands/LookTo.cs @@ -61,6 +61,12 @@ namespace Fungus iTween.LookTo(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _toTransform.transformRef == variable || _toPosition.vector3Ref == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/Menu.cs b/Assets/Fungus/Scripts/Commands/Menu.cs index 6babd89c..2af4c1fd 100644 --- a/Assets/Fungus/Scripts/Commands/Menu.cs +++ b/Assets/Fungus/Scripts/Commands/Menu.cs @@ -95,6 +95,12 @@ namespace Fungus return new Color32(184, 210, 235, 255); } + public override bool HasReference(Variable variable) + { + return interactable.booleanRef == variable || hideThisOption.booleanRef == variable || + base.HasReference(variable); + } + #endregion #region ILocalizable implementation diff --git a/Assets/Fungus/Scripts/Commands/MenuTimer.cs b/Assets/Fungus/Scripts/Commands/MenuTimer.cs index bec4cffb..cb012224 100644 --- a/Assets/Fungus/Scripts/Commands/MenuTimer.cs +++ b/Assets/Fungus/Scripts/Commands/MenuTimer.cs @@ -62,6 +62,12 @@ namespace Fungus return new Color32(184, 210, 235, 255); } + public override bool HasReference(Variable variable) + { + return _duration.floatRef == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/MoveAdd.cs b/Assets/Fungus/Scripts/Commands/MoveAdd.cs index 0d518740..0d7f2352 100644 --- a/Assets/Fungus/Scripts/Commands/MoveAdd.cs +++ b/Assets/Fungus/Scripts/Commands/MoveAdd.cs @@ -40,6 +40,12 @@ namespace Fungus iTween.MoveAdd(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _offset.vector3Ref == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/MoveFrom.cs b/Assets/Fungus/Scripts/Commands/MoveFrom.cs index 8cc0613b..f6912477 100644 --- a/Assets/Fungus/Scripts/Commands/MoveFrom.cs +++ b/Assets/Fungus/Scripts/Commands/MoveFrom.cs @@ -50,6 +50,12 @@ namespace Fungus iTween.MoveFrom(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _fromTransform.transformRef == variable || _fromPosition.vector3Ref == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/MoveTo.cs b/Assets/Fungus/Scripts/Commands/MoveTo.cs index aac0e7bc..33ba70cc 100644 --- a/Assets/Fungus/Scripts/Commands/MoveTo.cs +++ b/Assets/Fungus/Scripts/Commands/MoveTo.cs @@ -50,6 +50,12 @@ namespace Fungus iTween.MoveTo(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _toTransform.transformRef == variable || _toPosition.vector3Ref == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/OpenURL.cs b/Assets/Fungus/Scripts/Commands/OpenURL.cs index a13714fc..f9d67987 100644 --- a/Assets/Fungus/Scripts/Commands/OpenURL.cs +++ b/Assets/Fungus/Scripts/Commands/OpenURL.cs @@ -36,6 +36,11 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return url.stringRef == variable || base.HasReference(variable); + } + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/PlayAnimState.cs b/Assets/Fungus/Scripts/Commands/PlayAnimState.cs index 86983b6f..4738a515 100644 --- a/Assets/Fungus/Scripts/Commands/PlayAnimState.cs +++ b/Assets/Fungus/Scripts/Commands/PlayAnimState.cs @@ -53,6 +53,13 @@ namespace Fungus return new Color32(170, 204, 169, 255); } + public override bool HasReference(Variable variable) + { + return animator.animatorRef == variable || stateName.stringRef == variable || + layer.integerRef == variable || time.floatRef == variable || + base.HasReference(variable); + } + #endregion } } diff --git a/Assets/Fungus/Scripts/Commands/PlayUsfxrSound.cs b/Assets/Fungus/Scripts/Commands/PlayUsfxrSound.cs index b61e005c..c1eacfdd 100644 --- a/Assets/Fungus/Scripts/Commands/PlayUsfxrSound.cs +++ b/Assets/Fungus/Scripts/Commands/PlayUsfxrSound.cs @@ -83,6 +83,11 @@ using UnityEngine.Serialization; return new Color32(128, 200, 200, 255); } + public override bool HasReference(Variable variable) + { + return variable == _SettingsString.stringRef; + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityCount.cs b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityCount.cs index a1aa957a..69df8bd8 100644 --- a/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityCount.cs +++ b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityCount.cs @@ -30,5 +30,10 @@ namespace Fungus } return outVar.Key; } + + public override bool HasReference(Variable variable) + { + return outVar == variable; + } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/PunchPosition.cs b/Assets/Fungus/Scripts/Commands/PunchPosition.cs index 4f02620c..ff7b0b0a 100644 --- a/Assets/Fungus/Scripts/Commands/PunchPosition.cs +++ b/Assets/Fungus/Scripts/Commands/PunchPosition.cs @@ -40,6 +40,11 @@ namespace Fungus iTween.PunchPosition(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return variable == _amount.vector3Ref; + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/PunchRotation.cs b/Assets/Fungus/Scripts/Commands/PunchRotation.cs index 4fab9d73..71fec5b9 100644 --- a/Assets/Fungus/Scripts/Commands/PunchRotation.cs +++ b/Assets/Fungus/Scripts/Commands/PunchRotation.cs @@ -40,6 +40,11 @@ namespace Fungus iTween.PunchRotation(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return variable == _amount.vector3Ref; + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/PunchScale.cs b/Assets/Fungus/Scripts/Commands/PunchScale.cs index 2775eec2..7523520e 100644 --- a/Assets/Fungus/Scripts/Commands/PunchScale.cs +++ b/Assets/Fungus/Scripts/Commands/PunchScale.cs @@ -36,6 +36,11 @@ namespace Fungus iTween.PunchScale(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return variable == _amount.vector3Ref; + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/RandomFloat.cs b/Assets/Fungus/Scripts/Commands/RandomFloat.cs index 8ebcbcbc..1cfd5527 100644 --- a/Assets/Fungus/Scripts/Commands/RandomFloat.cs +++ b/Assets/Fungus/Scripts/Commands/RandomFloat.cs @@ -48,7 +48,7 @@ namespace Fungus public override bool HasReference(Variable variable) { - return (variable == this.variable); + return (variable == this.variable) || minValue.floatRef == variable || maxValue.floatRef == variable; } public override Color GetButtonColor() diff --git a/Assets/Fungus/Scripts/Commands/RandomInteger.cs b/Assets/Fungus/Scripts/Commands/RandomInteger.cs index 7e238a90..aa201df5 100644 --- a/Assets/Fungus/Scripts/Commands/RandomInteger.cs +++ b/Assets/Fungus/Scripts/Commands/RandomInteger.cs @@ -48,7 +48,7 @@ namespace Fungus public override bool HasReference(Variable variable) { - return (variable == this.variable); + return (variable == this.variable) || minValue.integerRef == variable || maxValue.integerRef == variable; } public override Color GetButtonColor() diff --git a/Assets/Fungus/Scripts/Commands/ResetAnimTrigger.cs b/Assets/Fungus/Scripts/Commands/ResetAnimTrigger.cs index f43c4774..baf3b277 100644 --- a/Assets/Fungus/Scripts/Commands/ResetAnimTrigger.cs +++ b/Assets/Fungus/Scripts/Commands/ResetAnimTrigger.cs @@ -49,6 +49,12 @@ namespace Fungus return new Color32(170, 204, 169, 255); } + public override bool HasReference(Variable variable) + { + return _animator.animatorRef == variable || _parameterName.stringRef == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/RotateAdd.cs b/Assets/Fungus/Scripts/Commands/RotateAdd.cs index f4dcd663..cf35b0dd 100644 --- a/Assets/Fungus/Scripts/Commands/RotateAdd.cs +++ b/Assets/Fungus/Scripts/Commands/RotateAdd.cs @@ -40,6 +40,12 @@ namespace Fungus iTween.RotateAdd(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _offset.vector3Ref == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/RotateFrom.cs b/Assets/Fungus/Scripts/Commands/RotateFrom.cs index f3797fde..46224268 100644 --- a/Assets/Fungus/Scripts/Commands/RotateFrom.cs +++ b/Assets/Fungus/Scripts/Commands/RotateFrom.cs @@ -50,6 +50,12 @@ namespace Fungus iTween.RotateFrom(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _fromTransform.transformRef == variable || _fromRotation.vector3Ref == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/RotateTo.cs b/Assets/Fungus/Scripts/Commands/RotateTo.cs index 1a6a1b33..7f5bcf74 100644 --- a/Assets/Fungus/Scripts/Commands/RotateTo.cs +++ b/Assets/Fungus/Scripts/Commands/RotateTo.cs @@ -50,6 +50,12 @@ namespace Fungus iTween.RotateTo(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _toTransform.transformRef == variable || _toRotation.vector3Ref == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/SaveVariable.cs b/Assets/Fungus/Scripts/Commands/SaveVariable.cs index 5b9f9e5e..4a5522d9 100644 --- a/Assets/Fungus/Scripts/Commands/SaveVariable.cs +++ b/Assets/Fungus/Scripts/Commands/SaveVariable.cs @@ -103,6 +103,11 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable in_variable) + { + return this.variable == in_variable || base.HasReference(in_variable); + } + #endregion #region Editor caches #if UNITY_EDITOR diff --git a/Assets/Fungus/Scripts/Commands/ScaleAdd.cs b/Assets/Fungus/Scripts/Commands/ScaleAdd.cs index 6dd633f2..be4e56f2 100644 --- a/Assets/Fungus/Scripts/Commands/ScaleAdd.cs +++ b/Assets/Fungus/Scripts/Commands/ScaleAdd.cs @@ -36,6 +36,12 @@ namespace Fungus iTween.ScaleAdd(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _offset.vector3Ref == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/ScaleFrom.cs b/Assets/Fungus/Scripts/Commands/ScaleFrom.cs index 1376c2ab..7c317f2a 100644 --- a/Assets/Fungus/Scripts/Commands/ScaleFrom.cs +++ b/Assets/Fungus/Scripts/Commands/ScaleFrom.cs @@ -46,6 +46,12 @@ namespace Fungus iTween.ScaleFrom(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _fromTransform.transformRef == variable || _fromScale.vector3Ref == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/ScaleTo.cs b/Assets/Fungus/Scripts/Commands/ScaleTo.cs index 4baeb3e5..3a80d57a 100644 --- a/Assets/Fungus/Scripts/Commands/ScaleTo.cs +++ b/Assets/Fungus/Scripts/Commands/ScaleTo.cs @@ -46,6 +46,12 @@ namespace Fungus iTween.ScaleTo(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _toTransform.transformRef == variable || _toScale.vector3Ref == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/SendMessage.cs b/Assets/Fungus/Scripts/Commands/SendMessage.cs index fd87b76d..995fc09c 100644 --- a/Assets/Fungus/Scripts/Commands/SendMessage.cs +++ b/Assets/Fungus/Scripts/Commands/SendMessage.cs @@ -84,6 +84,11 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return _message.stringRef == variable || base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/SetActive.cs b/Assets/Fungus/Scripts/Commands/SetActive.cs index 4a6f11bc..bafc947e 100644 --- a/Assets/Fungus/Scripts/Commands/SetActive.cs +++ b/Assets/Fungus/Scripts/Commands/SetActive.cs @@ -49,6 +49,12 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return _targetGameObject.gameObjectRef == variable || activeState.booleanRef == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/SetAnimBool.cs b/Assets/Fungus/Scripts/Commands/SetAnimBool.cs index a4b9290d..26a7a778 100644 --- a/Assets/Fungus/Scripts/Commands/SetAnimBool.cs +++ b/Assets/Fungus/Scripts/Commands/SetAnimBool.cs @@ -52,6 +52,12 @@ namespace Fungus return new Color32(170, 204, 169, 255); } + public override bool HasReference(Variable variable) + { + return _animator.animatorRef == variable || _parameterName.stringRef == variable || value.booleanRef == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/SetAnimFloat.cs b/Assets/Fungus/Scripts/Commands/SetAnimFloat.cs index 9494e542..5aa66f55 100644 --- a/Assets/Fungus/Scripts/Commands/SetAnimFloat.cs +++ b/Assets/Fungus/Scripts/Commands/SetAnimFloat.cs @@ -52,6 +52,12 @@ namespace Fungus return new Color32(170, 204, 169, 255); } + public override bool HasReference(Variable variable) + { + return _animator.animatorRef == variable || _parameterName.stringRef == variable || value.floatRef == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/SetAnimInteger.cs b/Assets/Fungus/Scripts/Commands/SetAnimInteger.cs index 8f07d4fd..cb4e8076 100644 --- a/Assets/Fungus/Scripts/Commands/SetAnimInteger.cs +++ b/Assets/Fungus/Scripts/Commands/SetAnimInteger.cs @@ -52,6 +52,12 @@ namespace Fungus return new Color32(170, 204, 169, 255); } + public override bool HasReference(Variable variable) + { + return _animator.animatorRef == variable || _parameterName.stringRef == variable || value.integerRef == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/SetAnimTrigger.cs b/Assets/Fungus/Scripts/Commands/SetAnimTrigger.cs index d7843e7a..a3d190cc 100644 --- a/Assets/Fungus/Scripts/Commands/SetAnimTrigger.cs +++ b/Assets/Fungus/Scripts/Commands/SetAnimTrigger.cs @@ -49,6 +49,11 @@ namespace Fungus return new Color32(170, 204, 169, 255); } + public override bool HasReference(Variable variable) + { + return _animator.animatorRef == variable || _parameterName.stringRef == variable || base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/SetClickable2D.cs b/Assets/Fungus/Scripts/Commands/SetClickable2D.cs index 80138ed7..29a59de9 100644 --- a/Assets/Fungus/Scripts/Commands/SetClickable2D.cs +++ b/Assets/Fungus/Scripts/Commands/SetClickable2D.cs @@ -44,7 +44,12 @@ namespace Fungus public override Color GetButtonColor() { - return new Color32(235, 191, 217, 255); + return new Color32(235, 191, 217, 255); + } + + public override bool HasReference(Variable variable) + { + return activeState.booleanRef == variable || base.HasReference(variable); } #endregion diff --git a/Assets/Fungus/Scripts/Commands/SetCollider.cs b/Assets/Fungus/Scripts/Commands/SetCollider.cs index ef623040..2cca14f8 100644 --- a/Assets/Fungus/Scripts/Commands/SetCollider.cs +++ b/Assets/Fungus/Scripts/Commands/SetCollider.cs @@ -102,6 +102,11 @@ namespace Fungus return propertyName == "targetObjects"; } + public override bool HasReference(Variable variable) + { + return activeState.booleanRef == variable || base.HasReference(variable); + } + #endregion } diff --git a/Assets/Fungus/Scripts/Commands/SetDraggable2D.cs b/Assets/Fungus/Scripts/Commands/SetDraggable2D.cs index c5e0ff6a..3b8ac1ef 100644 --- a/Assets/Fungus/Scripts/Commands/SetDraggable2D.cs +++ b/Assets/Fungus/Scripts/Commands/SetDraggable2D.cs @@ -47,6 +47,11 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return activeState.booleanRef == variable || base.HasReference(variable); + } + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/SetInteractable.cs b/Assets/Fungus/Scripts/Commands/SetInteractable.cs index e258883c..ea2d0912 100644 --- a/Assets/Fungus/Scripts/Commands/SetInteractable.cs +++ b/Assets/Fungus/Scripts/Commands/SetInteractable.cs @@ -101,6 +101,11 @@ namespace Fungus return false; } + public override bool HasReference(Variable variable) + { + return interactableState.booleanRef == variable || base.HasReference(variable); + } + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/SetLanguage.cs b/Assets/Fungus/Scripts/Commands/SetLanguage.cs index 2c6aae9f..9efc8867 100644 --- a/Assets/Fungus/Scripts/Commands/SetLanguage.cs +++ b/Assets/Fungus/Scripts/Commands/SetLanguage.cs @@ -48,6 +48,11 @@ namespace Fungus return new Color32(184, 210, 235, 255); } + public override bool HasReference(Variable variable) + { + return _languageCode.stringRef == variable || base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/SetSliderValue.cs b/Assets/Fungus/Scripts/Commands/SetSliderValue.cs index cfde6251..f80b06c9 100644 --- a/Assets/Fungus/Scripts/Commands/SetSliderValue.cs +++ b/Assets/Fungus/Scripts/Commands/SetSliderValue.cs @@ -47,6 +47,11 @@ namespace Fungus return slider.name + " = " + value.GetDescription(); } + public override bool HasReference(Variable variable) + { + return value.floatRef == variable || base.HasReference(variable); + } + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs b/Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs index e284941d..fb811b6b 100644 --- a/Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs +++ b/Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs @@ -80,6 +80,11 @@ namespace Fungus targetSprites.Add(null); } + public override bool HasReference(Variable variable) + { + return orderInLayer.integerRef == variable || base.HasReference(variable); + } + #endregion } } diff --git a/Assets/Fungus/Scripts/Commands/SetText.cs b/Assets/Fungus/Scripts/Commands/SetText.cs index 6fdb0fe5..a3204549 100644 --- a/Assets/Fungus/Scripts/Commands/SetText.cs +++ b/Assets/Fungus/Scripts/Commands/SetText.cs @@ -80,6 +80,11 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return text.stringRef == variable || base.HasReference(variable); + } + #endregion diff --git a/Assets/Fungus/Scripts/Commands/SetToggleState.cs b/Assets/Fungus/Scripts/Commands/SetToggleState.cs index 79d9f376..d93a0262 100644 --- a/Assets/Fungus/Scripts/Commands/SetToggleState.cs +++ b/Assets/Fungus/Scripts/Commands/SetToggleState.cs @@ -47,6 +47,11 @@ namespace Fungus return toggle.name + " = " + value.GetDescription(); } + public override bool HasReference(Variable variable) + { + return value.booleanRef == variable || base.HasReference(variable); + } + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/SetVariable.cs b/Assets/Fungus/Scripts/Commands/SetVariable.cs index a696a3ee..50ca8588 100644 --- a/Assets/Fungus/Scripts/Commands/SetVariable.cs +++ b/Assets/Fungus/Scripts/Commands/SetVariable.cs @@ -92,83 +92,86 @@ namespace Fungus return; } - if (variable.GetType() == typeof(BooleanVariable)) + + var t = variable.GetType(); + + if (t == typeof(BooleanVariable)) { BooleanVariable booleanVariable = (variable as BooleanVariable); booleanVariable.Apply(setOperator, booleanData.Value); } - else if (variable.GetType() == typeof(IntegerVariable)) + else if (t == typeof(IntegerVariable)) { IntegerVariable integerVariable = (variable as IntegerVariable); integerVariable.Apply(setOperator, integerData.Value); } - else if (variable.GetType() == typeof(FloatVariable)) + else if (t == typeof(FloatVariable)) { FloatVariable floatVariable = (variable as FloatVariable); floatVariable.Apply(setOperator, floatData.Value); } - else if (variable.GetType() == typeof(StringVariable)) + else if (t == typeof(StringVariable)) { StringVariable stringVariable = (variable as StringVariable); var flowchart = GetFlowchart(); stringVariable.Apply(setOperator, flowchart.SubstituteVariables(stringData.Value)); } - else if (variable.GetType() == typeof(AnimatorVariable)) + else if (t == typeof(AnimatorVariable)) { AnimatorVariable animatorVariable = (variable as AnimatorVariable); animatorVariable.Apply(setOperator, animatorData.Value); } - else if (variable.GetType() == typeof(AudioSourceVariable)) + else if (t == typeof(AudioSourceVariable)) { AudioSourceVariable audioSourceVariable = (variable as AudioSourceVariable); audioSourceVariable.Apply(setOperator, audioSourceData.Value); } - else if (variable.GetType() == typeof(ColorVariable)) + else if (t == typeof(ColorVariable)) { ColorVariable colorVariable = (variable as ColorVariable); colorVariable.Apply(setOperator, colorData.Value); } - else if (variable.GetType() == typeof(GameObjectVariable)) + else if (t == typeof(GameObjectVariable)) { GameObjectVariable gameObjectVariable = (variable as GameObjectVariable); gameObjectVariable.Apply(setOperator, gameObjectData.Value); } - else if (variable.GetType() == typeof(MaterialVariable)) + else if (t == typeof(MaterialVariable)) { MaterialVariable materialVariable = (variable as MaterialVariable); materialVariable.Apply(setOperator, materialData.Value); } - else if (variable.GetType() == typeof(ObjectVariable)) + else if (t == typeof(ObjectVariable)) { ObjectVariable objectVariable = (variable as ObjectVariable); objectVariable.Apply(setOperator, objectData.Value); } - else if (variable.GetType() == typeof(Rigidbody2DVariable)) + else if (t == typeof(Rigidbody2DVariable)) { Rigidbody2DVariable rigidbody2DVariable = (variable as Rigidbody2DVariable); rigidbody2DVariable.Apply(setOperator, rigidbody2DData.Value); } - else if (variable.GetType() == typeof(SpriteVariable)) + else if (t == typeof(SpriteVariable)) { SpriteVariable spriteVariable = (variable as SpriteVariable); spriteVariable.Apply(setOperator, spriteData.Value); } - else if (variable.GetType() == typeof(TextureVariable)) + else if (t == typeof(TextureVariable)) { TextureVariable textureVariable = (variable as TextureVariable); textureVariable.Apply(setOperator, textureData.Value); } - else if (variable.GetType() == typeof(TransformVariable)) + else if (t == typeof(TransformVariable)) { TransformVariable transformVariable = (variable as TransformVariable); transformVariable.Apply(setOperator, transformData.Value); } - else if (variable.GetType() == typeof(Vector2Variable)) + else if (t == typeof(Vector2Variable)) { Vector2Variable vector2Variable = (variable as Vector2Variable); vector2Variable.Apply(setOperator, vector2Data.Value); } - else if (variable.GetType() == typeof(Vector3Variable)) + else if (t == typeof(Vector3Variable)) { Vector3Variable vector3Variable = (variable as Vector3Variable); vector3Variable.Apply(setOperator, vector3Data.Value); @@ -240,67 +243,69 @@ namespace Fungus break; } - if (variable.GetType() == typeof(BooleanVariable)) + var t = variable.GetType(); + + if (t == typeof(BooleanVariable)) { description += booleanData.GetDescription(); } - else if (variable.GetType() == typeof(IntegerVariable)) + else if (t == typeof(IntegerVariable)) { description += integerData.GetDescription(); } - else if (variable.GetType() == typeof(FloatVariable)) + else if (t == typeof(FloatVariable)) { description += floatData.GetDescription(); } - else if (variable.GetType() == typeof(StringVariable)) + else if (t == typeof(StringVariable)) { description += stringData.GetDescription(); } - else if (variable.GetType() == typeof(AnimatorVariable)) + else if (t == typeof(AnimatorVariable)) { description += animatorData.GetDescription(); } - else if (variable.GetType() == typeof(AudioSourceVariable)) + else if (t == typeof(AudioSourceVariable)) { description += audioSourceData.GetDescription(); } - else if (variable.GetType() == typeof(ColorVariable)) + else if (t == typeof(ColorVariable)) { description += colorData.GetDescription(); } - else if (variable.GetType() == typeof(GameObjectVariable)) + else if (t == typeof(GameObjectVariable)) { description += gameObjectData.GetDescription(); } - else if (variable.GetType() == typeof(MaterialVariable)) + else if (t == typeof(MaterialVariable)) { description += materialData.GetDescription(); } - else if (variable.GetType() == typeof(ObjectVariable)) + else if (t == typeof(ObjectVariable)) { description += objectData.GetDescription(); } - else if (variable.GetType() == typeof(Rigidbody2DVariable)) + else if (t == typeof(Rigidbody2DVariable)) { description += rigidbody2DData.GetDescription(); } - else if (variable.GetType() == typeof(SpriteVariable)) + else if (t == typeof(SpriteVariable)) { description += spriteData.GetDescription(); } - else if (variable.GetType() == typeof(TextureVariable)) + else if (t == typeof(TextureVariable)) { description += textureData.GetDescription(); } - else if (variable.GetType() == typeof(TransformVariable)) + else if (t == typeof(TransformVariable)) { description += transformData.GetDescription(); } - else if (variable.GetType() == typeof(Vector2Variable)) + else if (t == typeof(Vector2Variable)) { description += vector2Data.GetDescription(); } - else if (variable.GetType() == typeof(Vector3Variable)) + else if (t == typeof(Vector3Variable)) { description += vector3Data.GetDescription(); } @@ -310,7 +315,77 @@ namespace Fungus public override bool HasReference(Variable variable) { - return (variable == this.variable); + bool retval = (variable == this.variable) || base.HasReference(variable); + + var t = variable.GetType(); + + //this is a nightmare + if (t == typeof(BooleanVariable)) + { + retval |= booleanData.booleanRef == variable; + } + else if (t == typeof(IntegerVariable)) + { + retval |= integerData.integerRef == variable; + } + else if (t == typeof(FloatVariable)) + { + retval |= floatData.floatRef == variable; + } + else if (t == typeof(StringVariable)) + { + retval |= stringData.stringRef == variable; + } + else if (t == typeof(AnimatorVariable)) + { + retval |= animatorData.animatorRef == variable; + } + else if (t == typeof(AudioSourceVariable)) + { + retval |= audioSourceData.audioSourceRef == variable; + } + else if (t == typeof(ColorVariable)) + { + retval |= colorData.colorRef == variable; + } + else if (t == typeof(GameObjectVariable)) + { + retval |= gameObjectData.gameObjectRef == variable; + } + else if (t == typeof(MaterialVariable)) + { + retval |= materialData.materialRef == variable; + } + else if (t == typeof(ObjectVariable)) + { + retval |= objectData.objectRef == variable; + } + else if (t == typeof(Rigidbody2DVariable)) + { + retval |= rigidbody2DData.rigidbody2DRef == variable; + } + else if (t == typeof(SpriteVariable)) + { + retval |= spriteData.spriteRef == variable; + } + else if (t == typeof(TextureVariable)) + { + retval |= textureData.textureRef == variable; + } + else if (t == typeof(TransformVariable)) + { + retval |= transformData.transformRef == variable; + } + else if (t == typeof(Vector2Variable)) + { + retval |= vector2Data.vector2Ref == variable; + } + else if (t == typeof(Vector3Variable)) + { + retval |= vector3Data.vector3Ref == variable; + } + + return retval; } public override Color GetButtonColor() diff --git a/Assets/Fungus/Scripts/Commands/ShakePosition.cs b/Assets/Fungus/Scripts/Commands/ShakePosition.cs index 4432d068..2388a0b2 100644 --- a/Assets/Fungus/Scripts/Commands/ShakePosition.cs +++ b/Assets/Fungus/Scripts/Commands/ShakePosition.cs @@ -55,6 +55,11 @@ namespace Fungus iTween.ShakePosition(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _amount.vector3Ref == variable || base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/ShakeRotation.cs b/Assets/Fungus/Scripts/Commands/ShakeRotation.cs index a4838efd..ab30c1d8 100644 --- a/Assets/Fungus/Scripts/Commands/ShakeRotation.cs +++ b/Assets/Fungus/Scripts/Commands/ShakeRotation.cs @@ -40,6 +40,11 @@ namespace Fungus iTween.ShakeRotation(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _amount.vector3Ref == variable || base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/ShakeScale.cs b/Assets/Fungus/Scripts/Commands/ShakeScale.cs index 6a3434d4..c2c0ffca 100644 --- a/Assets/Fungus/Scripts/Commands/ShakeScale.cs +++ b/Assets/Fungus/Scripts/Commands/ShakeScale.cs @@ -36,6 +36,11 @@ namespace Fungus iTween.ShakeScale(_targetObject.Value, tweenParams); } + public override bool HasReference(Variable variable) + { + return _amount.vector3Ref == variable || base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/ShowSprite.cs b/Assets/Fungus/Scripts/Commands/ShowSprite.cs index 110b6517..ea454a50 100644 --- a/Assets/Fungus/Scripts/Commands/ShowSprite.cs +++ b/Assets/Fungus/Scripts/Commands/ShowSprite.cs @@ -71,6 +71,11 @@ namespace Fungus return new Color32(221, 184, 169, 255); } + public override bool HasReference(Variable variable) + { + return _visible.booleanRef == variable || base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/StopBlock.cs b/Assets/Fungus/Scripts/Commands/StopBlock.cs index 125045d4..4f390591 100644 --- a/Assets/Fungus/Scripts/Commands/StopBlock.cs +++ b/Assets/Fungus/Scripts/Commands/StopBlock.cs @@ -55,6 +55,11 @@ namespace Fungus return new Color32(253, 253, 150, 255); } + public override bool HasReference(Variable variable) + { + return blockName.stringRef == variable || base.HasReference(variable); + } + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/StopTween.cs b/Assets/Fungus/Scripts/Commands/StopTween.cs index 059bf75e..f1cd8d11 100644 --- a/Assets/Fungus/Scripts/Commands/StopTween.cs +++ b/Assets/Fungus/Scripts/Commands/StopTween.cs @@ -27,6 +27,11 @@ namespace Fungus Continue(); } + public override bool HasReference(Variable variable) + { + return _tweenName.stringRef == variable || base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/TweenUI.cs b/Assets/Fungus/Scripts/Commands/TweenUI.cs index 2563c796..1a7e62f0 100644 --- a/Assets/Fungus/Scripts/Commands/TweenUI.cs +++ b/Assets/Fungus/Scripts/Commands/TweenUI.cs @@ -132,6 +132,11 @@ namespace Fungus return false; } + public override bool HasReference(Variable variable) + { + return waitUntilFinished.booleanRef == variable || duration.floatRef == variable || base.HasReference(variable); + } + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/VariableCondition.cs b/Assets/Fungus/Scripts/Commands/VariableCondition.cs index f69db54f..a1ab567a 100644 --- a/Assets/Fungus/Scripts/Commands/VariableCondition.cs +++ b/Assets/Fungus/Scripts/Commands/VariableCondition.cs @@ -87,82 +87,84 @@ namespace Fungus bool condition = false; - if (variable.GetType() == typeof(BooleanVariable)) + var t = variable.GetType(); + + if (t == typeof(BooleanVariable)) { BooleanVariable booleanVariable = (variable as BooleanVariable); condition = booleanVariable.Evaluate(compareOperator, booleanData.Value); } - else if (variable.GetType() == typeof(IntegerVariable)) + else if (t == typeof(IntegerVariable)) { IntegerVariable integerVariable = (variable as IntegerVariable); condition = integerVariable.Evaluate(compareOperator, integerData.Value); } - else if (variable.GetType() == typeof(FloatVariable)) + else if (t == typeof(FloatVariable)) { FloatVariable floatVariable = (variable as FloatVariable); condition = floatVariable.Evaluate(compareOperator, floatData.Value); } - else if (variable.GetType() == typeof(StringVariable)) + else if (t == typeof(StringVariable)) { StringVariable stringVariable = (variable as StringVariable); condition = stringVariable.Evaluate(compareOperator, stringData.Value); } - else if (variable.GetType() == typeof(AnimatorVariable)) + else if (t == typeof(AnimatorVariable)) { AnimatorVariable animatorVariable = (variable as AnimatorVariable); condition = animatorVariable.Evaluate(compareOperator, animatorData.Value); } - else if (variable.GetType() == typeof(AudioSourceVariable)) + else if (t == typeof(AudioSourceVariable)) { AudioSourceVariable audioSourceVariable = (variable as AudioSourceVariable); condition = audioSourceVariable.Evaluate(compareOperator, audioSourceData.Value); } - else if (variable.GetType() == typeof(ColorVariable)) + else if (t == typeof(ColorVariable)) { ColorVariable colorVariable = (variable as ColorVariable); condition = colorVariable.Evaluate(compareOperator, colorData.Value); } - else if (variable.GetType() == typeof(GameObjectVariable)) + else if (t == typeof(GameObjectVariable)) { GameObjectVariable gameObjectVariable = (variable as GameObjectVariable); condition = gameObjectVariable.Evaluate(compareOperator, gameObjectData.Value); } - else if (variable.GetType() == typeof(MaterialVariable)) + else if (t == typeof(MaterialVariable)) { MaterialVariable materialVariable = (variable as MaterialVariable); condition = materialVariable.Evaluate(compareOperator, materialData.Value); } - else if (variable.GetType() == typeof(ObjectVariable)) + else if (t == typeof(ObjectVariable)) { ObjectVariable objectVariable = (variable as ObjectVariable); condition = objectVariable.Evaluate(compareOperator, objectData.Value); } - else if (variable.GetType() == typeof(Rigidbody2DVariable)) + else if (t == typeof(Rigidbody2DVariable)) { Rigidbody2DVariable rigidbody2DVariable = (variable as Rigidbody2DVariable); condition = rigidbody2DVariable.Evaluate(compareOperator, rigidbody2DData.Value); } - else if (variable.GetType() == typeof(SpriteVariable)) + else if (t == typeof(SpriteVariable)) { SpriteVariable spriteVariable = (variable as SpriteVariable); condition = spriteVariable.Evaluate(compareOperator, spriteData.Value); } - else if (variable.GetType() == typeof(TextureVariable)) + else if (t == typeof(TextureVariable)) { TextureVariable textureVariable = (variable as TextureVariable); condition = textureVariable.Evaluate(compareOperator, textureData.Value); } - else if (variable.GetType() == typeof(TransformVariable)) + else if (t == typeof(TransformVariable)) { TransformVariable transformVariable = (variable as TransformVariable); condition = transformVariable.Evaluate(compareOperator, transformData.Value); } - else if (variable.GetType() == typeof(Vector2Variable)) + else if (t == typeof(Vector2Variable)) { Vector2Variable vector2Variable = (variable as Vector2Variable); condition = vector2Variable.Evaluate(compareOperator, vector2Data.Value); } - else if (variable.GetType() == typeof(Vector3Variable)) + else if (t == typeof(Vector3Variable)) { Vector3Variable vector3Variable = (variable as Vector3Variable); condition = vector3Variable.Evaluate(compareOperator, vector3Data.Value); @@ -209,70 +211,72 @@ namespace Fungus return "Error: No variable selected"; } + var t = variable.GetType(); + string summary = variable.Key + " "; summary += Condition.GetOperatorDescription(compareOperator) + " "; - if (variable.GetType() == typeof(BooleanVariable)) + if (t == typeof(BooleanVariable)) { summary += booleanData.GetDescription(); } - else if (variable.GetType() == typeof(IntegerVariable)) + else if (t == typeof(IntegerVariable)) { summary += integerData.GetDescription(); } - else if (variable.GetType() == typeof(FloatVariable)) + else if (t == typeof(FloatVariable)) { summary += floatData.GetDescription(); } - else if (variable.GetType() == typeof(StringVariable)) + else if (t == typeof(StringVariable)) { summary += stringData.GetDescription(); } - else if (variable.GetType() == typeof(AnimatorVariable)) + else if (t == typeof(AnimatorVariable)) { summary += animatorData.GetDescription(); } - else if (variable.GetType() == typeof(AudioSourceVariable)) + else if (t == typeof(AudioSourceVariable)) { summary += audioSourceData.GetDescription(); } - else if (variable.GetType() == typeof(ColorVariable)) + else if (t == typeof(ColorVariable)) { summary += colorData.GetDescription(); } - else if (variable.GetType() == typeof(GameObjectVariable)) + else if (t == typeof(GameObjectVariable)) { summary += gameObjectData.GetDescription(); } - else if (variable.GetType() == typeof(MaterialVariable)) + else if (t == typeof(MaterialVariable)) { summary += materialData.GetDescription(); } - else if (variable.GetType() == typeof(ObjectVariable)) + else if (t == typeof(ObjectVariable)) { summary += objectData.GetDescription(); } - else if (variable.GetType() == typeof(Rigidbody2DVariable)) + else if (t == typeof(Rigidbody2DVariable)) { summary += rigidbody2DData.GetDescription(); } - else if (variable.GetType() == typeof(SpriteVariable)) + else if (t == typeof(SpriteVariable)) { summary += spriteData.GetDescription(); } - else if (variable.GetType() == typeof(TextureVariable)) + else if (t == typeof(TextureVariable)) { summary += textureData.GetDescription(); } - else if (variable.GetType() == typeof(TransformVariable)) + else if (t == typeof(TransformVariable)) { summary += transformData.GetDescription(); } - else if (variable.GetType() == typeof(Vector2Variable)) + else if (t == typeof(Vector2Variable)) { summary += vector2Data.GetDescription(); } - else if (variable.GetType() == typeof(Vector3Variable)) + else if (t == typeof(Vector3Variable)) { summary += vector3Data.GetDescription(); } @@ -282,7 +286,77 @@ namespace Fungus public override bool HasReference(Variable variable) { - return (variable == this.variable); + bool retval = (variable == this.variable) || base.HasReference(variable); + + var t = variable.GetType(); + + //this is a nightmare + if (t == typeof(BooleanVariable)) + { + retval |= booleanData.booleanRef == variable; + } + else if (t == typeof(IntegerVariable)) + { + retval |= integerData.integerRef == variable; + } + else if (t == typeof(FloatVariable)) + { + retval |= floatData.floatRef == variable; + } + else if (t == typeof(StringVariable)) + { + retval |= stringData.stringRef == variable; + } + else if (t == typeof(AnimatorVariable)) + { + retval |= animatorData.animatorRef == variable; + } + else if (t == typeof(AudioSourceVariable)) + { + retval |= audioSourceData.audioSourceRef == variable; + } + else if (t == typeof(ColorVariable)) + { + retval |= colorData.colorRef == variable; + } + else if (t == typeof(GameObjectVariable)) + { + retval |= gameObjectData.gameObjectRef == variable; + } + else if (t == typeof(MaterialVariable)) + { + retval |= materialData.materialRef == variable; + } + else if (t == typeof(ObjectVariable)) + { + retval |= objectData.objectRef == variable; + } + else if (t == typeof(Rigidbody2DVariable)) + { + retval |= rigidbody2DData.rigidbody2DRef == variable; + } + else if (t == typeof(SpriteVariable)) + { + retval |= spriteData.spriteRef == variable; + } + else if (t == typeof(TextureVariable)) + { + retval |= textureData.textureRef == variable; + } + else if (t == typeof(TransformVariable)) + { + retval |= transformData.transformRef == variable; + } + else if (t == typeof(Vector2Variable)) + { + retval |= vector2Data.vector2Ref == variable; + } + else if (t == typeof(Vector3Variable)) + { + retval |= vector3Data.vector3Ref == variable; + } + + return retval; } public override Color GetButtonColor() diff --git a/Assets/Fungus/Scripts/Commands/Wait.cs b/Assets/Fungus/Scripts/Commands/Wait.cs index 6299217c..5c506688 100644 --- a/Assets/Fungus/Scripts/Commands/Wait.cs +++ b/Assets/Fungus/Scripts/Commands/Wait.cs @@ -41,6 +41,11 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return _duration.floatRef == variable || base.HasReference(variable); + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/WaitFrames.cs b/Assets/Fungus/Scripts/Commands/WaitFrames.cs index a099b0eb..5d041945 100644 --- a/Assets/Fungus/Scripts/Commands/WaitFrames.cs +++ b/Assets/Fungus/Scripts/Commands/WaitFrames.cs @@ -49,6 +49,11 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + return frameCount.integerRef == variable || base.HasReference(variable); + } + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Write.cs b/Assets/Fungus/Scripts/Commands/Write.cs index 297df887..34ff445e 100644 --- a/Assets/Fungus/Scripts/Commands/Write.cs +++ b/Assets/Fungus/Scripts/Commands/Write.cs @@ -155,6 +155,11 @@ namespace Fungus return "WRITE." + GetFlowchartLocalizationId() + "." + itemId; } + public override bool HasReference(Variable variable) + { + return text.stringRef == variable || setAlpha.floatRef == variable || setColor.colorRef == variable || base.HasReference(variable); + } + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/iTweenCommand.cs b/Assets/Fungus/Scripts/Commands/iTweenCommand.cs index 2bc8b0ac..b118b303 100644 --- a/Assets/Fungus/Scripts/Commands/iTweenCommand.cs +++ b/Assets/Fungus/Scripts/Commands/iTweenCommand.cs @@ -108,6 +108,12 @@ namespace Fungus return new Color32(233, 163, 180, 255); } + public override bool HasReference(Variable variable) + { + return _targetObject.gameObjectRef == variable || _tweenName.stringRef == variable || + base.HasReference(variable); + } + #endregion #region Backwards compatibility