Browse Source

Converted SetVariable and If to use serialized property

master
chrisgregan 10 years ago
parent
commit
b547553c20
  1. BIN
      Assets/Example/Scenes/Example.unity
  2. 4
      Assets/Fungus/Dialog/Commands/Say.cs
  3. 1
      Assets/Fungus/Dialog/Editor/SayEditor.cs
  4. 9
      Assets/Fungus/FungusScript/Editor/FungusVariableEditor.cs
  5. 69
      Assets/Fungus/FungusScript/Editor/IfEditor.cs
  6. 70
      Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs

BIN
Assets/Example/Scenes/Example.unity

Binary file not shown.

4
Assets/Fungus/Dialog/Commands/Say.cs

@ -10,8 +10,10 @@ namespace Fungus.Script
"Writes a line of story text to the dialog. A list of options can be specified for the player to choose from. Use a non-zero timeout to give the player a limited time to choose.")]
public class Say : FungusCommand
{
public Character character;
[TextArea(5,10)]
public string storyText;
public Character character;
public AudioClip voiceOverClip;
public bool showOnce;
int executionCount;

1
Assets/Fungus/Dialog/Editor/SayEditor.cs

@ -48,7 +48,6 @@ namespace Fungus.Script
serializedObject.Update();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel(new GUIContent("Say Text", "Text to display in dialog"));
GUILayout.FlexibleSpace();
if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton)))
{

9
Assets/Fungus/FungusScript/Editor/FungusVariableEditor.cs

@ -17,7 +17,7 @@ namespace Fungus.Script
t.hideFlags = HideFlags.HideInInspector;
}
static public FungusVariable VariableField(GUIContent label, FungusScript fungusScript, FungusVariable variable, Func<FungusVariable, bool> filter = null)
static public void VariableField(SerializedProperty property, GUIContent label, FungusScript fungusScript, Func<FungusVariable, bool> filter = null)
{
List<string> variableKeys = new List<string>();
List<FungusVariable> variableObjects = new List<FungusVariable>();
@ -28,6 +28,9 @@ namespace Fungus.Script
List<FungusVariable> variables = fungusScript.variables;
int index = 0;
int selectedIndex = 0;
FungusVariable selectedVariable = property.objectReferenceValue as FungusVariable;
foreach (FungusVariable v in variables)
{
if (filter != null)
@ -43,7 +46,7 @@ namespace Fungus.Script
index++;
if (v == variable)
if (v == selectedVariable)
{
selectedIndex = index;
}
@ -51,7 +54,7 @@ namespace Fungus.Script
selectedIndex = EditorGUILayout.Popup(label.text, selectedIndex, variableKeys.ToArray());
return variableObjects[selectedIndex];
property.objectReferenceValue = variableObjects[selectedIndex];
}
}

69
Assets/Fungus/FungusScript/Editor/IfEditor.cs

@ -9,6 +9,23 @@ namespace Fungus.Script
[CustomEditor (typeof(If))]
public class IfEditor : FungusCommandEditor
{
SerializedProperty variableProp;
SerializedProperty compareOperatorProp;
SerializedProperty booleanValueProp;
SerializedProperty integerValueProp;
SerializedProperty floatValueProp;
SerializedProperty stringValueProp;
void OnEnable()
{
variableProp = serializedObject.FindProperty("variable");
compareOperatorProp = serializedObject.FindProperty("compareOperator");
booleanValueProp = serializedObject.FindProperty("booleanValue");
integerValueProp = serializedObject.FindProperty("integerValue");
floatValueProp = serializedObject.FindProperty("floatValue");
stringValueProp = serializedObject.FindProperty("stringValue");
}
public override void DrawCommandGUI()
{
serializedObject.Update();
@ -21,27 +38,25 @@ namespace Fungus.Script
return;
}
FungusVariable fungusVariable = FungusVariableEditor.VariableField(new GUIContent("Variable", "Variable to use in operation"),
t.GetFungusScript(),
t.variable,
null);
if (fungusVariable != t.variable)
{
Undo.RecordObject(t, "Select Variable");
t.variable = fungusVariable;
}
FungusVariableEditor.VariableField(variableProp,
new GUIContent("Variable", "Variable to use in operation"),
t.GetFungusScript(),
null);
if (t.variable == null)
if (variableProp.objectReferenceValue == null)
{
serializedObject.ApplyModifiedProperties();
return;
}
FungusVariable selectedVariable = variableProp.objectReferenceValue as FungusVariable;
System.Type variableType = selectedVariable.GetType();
List<GUIContent> operatorList = new List<GUIContent>();
operatorList.Add(new GUIContent("=="));
operatorList.Add(new GUIContent("!="));
if (t.variable.GetType() == typeof(IntegerVariable) ||
t.variable.GetType() == typeof(FloatVariable))
if (variableType == typeof(IntegerVariable) ||
variableType == typeof(FloatVariable))
{
operatorList.Add(new GUIContent("<"));
operatorList.Add(new GUIContent(">"));
@ -49,31 +64,25 @@ namespace Fungus.Script
operatorList.Add(new GUIContent(">="));
}
CompareOperator compareOperator = (CompareOperator)EditorGUILayout.Popup(new GUIContent("Compare",
"The comparison operator to use when comparing values"),
(int)t.compareOperator,
operatorList.ToArray());
if (compareOperator != t.compareOperator)
{
Undo.RecordObject(t, "Select Compare Operator");
t.compareOperator = compareOperator;
}
compareOperatorProp.enumValueIndex = EditorGUILayout.Popup(new GUIContent("Compare", "The comparison operator to use when comparing values"),
compareOperatorProp.enumValueIndex,
operatorList.ToArray());
if (t.variable.GetType() == typeof(BooleanVariable))
if (variableType == typeof(BooleanVariable))
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("booleanValue"));
EditorGUILayout.PropertyField(booleanValueProp);
}
else if (t.variable.GetType() == typeof(IntegerVariable))
else if (variableType == typeof(IntegerVariable))
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("integerValue"));
EditorGUILayout.PropertyField(integerValueProp);
}
else if (t.variable.GetType() == typeof(FloatVariable))
else if (variableType == typeof(FloatVariable))
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("floatValue"));
EditorGUILayout.PropertyField(floatValueProp);
}
else if (t.variable.GetType() == typeof(StringVariable))
else if (variableType == typeof(StringVariable))
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("stringValue"));
EditorGUILayout.PropertyField(stringValueProp);
}
serializedObject.ApplyModifiedProperties();

