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.")] "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 class Say : FungusCommand
{ {
public Character character; [TextArea(5,10)]
public string storyText; public string storyText;
public Character character;
public AudioClip voiceOverClip; public AudioClip voiceOverClip;
public bool showOnce; public bool showOnce;
int executionCount; int executionCount;

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

@ -48,7 +48,6 @@ namespace Fungus.Script
serializedObject.Update(); serializedObject.Update();
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel(new GUIContent("Say Text", "Text to display in dialog"));
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton))) 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; 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<string> variableKeys = new List<string>();
List<FungusVariable> variableObjects = new List<FungusVariable>(); List<FungusVariable> variableObjects = new List<FungusVariable>();
@ -28,6 +28,9 @@ namespace Fungus.Script
List<FungusVariable> variables = fungusScript.variables; List<FungusVariable> variables = fungusScript.variables;
int index = 0; int index = 0;
int selectedIndex = 0; int selectedIndex = 0;
FungusVariable selectedVariable = property.objectReferenceValue as FungusVariable;
foreach (FungusVariable v in variables) foreach (FungusVariable v in variables)
{ {
if (filter != null) if (filter != null)
@ -43,7 +46,7 @@ namespace Fungus.Script
index++; index++;
if (v == variable) if (v == selectedVariable)
{ {
selectedIndex = index; selectedIndex = index;
} }
@ -51,7 +54,7 @@ namespace Fungus.Script
selectedIndex = EditorGUILayout.Popup(label.text, selectedIndex, variableKeys.ToArray()); 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))] [CustomEditor (typeof(If))]
public class IfEditor : FungusCommandEditor 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() public override void DrawCommandGUI()
{ {
serializedObject.Update(); serializedObject.Update();
@ -21,27 +38,25 @@ namespace Fungus.Script
return; return;
} }
FungusVariable fungusVariable = FungusVariableEditor.VariableField(new GUIContent("Variable", "Variable to use in operation"), FungusVariableEditor.VariableField(variableProp,
t.GetFungusScript(), new GUIContent("Variable", "Variable to use in operation"),
t.variable, t.GetFungusScript(),
null); null);
if (fungusVariable != t.variable)
{
Undo.RecordObject(t, "Select Variable");
t.variable = fungusVariable;
}
if (t.variable == null) if (variableProp.objectReferenceValue == null)
{ {
serializedObject.ApplyModifiedProperties();
return; return;
} }
FungusVariable selectedVariable = variableProp.objectReferenceValue as FungusVariable;
System.Type variableType = selectedVariable.GetType();
List<GUIContent> operatorList = new List<GUIContent>(); List<GUIContent> operatorList = new List<GUIContent>();
operatorList.Add(new GUIContent("==")); operatorList.Add(new GUIContent("=="));
operatorList.Add(new GUIContent("!=")); operatorList.Add(new GUIContent("!="));
if (t.variable.GetType() == typeof(IntegerVariable) || if (variableType == typeof(IntegerVariable) ||
t.variable.GetType() == typeof(FloatVariable)) variableType == typeof(FloatVariable))
{ {
operatorList.Add(new GUIContent("<")); operatorList.Add(new GUIContent("<"));
operatorList.Add(new GUIContent(">")); operatorList.Add(new GUIContent(">"));
@ -49,31 +64,25 @@ namespace Fungus.Script
operatorList.Add(new GUIContent(">=")); operatorList.Add(new GUIContent(">="));
} }
CompareOperator compareOperator = (CompareOperator)EditorGUILayout.Popup(new GUIContent("Compare", compareOperatorProp.enumValueIndex = EditorGUILayout.Popup(new GUIContent("Compare", "The comparison operator to use when comparing values"),
"The comparison operator to use when comparing values"), compareOperatorProp.enumValueIndex,
(int)t.compareOperator, operatorList.ToArray());
operatorList.ToArray());
if (compareOperator != t.compareOperator)
{
Undo.RecordObject(t, "Select Compare Operator");
t.compareOperator = compareOperator;
}
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(); serializedObject.ApplyModifiedProperties();

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

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

Loading…
Cancel
Save