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.
93 lines
3.6 KiB
93 lines
3.6 KiB
8 years ago
|
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
|
||
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
|
||
9 years ago
|
|
||
10 years ago
|
using UnityEditor;
|
||
|
using UnityEngine;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
8 years ago
|
namespace Fungus.EditorUtils
|
||
10 years ago
|
{
|
||
7 years ago
|
[CustomEditor (typeof(VariableCondition), true)]
|
||
|
public class VariableConditionEditor : CommandEditor
|
||
8 years ago
|
{
|
||
|
protected SerializedProperty variableProp;
|
||
|
protected SerializedProperty compareOperatorProp;
|
||
|
protected SerializedProperty booleanDataProp;
|
||
|
protected SerializedProperty integerDataProp;
|
||
|
protected SerializedProperty floatDataProp;
|
||
|
protected SerializedProperty stringDataProp;
|
||
|
|
||
|
protected virtual void OnEnable()
|
||
|
{
|
||
|
if (NullTargetCheck()) // Check for an orphaned editor instance
|
||
|
return;
|
||
|
|
||
|
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();
|
||
|
|
||
7 years ago
|
VariableCondition t = target as VariableCondition;
|
||
8 years ago
|
|
||
8 years ago
|
var flowchart = (Flowchart)t.GetFlowchart();
|
||
8 years ago
|
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();
|
||
|
}
|
||
|
}
|
||
10 years ago
|
}
|