diff --git a/Assets/Fungus/Dialog/Commands/AddOption.cs b/Assets/Fungus/Dialog/Commands/AddOption.cs
index c2aaafdd..6a0fde2d 100644
--- a/Assets/Fungus/Dialog/Commands/AddOption.cs
+++ b/Assets/Fungus/Dialog/Commands/AddOption.cs
@@ -8,7 +8,7 @@ namespace Fungus
[CommandInfo("Dialog",
"Add Option",
"Adds an option for the player to select, displayed by the next Say command.")]
- public class AddOption : Command
+ public class AddOption : SetVariable
{
public string optionText;
public Sequence targetSequence;
@@ -26,6 +26,8 @@ namespace Fungus
Choose.Option option = new Choose.Option();
option.optionText = optionText;
option.targetSequence = targetSequence;
+ option.action = () => DoSetOperation();
+
Choose.options.Add(option);
Continue();
diff --git a/Assets/Fungus/Dialog/Commands/Choose.cs b/Assets/Fungus/Dialog/Commands/Choose.cs
index 938919c5..d482a16a 100644
--- a/Assets/Fungus/Dialog/Commands/Choose.cs
+++ b/Assets/Fungus/Dialog/Commands/Choose.cs
@@ -14,6 +14,7 @@ namespace Fungus
{
public string optionText;
public Sequence targetSequence;
+ public Action action;
}
static public List options = new List ();
@@ -60,6 +61,11 @@ namespace Fungus
dialogOption.onSelect = delegate {
+ if (option.action != null)
+ {
+ option.action();
+ }
+
chooseDialog.ShowDialog(false);
if (onSelectSequence == null)
diff --git a/Assets/Fungus/Dialog/Editor/AddOptionEditor.cs b/Assets/Fungus/Dialog/Editor/AddOptionEditor.cs
index ae30fd3c..69f1aa88 100644
--- a/Assets/Fungus/Dialog/Editor/AddOptionEditor.cs
+++ b/Assets/Fungus/Dialog/Editor/AddOptionEditor.cs
@@ -9,14 +9,15 @@ namespace Fungus
{
[CustomEditor (typeof(AddOption))]
- public class AddOptionEditor : CommandEditor
+ public class AddOptionEditor : SetVariableEditor
{
protected SerializedProperty optionTextProp;
protected SerializedProperty hideOnSelectedProp;
protected SerializedProperty targetSequenceProp;
- protected virtual void OnEnable()
+ protected override void OnEnable()
{
+ base.OnEnable();
optionTextProp = serializedObject.FindProperty("optionText");
hideOnSelectedProp = serializedObject.FindProperty("hideOnSelected");
targetSequenceProp = serializedObject.FindProperty("targetSequence");
@@ -38,6 +39,8 @@ namespace Fungus
EditorGUILayout.PropertyField(hideOnSelectedProp, new GUIContent("Hide On Selected", "Hide this option forever once the player has selected it."));
serializedObject.ApplyModifiedProperties();
+
+ base.DrawCommandGUI();
}
}
diff --git a/Assets/Fungus/FungusScript/Commands/SetVariable.cs b/Assets/Fungus/FungusScript/Commands/SetVariable.cs
index 025e02df..4b7d618b 100644
--- a/Assets/Fungus/FungusScript/Commands/SetVariable.cs
+++ b/Assets/Fungus/FungusScript/Commands/SetVariable.cs
@@ -31,10 +31,78 @@ namespace Fungus
public StringData stringData;
public override void OnEnter()
+ {
+ DoSetOperation();
+
+ Continue();
+ }
+
+ public override string GetSummary()
+ {
+ if (variable == null)
+ {
+ return "Error: Variable not selected";
+ }
+
+ string description = variable.key;
+
+ switch (setOperator)
+ {
+ default:
+ case SetOperator.Assign:
+ description += " = ";
+ break;
+ case SetOperator.Negate:
+ description += " != ";
+ break;
+ case SetOperator.Add:
+ description += " += ";
+ break;
+ case SetOperator.Subtract:
+ description += " -= ";
+ break;
+ case SetOperator.Multiply:
+ description += " *= ";
+ break;
+ case SetOperator.Divide:
+ description += " /= ";
+ break;
+ }
+
+ if (variable.GetType() == typeof(BooleanVariable))
+ {
+ description += booleanData.GetDescription();
+ }
+ else if (variable.GetType() == typeof(IntegerVariable))
+ {
+ description += integerData.GetDescription();
+ }
+ else if (variable.GetType() == typeof(FloatVariable))
+ {
+ description += floatData.GetDescription();
+ }
+ else if (variable.GetType() == typeof(StringVariable))
+ {
+ description += stringData.GetDescription();
+ }
+
+ return description;
+ }
+
+ public override bool HasReference(Variable variable)
+ {
+ return (variable == this.variable);
+ }
+
+ public override Color GetButtonColor()
+ {
+ return new Color32(253, 253, 150, 255);
+ }
+
+ protected virtual void DoSetOperation()
{
if (variable == null)
{
- Continue();
return;
}
@@ -42,7 +110,7 @@ namespace Fungus
{
BooleanVariable lhs = (variable as BooleanVariable);
bool rhs = booleanData.Value;
-
+
switch (setOperator)
{
default:
@@ -58,7 +126,7 @@ namespace Fungus
{
IntegerVariable lhs = (variable as IntegerVariable);
int rhs = integerData.Value;
-
+
switch (setOperator)
{
default:
@@ -108,7 +176,7 @@ namespace Fungus
{
StringVariable lhs = (variable as StringVariable);
string rhs = stringData.Value;
-
+
switch (setOperator)
{
default:
@@ -117,70 +185,6 @@ namespace Fungus
break;
}
}
-
- Continue();
- }
-
- public override string GetSummary()
- {
- if (variable == null)
- {
- return "Error: Variable not selected";
- }
-
- string description = variable.key;
-
- switch (setOperator)
- {
- default:
- case SetOperator.Assign:
- description += " = ";
- break;
- case SetOperator.Negate:
- description += " != ";
- break;
- case SetOperator.Add:
- description += " += ";
- break;
- case SetOperator.Subtract:
- description += " -= ";
- break;
- case SetOperator.Multiply:
- description += " *= ";
- break;
- case SetOperator.Divide:
- description += " /= ";
- break;
- }
-
- if (variable.GetType() == typeof(BooleanVariable))
- {
- description += booleanData.GetDescription();
- }
- else if (variable.GetType() == typeof(IntegerVariable))
- {
- description += integerData.GetDescription();
- }
- else if (variable.GetType() == typeof(FloatVariable))
- {
- description += floatData.GetDescription();
- }
- else if (variable.GetType() == typeof(StringVariable))
- {
- description += stringData.GetDescription();
- }
-
- return description;
- }
-
- public override bool HasReference(Variable variable)
- {
- return (variable == this.variable);
- }
-
- public override Color GetButtonColor()
- {
- return new Color32(253, 253, 150, 255);
}
}