|
|
@ -12,10 +12,8 @@ namespace Fungus.EditorUtils |
|
|
|
{ |
|
|
|
{ |
|
|
|
protected SerializedProperty variableProp; |
|
|
|
protected SerializedProperty variableProp; |
|
|
|
protected SerializedProperty compareOperatorProp; |
|
|
|
protected SerializedProperty compareOperatorProp; |
|
|
|
protected SerializedProperty booleanDataProp; |
|
|
|
|
|
|
|
protected SerializedProperty integerDataProp; |
|
|
|
protected Dictionary<System.Type, SerializedProperty> propByVariableType; |
|
|
|
protected SerializedProperty floatDataProp; |
|
|
|
|
|
|
|
protected SerializedProperty stringDataProp; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnEnable() |
|
|
|
protected virtual void OnEnable() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -24,10 +22,15 @@ namespace Fungus.EditorUtils |
|
|
|
|
|
|
|
|
|
|
|
variableProp = serializedObject.FindProperty("variable"); |
|
|
|
variableProp = serializedObject.FindProperty("variable"); |
|
|
|
compareOperatorProp = serializedObject.FindProperty("compareOperator"); |
|
|
|
compareOperatorProp = serializedObject.FindProperty("compareOperator"); |
|
|
|
booleanDataProp = serializedObject.FindProperty("booleanData"); |
|
|
|
|
|
|
|
integerDataProp = serializedObject.FindProperty("integerData"); |
|
|
|
// Get variable data props by name |
|
|
|
floatDataProp = serializedObject.FindProperty("floatData"); |
|
|
|
propByVariableType = new Dictionary<System.Type, SerializedProperty>() { |
|
|
|
stringDataProp = serializedObject.FindProperty("stringData"); |
|
|
|
{ typeof(BooleanVariable), serializedObject.FindProperty("booleanData") }, |
|
|
|
|
|
|
|
{ typeof(IntegerVariable), serializedObject.FindProperty("integerData") }, |
|
|
|
|
|
|
|
{ typeof(FloatVariable), serializedObject.FindProperty("floatData") }, |
|
|
|
|
|
|
|
{ typeof(StringVariable), serializedObject.FindProperty("stringData") }, |
|
|
|
|
|
|
|
{ typeof(GameObjectVariable), serializedObject.FindProperty("gameObjectData") } |
|
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override void DrawCommandGUI() |
|
|
|
public override void DrawCommandGUI() |
|
|
@ -42,6 +45,7 @@ namespace Fungus.EditorUtils |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Select Variable |
|
|
|
EditorGUILayout.PropertyField(variableProp); |
|
|
|
EditorGUILayout.PropertyField(variableProp); |
|
|
|
|
|
|
|
|
|
|
|
if (variableProp.objectReferenceValue == null) |
|
|
|
if (variableProp.objectReferenceValue == null) |
|
|
@ -50,42 +54,61 @@ namespace Fungus.EditorUtils |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get selected variable |
|
|
|
Variable selectedVariable = variableProp.objectReferenceValue as Variable; |
|
|
|
Variable selectedVariable = variableProp.objectReferenceValue as Variable; |
|
|
|
System.Type variableType = selectedVariable.GetType(); |
|
|
|
System.Type variableType = selectedVariable.GetType(); |
|
|
|
|
|
|
|
|
|
|
|
List<GUIContent> operatorList = new List<GUIContent>(); |
|
|
|
// Get operators for the variable |
|
|
|
operatorList.Add(new GUIContent("==")); |
|
|
|
CompareOperator[] compareOperators = VariableCondition.operatorsByVariableType[variableType]; |
|
|
|
operatorList.Add(new GUIContent("!=")); |
|
|
|
|
|
|
|
if (variableType == typeof(IntegerVariable) || |
|
|
|
|
|
|
|
variableType == typeof(FloatVariable)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
operatorList.Add(new GUIContent("<")); |
|
|
|
|
|
|
|
operatorList.Add(new GUIContent(">")); |
|
|
|
|
|
|
|
operatorList.Add(new GUIContent("<=")); |
|
|
|
|
|
|
|
operatorList.Add(new GUIContent(">=")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
compareOperatorProp.enumValueIndex = EditorGUILayout.Popup(new GUIContent("Compare", "The comparison operator to use when comparing values"), |
|
|
|
// Create operator list |
|
|
|
compareOperatorProp.enumValueIndex, |
|
|
|
List<GUIContent> operatorsList = new List<GUIContent>(); |
|
|
|
operatorList.ToArray()); |
|
|
|
foreach (var compareOperator in compareOperators) |
|
|
|
|
|
|
|
|
|
|
|
if (variableType == typeof(BooleanVariable)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
EditorGUILayout.PropertyField(booleanDataProp); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (variableType == typeof(IntegerVariable)) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
EditorGUILayout.PropertyField(integerDataProp); |
|
|
|
switch (compareOperator) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case CompareOperator.Equals: |
|
|
|
|
|
|
|
operatorsList.Add(new GUIContent("==")); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CompareOperator.NotEquals: |
|
|
|
|
|
|
|
operatorsList.Add(new GUIContent("!=")); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CompareOperator.LessThan: |
|
|
|
|
|
|
|
operatorsList.Add(new GUIContent("<")); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CompareOperator.GreaterThan: |
|
|
|
|
|
|
|
operatorsList.Add(new GUIContent(">")); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CompareOperator.LessThanOrEquals: |
|
|
|
|
|
|
|
operatorsList.Add(new GUIContent("<=")); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CompareOperator.GreaterThanOrEquals: |
|
|
|
|
|
|
|
operatorsList.Add(new GUIContent(">=")); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
Debug.LogError("The " + compareOperator.ToString() + " operator has no matching GUIContent."); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (variableType == typeof(FloatVariable)) |
|
|
|
|
|
|
|
{ |
|
|
|
// Get previously selected operator |
|
|
|
EditorGUILayout.PropertyField(floatDataProp); |
|
|
|
int selectedIndex = System.Array.IndexOf(compareOperators, t._CompareOperator); |
|
|
|
} |
|
|
|
if (selectedIndex < 0) |
|
|
|
else if (variableType == typeof(StringVariable)) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
EditorGUILayout.PropertyField(stringDataProp); |
|
|
|
// Default to first index if the operator is not found in the available operators list |
|
|
|
|
|
|
|
// This can occur when changing between variable types |
|
|
|
|
|
|
|
selectedIndex = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selectedIndex = EditorGUILayout.Popup( |
|
|
|
|
|
|
|
new GUIContent("Compare", "The comparison operator to use when comparing values"), |
|
|
|
|
|
|
|
selectedIndex, |
|
|
|
|
|
|
|
operatorsList.ToArray()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
compareOperatorProp.enumValueIndex = (int)compareOperators[selectedIndex]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.PropertyField(propByVariableType[variableType]); |
|
|
|
|
|
|
|
|
|
|
|
serializedObject.ApplyModifiedProperties(); |
|
|
|
serializedObject.ApplyModifiedProperties(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|