You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.7 KiB
90 lines
2.7 KiB
using UnityEditor; |
|
using UnityEngine; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using System.Reflection; |
|
|
|
namespace Fungus |
|
{ |
|
|
|
[CustomEditor (typeof(If), true)] |
|
public class IfEditor : CommandEditor |
|
{ |
|
protected SerializedProperty variableProp; |
|
protected SerializedProperty compareOperatorProp; |
|
protected SerializedProperty booleanDataProp; |
|
protected SerializedProperty integerDataProp; |
|
protected SerializedProperty floatDataProp; |
|
protected SerializedProperty stringDataProp; |
|
|
|
protected virtual void OnEnable() |
|
{ |
|
variableProp = serializedObject.FindProperty("variable"); |
|
compareOperatorProp = serializedObject.FindProperty("compareOperator"); |
|
booleanDataProp = serializedObject.FindProperty("booleanData"); |
|
integerDataProp = serializedObject.FindProperty("integerData"); |
|
floatDataProp = serializedObject.FindProperty("floatData"); |
|
stringDataProp = serializedObject.FindProperty("stringData"); |
|
} |
|
|
|
public override void DrawCommandGUI() |
|
{ |
|
serializedObject.Update(); |
|
|
|
If t = target as If; |
|
|
|
Flowchart flowchart = t.GetFlowchart(); |
|
if (flowchart == null) |
|
{ |
|
return; |
|
} |
|
|
|
EditorGUILayout.PropertyField(variableProp); |
|
|
|
if (variableProp.objectReferenceValue == null) |
|
{ |
|
serializedObject.ApplyModifiedProperties(); |
|
return; |
|
} |
|
|
|
Variable selectedVariable = variableProp.objectReferenceValue as Variable; |
|
System.Type variableType = selectedVariable.GetType(); |
|
|
|
List<GUIContent> operatorList = new List<GUIContent>(); |
|
operatorList.Add(new GUIContent("==")); |
|
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"), |
|
compareOperatorProp.enumValueIndex, |
|
operatorList.ToArray()); |
|
|
|
if (variableType == typeof(BooleanVariable)) |
|
{ |
|
EditorGUILayout.PropertyField(booleanDataProp); |
|
} |
|
else if (variableType == typeof(IntegerVariable)) |
|
{ |
|
EditorGUILayout.PropertyField(integerDataProp); |
|
} |
|
else if (variableType == typeof(FloatVariable)) |
|
{ |
|
EditorGUILayout.PropertyField(floatDataProp); |
|
} |
|
else if (variableType == typeof(StringVariable)) |
|
{ |
|
EditorGUILayout.PropertyField(stringDataProp); |
|
} |
|
|
|
serializedObject.ApplyModifiedProperties(); |
|
} |
|
} |
|
|
|
}
|
|
|