Browse Source

Merge branch 'hotfix/841'

master
Steve Halliwell 4 years ago
parent
commit
870256b4c1
  1. 14
      Assets/Fungus/Scripts/Commands/SetVariable.cs
  2. 18
      Assets/Fungus/Scripts/Commands/VariableCondition.cs
  3. 6
      Assets/Fungus/Scripts/Components/Variable.cs
  4. 29
      Assets/Fungus/Scripts/Utils/AllVariableTypes.cs
  5. 1208
      Assets/Tests/String SetVar Concat.unity
  6. 7
      Assets/Tests/String SetVar Concat.unity.meta

14
Assets/Fungus/Scripts/Commands/SetVariable.cs

@ -71,6 +71,20 @@ namespace Fungus
#endregion
#region Editor caches
#if UNITY_EDITOR
protected override void RefreshVariableCache()
{
base.RefreshVariableCache();
if(anyVar != null)
anyVar.RefreshVariableCacheHelper(GetFlowchart(), ref referencedVariables);
}
#endif
#endregion Editor caches
#region backwards compat

18
Assets/Fungus/Scripts/Commands/VariableCondition.cs

@ -144,6 +144,24 @@ namespace Fungus
}
#region Editor caches
#if UNITY_EDITOR
protected override void RefreshVariableCache()
{
base.RefreshVariableCache();
if (conditions != null)
{
foreach (var item in conditions)
{
item.AnyVar.RefreshVariableCacheHelper(GetFlowchart(), ref referencedVariables);
}
}
}
#endif
#endregion Editor caches
#region backwards compat
[HideInInspector]

6
Assets/Fungus/Scripts/Components/Variable.cs

@ -161,6 +161,12 @@ namespace Fungus
/// Not recommended for direct use, primarily intended for use in editor code.
/// </summary>
public abstract object GetValue();
//we are required to be on a flowchart so we provide this as a helper
public virtual Flowchart GetFlowchart()
{
return GetComponent<Flowchart>();
}
#endregion
}

29
Assets/Fungus/Scripts/Utils/AllVariableTypes.cs

@ -57,6 +57,9 @@ namespace Fungus
///
/// New types created need to be added to the list below and also to AllVariableTypes and
/// AnyVaraibleAndDataPair
///
/// Note; when using this in a command ensure that RefreshVariableCache is also handled for
/// string var substitution.
/// </summary>
[System.Serializable]
public partial struct AnyVariableData
@ -121,6 +124,9 @@ namespace Fungus
///
/// New types created need to be added to the list below and also to AllVariableTypes and
/// AnyVariableData
///
/// Note to ensure use of RefreshVariableCacheHelper in commands, see SetVariable for
/// example.
/// </summary>
[System.Serializable]
public class AnyVariableAndDataPair
@ -243,9 +249,17 @@ namespace Fungus
(anyVar, setOperator) => anyVar.variable.Apply(setOperator, anyVar.data.spriteData.Value)) },
{ typeof(StringVariable),
new TypeActions( "stringData",
(anyVar, compareOperator) => {return anyVar.variable.Evaluate(compareOperator, anyVar.data.stringData.Value); },
(anyVar, compareOperator) =>
{
var subbedRHS = anyVar.variable.GetFlowchart().SubstituteVariables(anyVar.data.stringData.Value);
return anyVar.variable.Evaluate(compareOperator, subbedRHS);
},
(anyVar) => anyVar.data.stringData.GetDescription(),
(anyVar, setOperator) => anyVar.variable.Apply(setOperator, anyVar.data.stringData.Value)) },
(anyVar, setOperator) =>
{
var subbedRHS = anyVar.variable.GetFlowchart().SubstituteVariables(anyVar.data.stringData.Value);
anyVar.variable.Apply(setOperator, subbedRHS);
})},
{ typeof(TextureVariable),
new TypeActions( "textureData",
(anyVar, compareOperator) => {return anyVar.variable.Evaluate(compareOperator, anyVar.data.textureData.Value); },
@ -278,6 +292,17 @@ namespace Fungus
return variable == this.variable || data.HasReference(variable);
}
#if UNITY_EDITOR
public void RefreshVariableCacheHelper(Flowchart f, ref List<Variable> referencedVariables)
{
if (variable is StringVariable asStringVar && asStringVar != null && !string.IsNullOrEmpty(asStringVar.Value))
f.DetermineSubstituteVariables(asStringVar.Value, referencedVariables);
if (!string.IsNullOrEmpty(data.stringData.Value))
f.DetermineSubstituteVariables(data.stringData.Value, referencedVariables);
}
#endif
public string GetDataDescription()
{
TypeActions ta = null;

1208
Assets/Tests/String SetVar Concat.unity

File diff suppressed because it is too large Load Diff

7
Assets/Tests/String SetVar Concat.unity.meta

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7cbab126c463cee43a352a5be69ba65c
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save