An easy to use Unity 3D library for creating illustrated Interactive Fiction games and more.
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.

95 lines
3.6 KiB

// 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)
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
using Fungus.Commands;
using Fungus.Variables;
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()
{
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();
If t = target as If;
var 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();
}
}
}