70
Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs

@ -9,6 +9,23 @@ namespace Fungus.Script
[CustomEditor (typeof(SetVariable))]
public class SetVariableEditor : FungusCommandEditor
{
SerializedProperty variableProp;
SerializedProperty setOperatorProp;
SerializedProperty booleanDataProp;
SerializedProperty integerDataProp;
SerializedProperty floatDataProp;
SerializedProperty stringDataProp;
void OnEnable()
{
variableProp = serializedObject.FindProperty("variable");
setOperatorProp = serializedObject.FindProperty("setOperator");
booleanDataProp = serializedObject.FindProperty("booleanData");
integerDataProp = serializedObject.FindProperty("integerData");
floatDataProp = serializedObject.FindProperty("floatData");
stringDataProp = serializedObject.FindProperty("stringData");
}
public override void DrawCommandGUI()
{
serializedObject.Update();
@ -21,29 +38,28 @@ namespace Fungus.Script
return;
}
FungusVariable variable = FungusVariableEditor.VariableField(new GUIContent("Variable", "Variable to set"),
fungusScript,
t.variable);
FungusVariableEditor.VariableField(variableProp,
new GUIContent("Variable", "Variable to set"),
fungusScript);
if (variable != t.variable)
{
Undo.RecordObject(t, "Set Variable Key");
t.variable = variable;
}
if (t.variable == null)
if (variableProp.objectReferenceValue == null)
{
serializedObject.ApplyModifiedProperties();
return;
}
FungusVariable selectedVariable = variableProp.objectReferenceValue as FungusVariable;
System.Type variableType = selectedVariable.GetType();
List<GUIContent> operatorsList = new List<GUIContent>();
operatorsList.Add(new GUIContent("="));
if (variable.GetType() == typeof(BooleanVariable))
if (variableType == typeof(BooleanVariable))
{
operatorsList.Add(new GUIContent("!"));
}
else if (variable.GetType() == typeof(IntegerVariable) ||
variable.GetType() == typeof(FloatVariable))
else if (variableType == typeof(IntegerVariable) ||
variableType == typeof(FloatVariable))
{
operatorsList.Add(new GUIContent("+="));
operatorsList.Add(new GUIContent("-="));
@ -78,8 +94,8 @@ namespace Fungus.Script
selectedIndex = EditorGUILayout.Popup(new GUIContent("Operator", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray());
SetVariable.SetOperator setOperator = SetVariable.SetOperator.Assign;
if (variable.GetType() == typeof(BooleanVariable) ||
variable.GetType() == typeof(StringVariable))
if (variableType == typeof(BooleanVariable) ||
variableType == typeof(StringVariable))
{
switch (selectedIndex)
{
@ -92,8 +108,8 @@ namespace Fungus.Script
break;
}
}
else if (variable.GetType() == typeof(IntegerVariable) ||
variable.GetType() == typeof(FloatVariable))
else if (variableType == typeof(IntegerVariable) ||
variableType == typeof(FloatVariable))
{
switch (selectedIndex)
{
@ -116,27 +132,23 @@ namespace Fungus.Script
}
}
if (setOperator != t.setOperator)
{
Undo.RecordObject(t, "Set Operator");
t.setOperator = setOperator;
}
setOperatorProp.enumValueIndex = (int)setOperator;
if (variable.GetType() == typeof(BooleanVariable))
if (variableType == typeof(BooleanVariable))
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("booleanData"));
EditorGUILayout.PropertyField(booleanDataProp);
}
else if (variable.GetType() == typeof(IntegerVariable))
else if (variableType == typeof(IntegerVariable))
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("integerData"));
EditorGUILayout.PropertyField(integerDataProp);
}
else if (variable.GetType() == typeof(FloatVariable))
else if (variableType == typeof(FloatVariable))
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("floatData"));
EditorGUILayout.PropertyField(floatDataProp);
}
else if (variable.GetType() == typeof(StringVariable))
else if (variableType == typeof(StringVariable))
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("stringData"));
EditorGUILayout.PropertyField(stringDataProp);
}
serializedObject.ApplyModifiedProperties();

Loading…
Cancel
Save