Browse Source

made requested changes

master
vjs22334 5 years ago
parent
commit
921ba5ccd7
  1. 42
      Assets/Fungus/Scripts/Commands/VariableCondition.cs
  2. 15
      Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs
  3. 598
      Assets/FungusExamples/Conditions/MultipleConditionsExample.unity

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

@ -3,12 +3,16 @@
using UnityEngine;
using System.Collections.Generic;
using System.Text;
namespace Fungus
{
/// <summary>
/// class for a single condition. A list of this is used for multiple conditions.
/// </summary>
[System.Serializable]
public class conditionExpression
public class ConditionExpression
{
[SerializeField] protected CompareOperator compareOperator;
[SerializeField] protected AnyVariableAndDataPair anyVar;
@ -16,8 +20,8 @@ namespace Fungus
public virtual AnyVariableAndDataPair AnyVar { get { return anyVar; } }
public virtual CompareOperator CompareOperator { get { return compareOperator; } }
public conditionExpression(){}
public conditionExpression(CompareOperator op, AnyVariableAndDataPair variablePair)
public ConditionExpression(){}
public ConditionExpression(CompareOperator op, AnyVariableAndDataPair variablePair)
{
compareOperator = op;
@ -37,12 +41,12 @@ namespace Fungus
public abstract class VariableCondition : Condition, ISerializationCallbackReceiver
{
[Tooltip("The type of comparison to be performed")]
[Tooltip("Selecting \"Any One True\" will result in true if atleast one of the conditions is true. Selecting \"All True\" will result in true only when all the conditions are true.")]
[SerializeField] protected AnyOrAllConditions anyOrAllConditions;
[SerializeField] protected List<conditionExpression> conditions = new List<conditionExpression>();
[SerializeField] protected List<ConditionExpression> conditions = new List<ConditionExpression>();
/// <summary>
@ -55,12 +59,12 @@ namespace Fungus
if (conditions == null)
{
conditions = new List<conditionExpression>();
conditions = new List<ConditionExpression>();
}
if (conditions.Count == 0)
{
conditions.Add(new conditionExpression());
conditions.Add(new ConditionExpression());
}
}
@ -72,7 +76,7 @@ namespace Fungus
}
bool resultAny = false, resultAll = true;
foreach (conditionExpression condition in conditions)
foreach (ConditionExpression condition in conditions)
{
bool curResult = false;
if (condition.AnyVar == null)
@ -98,7 +102,7 @@ namespace Fungus
return false;
}
foreach (conditionExpression condition in conditions)
foreach (ConditionExpression condition in conditions)
{
if (condition.AnyVar == null || condition.AnyVar.variable == null)
{
@ -116,7 +120,7 @@ namespace Fungus
/// </summary>
public virtual CompareOperator CompareOperator { get { return conditions[0].CompareOperator; } }
public virtual List<conditionExpression> Conditions { get { return conditions; } }
public virtual List<ConditionExpression> Conditions { get { return conditions; } }
public override string GetSummary()
{
@ -125,29 +129,29 @@ namespace Fungus
return "Error: No variable selected";
}
string summary = "";
string connector = "";
if (anyOrAllConditions == AnyOrAllConditions.AnyOneTrue)
{
connector = " Or ";
connector = " <b>OR</b> ";
}
else
{
connector = " And ";
connector = " <b>AND</b> ";
}
StringBuilder summary = new StringBuilder("");
for (int i = 0 ; i < conditions.Count; i++)
{
summary += conditions[i].AnyVar.variable.Key + " ";
summary += VariableUtil.GetCompareOperatorDescription(conditions[i].CompareOperator) + " ";
summary += conditions[i].AnyVar.GetDataDescription();
summary.Append(conditions[i].AnyVar.variable.Key + " " +
VariableUtil.GetCompareOperatorDescription(conditions[i].CompareOperator) + " " +
conditions[i].AnyVar.GetDataDescription());
if (i < conditions.Count - 1)
{
summary += connector;
summary.Append(connector);
}
}
return summary;
return summary.ToString();
}
public override bool HasReference(Variable variable)
@ -318,7 +322,7 @@ namespace Fungus
if (anyVar != null && anyVar.variable != null)
{
conditionExpression c = new conditionExpression(compareOperator,anyVar);
ConditionExpression c = new ConditionExpression(compareOperator,anyVar);
if (!conditions.Contains(c))
{
conditions.Add(c);

15
Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs

@ -59,16 +59,11 @@ namespace Fungus.EditorUtils
EditorGUILayout.PropertyField(serializedObject.FindProperty("anyOrAllConditions"));
conditions.arraySize = EditorGUILayout.IntField("Size", conditions.arraySize);
GUILayout.Label("Conditions",EditorStyles.boldLabel);
for (int i = 0; i < conditions.arraySize; i++)
{
GUILayout.Label("Condition "+(i+1).ToString(),EditorStyles.boldLabel);
//uncomment this for indentation
// EditorGUI.indentLevel++;
EditorGUI.indentLevel++;
VariableCondition t = target as VariableCondition;
var flowchart = (Flowchart)t.GetFlowchart();
@ -110,12 +105,8 @@ namespace Fungus.EditorUtils
conditionCompare.enumValueIndex = selectedIndex;
}
//uncomment this for indentation
// EditorGUI.indentLevel--;
EditorGUI.indentLevel--;
GUILayout.Space(10f);
}
serializedObject.ApplyModifiedProperties();
}

598
Assets/FungusExamples/Conditions/MultipleConditionsExample.unity

@ -353,6 +353,12 @@ GameObject:
- component: {fileID: 1292574170}
- component: {fileID: 1292574169}
- component: {fileID: 1292574168}
- component: {fileID: 1292574186}
- component: {fileID: 1292574185}
- component: {fileID: 1292574184}
- component: {fileID: 1292574183}
- component: {fileID: 1292574182}
- component: {fileID: 1292574181}
m_Layer: 0
m_Name: Flowchart
m_TagString: Untagged
@ -723,12 +729,12 @@ MonoBehaviour:
serializedVersion: 2
x: 67
y: 70
width: 138.8
width: 109.2
height: 40
tint: {r: 1, g: 1, b: 1, a: 1}
useCustomTint: 0
itemId: 0
blockName: Conditions Test
blockName: If Example
description:
eventHandler: {fileID: 1292574164}
commandList:
@ -739,6 +745,7 @@ MonoBehaviour:
- {fileID: 1292574173}
- {fileID: 1292574168}
- {fileID: 1292574172}
- {fileID: 1292574185}
suppressAllAutoSelections: 0
--- !u!114 &1292574166
MonoBehaviour:
@ -766,7 +773,8 @@ MonoBehaviour:
height: 859
selectedBlocks:
- {fileID: 1292574165}
selectedCommands: []
selectedCommands:
- {fileID: 1292574163}
variables:
- {fileID: 1292574180}
- {fileID: 1292574179}
@ -1358,7 +1366,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
scope: 0
key: bar
value: xyz
value: preda2or
--- !u!114 &1292574176
MonoBehaviour:
m_ObjectHideFlags: 2
@ -1388,7 +1396,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
scope: 0
key: B
value: 10
value: 5
--- !u!114 &1292574178
MonoBehaviour:
m_ObjectHideFlags: 2
@ -1403,7 +1411,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
scope: 0
key: A
value: 11
value: 0
--- !u!114 &1292574179
MonoBehaviour:
m_ObjectHideFlags: 2
@ -1433,4 +1441,580 @@ MonoBehaviour:
m_EditorClassIdentifier:
scope: 0
key: boolx
value: 1
value: 0
--- !u!114 &1292574181
MonoBehaviour:
m_ObjectHideFlags: 2
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1292574162}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 93cb9773f2ca04e2bbf7a68ccfc23267, type: 3}
m_Name:
m_EditorClassIdentifier:
itemId: 17
indentLevel: 0
--- !u!114 &1292574182
MonoBehaviour:
m_ObjectHideFlags: 2
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1292574162}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fb77d0ce495044f6e9feb91b31798e8c, type: 3}
m_Name:
m_EditorClassIdentifier:
itemId: 16
indentLevel: 1
anyVar:
variable: {fileID: 1292574178}
data:
animatorData:
animatorRef: {fileID: 0}
animatorVal: {fileID: 0}
audioSourceData:
audioSourceRef: {fileID: 0}
audioSourceVal: {fileID: 0}
booleanData:
booleanRef: {fileID: 0}
booleanVal: 0
collectionData:
collectionRef: {fileID: 0}
collectionVal: {fileID: 0}
collider2DData:
collider2DRef: {fileID: 0}
collider2DVal: {fileID: 0}
colliderData:
colliderRef: {fileID: 0}
colliderVal: {fileID: 0}
colorData:
colorRef: {fileID: 0}
colorVal: {r: 0, g: 0, b: 0, a: 0}
floatData:
floatRef: {fileID: 0}
floatVal: 0
gameObjectData:
gameObjectRef: {fileID: 0}
gameObjectVal: {fileID: 0}
integerData:
integerRef: {fileID: 0}
integerVal: 1
materialData:
materialRef: {fileID: 0}
materialVal: {fileID: 0}
matrix4x4Data:
matrix4x4Ref: {fileID: 0}
matrix4x4Val:
e00: 0
e01: 0
e02: 0
e03: 0
e10: 0
e11: 0
e12: 0
e13: 0
e20: 0
e21: 0
e22: 0
e23: 0
e30: 0
e31: 0
e32: 0
e33: 0
objectData:
objectRef: {fileID: 0}
objectVal: {fileID: 0}
quaternionData:
quaternionRef: {fileID: 0}
quaternionVal: {x: 0, y: 0, z: 0, w: 0}
rigidbody2DData:
rigidbody2DRef: {fileID: 0}
rigidbody2DVal: {fileID: 0}
rigidbodyData:
rigidbodyRef: {fileID: 0}
rigidbodyVal: {fileID: 0}
spriteData:
spriteRef: {fileID: 0}
spriteVal: {fileID: 0}
stringData:
stringRef: {fileID: 0}
stringVal:
textureData:
textureRef: {fileID: 0}
textureVal: {fileID: 0}
transformData:
transformRef: {fileID: 0}
transformVal: {fileID: 0}
vector2Data:
vector2Ref: {fileID: 0}
vector2Val: {x: 0, y: 0}
vector3Data:
vector3Ref: {fileID: 0}
vector3Val: {x: 0, y: 0, z: 0}
vector4Data:
vector4Ref: {fileID: 0}
vector4Val: {x: 0, y: 0, z: 0, w: 0}
setOperator: 2
variable: {fileID: 0}
booleanData:
booleanRef: {fileID: 0}
booleanVal: 0
integerData:
integerRef: {fileID: 0}
integerVal: 0
floatData:
floatRef: {fileID: 0}
floatVal: 0
stringData:
stringRef: {fileID: 0}
stringVal:
animatorData:
animatorRef: {fileID: 0}
animatorVal: {fileID: 0}
audioSourceData:
audioSourceRef: {fileID: 0}
audioSourceVal: {fileID: 0}
colorData:
colorRef: {fileID: 0}
colorVal: {r: 0, g: 0, b: 0, a: 0}
gameObjectData:
gameObjectRef: {fileID: 0}
gameObjectVal: {fileID: 0}
materialData:
materialRef: {fileID: 0}
materialVal: {fileID: 0}
objectData:
objectRef: {fileID: 0}
objectVal: {fileID: 0}
rigidbody2DData:
rigidbody2DRef: {fileID: 0}
rigidbody2DVal: {fileID: 0}
spriteData:
spriteRef: {fileID: 0}
spriteVal: {fileID: 0}
textureData:
textureRef: {fileID: 0}
textureVal: {fileID: 0}
transformData:
transformRef: {fileID: 0}
transformVal: {fileID: 0}
vector2Data:
vector2Ref: {fileID: 0}
vector2Val: {x: 0, y: 0}
vector3Data:
vector3Ref: {fileID: 0}
vector3Val: {x: 0, y: 0, z: 0}
--- !u!114 &1292574183
MonoBehaviour:
m_ObjectHideFlags: 2
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1292574162}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ec422cd568a9c4a31ad7c36d0572b9da, type: 3}
m_Name:
m_EditorClassIdentifier:
itemId: 15
indentLevel: 1
storyText: Value of A = {$A}
description:
character: {fileID: 0}
portrait: {fileID: 0}
voiceOverClip: {fileID: 0}
showAlways: 1
showCount: 1
extendPrevious: 0
fadeWhenDone: 1
waitForClick: 1
stopVoiceover: 1
waitForVO: 0
setSayDialog: {fileID: 0}
--- !u!114 &1292574184
MonoBehaviour:
m_ObjectHideFlags: 2
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1292574162}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 663c8a7831a104d16ad7078a4dc2bd10, type: 3}
m_Name:
m_EditorClassIdentifier:
itemId: 14
indentLevel: 0
anyOrAllConditions: 1
conditions:
- compareOperator: 2
anyVar:
variable: {fileID: 1292574178}
data:
animatorData:
animatorRef: {fileID: 0}
animatorVal: {fileID: 0}
audioSourceData:
audioSourceRef: {fileID: 0}
audioSourceVal: {fileID: 0}
booleanData:
booleanRef: {fileID: 0}
booleanVal: 0
collectionData:
collectionRef: {fileID: 0}
collectionVal: {fileID: 0}
collider2DData:
collider2DRef: {fileID: 0}
collider2DVal: {fileID: 0}
colliderData:
colliderRef: {fileID: 0}
colliderVal: {fileID: 0}
colorData:
colorRef: {fileID: 0}
colorVal: {r: 0, g: 0, b: 0, a: 0}
floatData:
floatRef: {fileID: 0}
floatVal: 0
gameObjectData:
gameObjectRef: {fileID: 0}
gameObjectVal: {fileID: 0}
integerData:
integerRef: {fileID: 0}
integerVal: 5
materialData:
materialRef: {fileID: 0}
materialVal: {fileID: 0}
matrix4x4Data:
matrix4x4Ref: {fileID: 0}
matrix4x4Val:
e00: 0
e01: 0
e02: 0
e03: 0
e10: 0
e11: 0
e12: 0
e13: 0
e20: 0
e21: 0
e22: 0
e23: 0
e30: 0
e31: 0
e32: 0
e33: 0
objectData:
objectRef: {fileID: 0}
objectVal: {fileID: 0}
quaternionData:
quaternionRef: {fileID: 0}
quaternionVal: {x: 0, y: 0, z: 0, w: 0}
rigidbody2DData:
rigidbody2DRef: {fileID: 0}
rigidbody2DVal: {fileID: 0}
rigidbodyData:
rigidbodyRef: {fileID: 0}
rigidbodyVal: {fileID: 0}
spriteData:
spriteRef: {fileID: 0}
spriteVal: {fileID: 0}
stringData:
stringRef: {fileID: 0}
stringVal:
textureData:
textureRef: {fileID: 0}
textureVal: {fileID: 0}
transformData:
transformRef: {fileID: 0}
transformVal: {fileID: 0}
vector2Data:
vector2Ref: {fileID: 0}
vector2Val: {x: 0, y: 0}
vector3Data:
vector3Ref: {fileID: 0}
vector3Val: {x: 0, y: 0, z: 0}
vector4Data:
vector4Ref: {fileID: 0}
vector4Val: {x: 0, y: 0, z: 0, w: 0}
- compareOperator: 0
anyVar:
variable: {fileID: 1292574180}
data:
animatorData:
animatorRef: {fileID: 0}
animatorVal: {fileID: 0}
audioSourceData:
audioSourceRef: {fileID: 0}
audioSourceVal: {fileID: 0}
booleanData:
booleanRef: {fileID: 1292574179}
booleanVal: 0
collectionData:
collectionRef: {fileID: 0}
collectionVal: {fileID: 0}
collider2DData:
collider2DRef: {fileID: 0}
collider2DVal: {fileID: 0}
colliderData:
colliderRef: {fileID: 0}
colliderVal: {fileID: 0}
colorData:
colorRef: {fileID: 0}
colorVal: {r: 0, g: 0, b: 0, a: 0}
floatData:
floatRef: {fileID: 0}
floatVal: 0
gameObjectData:
gameObjectRef: {fileID: 0}
gameObjectVal: {fileID: 0}
integerData:
integerRef: {fileID: 0}
integerVal: 0
materialData:
materialRef: {fileID: 0}
materialVal: {fileID: 0}
matrix4x4Data:
matrix4x4Ref: {fileID: 0}
matrix4x4Val:
e00: 0
e01: 0
e02: 0
e03: 0
e10: 0
e11: 0
e12: 0
e13: 0
e20: 0
e21: 0
e22: 0
e23: 0
e30: 0
e31: 0
e32: 0
e33: 0
objectData:
objectRef: {fileID: 0}
objectVal: {fileID: 0}
quaternionData:
quaternionRef: {fileID: 0}
quaternionVal: {x: 0, y: 0, z: 0, w: 0}
rigidbody2DData:
rigidbody2DRef: {fileID: 0}
rigidbody2DVal: {fileID: 0}
rigidbodyData:
rigidbodyRef: {fileID: 0}
rigidbodyVal: {fileID: 0}
spriteData:
spriteRef: {fileID: 0}
spriteVal: {fileID: 0}
stringData:
stringRef: {fileID: 0}
stringVal:
textureData:
textureRef: {fileID: 0}
textureVal: {fileID: 0}
transformData:
transformRef: {fileID: 0}
transformVal: {fileID: 0}
vector2Data:
vector2Ref: {fileID: 0}
vector2Val: {x: 0, y: 0}
vector3Data:
vector3Ref: {fileID: 0}
vector3Val: {x: 0, y: 0, z: 0}
vector4Data:
vector4Ref: {fileID: 0}
vector4Val: {x: 0, y: 0, z: 0, w: 0}
compareOperator: 0
anyVar:
variable: {fileID: 0}
data:
animatorData:
animatorRef: {fileID: 0}
animatorVal: {fileID: 0}
audioSourceData:
audioSourceRef: {fileID: 0}
audioSourceVal: {fileID: 0}
booleanData:
booleanRef: {fileID: 0}
booleanVal: 0
collectionData:
collectionRef: {fileID: 0}
collectionVal: {fileID: 0}
collider2DData:
collider2DRef: {fileID: 0}
collider2DVal: {fileID: 0}
colliderData:
colliderRef: {fileID: 0}
colliderVal: {fileID: 0}
colorData:
colorRef: {fileID: 0}
colorVal: {r: 0, g: 0, b: 0, a: 0}
floatData:
floatRef: {fileID: 0}
floatVal: 0
gameObjectData:
gameObjectRef: {fileID: 0}
gameObjectVal: {fileID: 0}
integerData:
integerRef: {fileID: 0}
integerVal: 0
materialData:
materialRef: {fileID: 0}
materialVal: {fileID: 0}
matrix4x4Data:
matrix4x4Ref: {fileID: 0}
matrix4x4Val:
e00: 0
e01: 0
e02: 0
e03: 0
e10: 0
e11: 0
e12: 0
e13: 0
e20: 0
e21: 0
e22: 0
e23: 0
e30: 0
e31: 0
e32: 0
e33: 0
objectData:
objectRef: {fileID: 0}
objectVal: {fileID: 0}
quaternionData:
quaternionRef: {fileID: 0}
quaternionVal: {x: 0, y: 0, z: 0, w: 0}
rigidbody2DData:
rigidbody2DRef: {fileID: 0}
rigidbody2DVal: {fileID: 0}
rigidbodyData:
rigidbodyRef: {fileID: 0}
rigidbodyVal: {fileID: 0}
spriteData:
spriteRef: {fileID: 0}
spriteVal: {fileID: 0}
stringData:
stringRef: {fileID: 0}
stringVal:
textureData:
textureRef: {fileID: 0}
textureVal: {fileID: 0}
transformData:
transformRef: {fileID: 0}
transformVal: {fileID: 0}
vector2Data:
vector2Ref: {fileID: 0}
vector2Val: {x: 0, y: 0}
vector3Data:
vector3Ref: {fileID: 0}
vector3Val: {x: 0, y: 0, z: 0}
vector4Data:
vector4Ref: {fileID: 0}
vector4Val: {x: 0, y: 0, z: 0, w: 0}
variable: {fileID: 0}
booleanData:
booleanRef: {fileID: 0}
booleanVal: 0
integerData:
integerRef: {fileID: 0}
integerVal: 0
floatData:
floatRef: {fileID: 0}
floatVal: 0
stringData:
stringRef: {fileID: 0}
stringVal:
animatorData:
animatorRef: {fileID: 0}
animatorVal: {fileID: 0}
audioSourceData:
audioSourceRef: {fileID: 0}
audioSourceVal: {fileID: 0}
colorData:
colorRef: {fileID: 0}
colorVal: {r: 0, g: 0, b: 0, a: 0}
gameObjectData:
gameObjectRef: {fileID: 0}
gameObjectVal: {fileID: 0}
materialData:
materialRef: {fileID: 0}
materialVal: {fileID: 0}
objectData:
objectRef: {fileID: 0}
objectVal: {fileID: 0}
rigidbody2DData:
rigidbody2DRef: {fileID: 0}
rigidbody2DVal: {fileID: 0}
spriteData:
spriteRef: {fileID: 0}
spriteVal: {fileID: 0}
textureData:
textureRef: {fileID: 0}
textureVal: {fileID: 0}
transformData:
transformRef: {fileID: 0}
transformVal: {fileID: 0}
vector2Data:
vector2Ref: {fileID: 0}
vector2Val: {x: 0, y: 0}
vector3Data:
vector3Ref: {fileID: 0}
vector3Val: {x: 0, y: 0, z: 0}
--- !u!114 &1292574185
MonoBehaviour:
m_ObjectHideFlags: 2
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1292574162}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 050fb9e6e72f442b3b883da8a965bdeb, type: 3}
m_Name:
m_EditorClassIdentifier:
itemId: 13
indentLevel: 0
targetFlowchart: {fileID: 0}
targetBlock: {fileID: 1292574186}
startLabel:
stringRef: {fileID: 0}
stringVal:
startIndex: 0
callMode: 0
--- !u!114 &1292574186
MonoBehaviour:
m_ObjectHideFlags: 2
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1292574162}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3d3d73aef2cfc4f51abf34ac00241f60, type: 3}
m_Name:
m_EditorClassIdentifier:
nodeRect:
serializedVersion: 2
x: 229
y: 70
width: 131.6
height: 40
tint: {r: 1, g: 1, b: 1, a: 1}
useCustomTint: 0
itemId: 12
blockName: While Example
description:
eventHandler: {fileID: 0}
commandList:
- {fileID: 1292574184}
- {fileID: 1292574183}
- {fileID: 1292574182}
- {fileID: 1292574181}
suppressAllAutoSelections: 0

Loading…
Cancel
Save