Browse Source

Set command supports operators.

master
chrisgregan 11 years ago
parent
commit
9afdeda1b6
  1. 88
      Assets/Fungus/Editor/FungusScript/SetEditor.cs
  2. 77
      Assets/Fungus/VisualScripting/Set.cs
  3. BIN
      Assets/Shuttle/ShuttleGame.unity

88
Assets/Fungus/Editor/FungusScript/SetEditor.cs

@ -36,7 +36,95 @@ namespace Fungus.Script
{
return;
}
List<GUIContent> operatorsList = new List<GUIContent>();
operatorsList.Add(new GUIContent("="));
if (variableType == VariableType.Boolean)
{
operatorsList.Add(new GUIContent("!"));
}
else if (variableType == VariableType.Integer ||
variableType == VariableType.Float)
{
operatorsList.Add(new GUIContent("+"));
operatorsList.Add(new GUIContent("-"));
operatorsList.Add(new GUIContent("*"));
operatorsList.Add(new GUIContent("/"));
}
int selectedIndex = 0;
switch (t.setOperator)
{
default:
case Set.SetOperator.Assign:
selectedIndex = 0;
break;
case Set.SetOperator.Negate:
selectedIndex = 1;
break;
case Set.SetOperator.Add:
selectedIndex = 1;
break;
case Set.SetOperator.Subtract:
selectedIndex = 2;
break;
case Set.SetOperator.Multiply:
selectedIndex = 3;
break;
case Set.SetOperator.Divide:
selectedIndex = 4;
break;
}
selectedIndex = EditorGUILayout.Popup(new GUIContent("Operator", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray());
Set.SetOperator setOperator = Set.SetOperator.Assign;
switch (variableType)
{
default:
case VariableType.Boolean:
case VariableType.String:
switch (selectedIndex)
{
default:
case 0:
setOperator = Set.SetOperator.Assign;
break;
case 1:
setOperator = Set.SetOperator.Negate;
break;
}
break;
case VariableType.Integer:
case VariableType.Float:
switch (selectedIndex)
{
default:
case 0:
setOperator = Set.SetOperator.Assign;
break;
case 1:
setOperator = Set.SetOperator.Add;
break;
case 2:
setOperator = Set.SetOperator.Subtract;
break;
case 3:
setOperator = Set.SetOperator.Multiply;
break;
case 4:
setOperator = Set.SetOperator.Divide;
break;
}
break;
}
if (setOperator != t.setOperator)
{
Undo.RecordObject(t, "Set Operator");
t.setOperator = setOperator;
}
bool booleanValue = t.booleanData.value;
int integerValue = t.integerData.value;
float floatValue = t.floatData.value;

77
Assets/Fungus/VisualScripting/Set.cs

@ -6,8 +6,20 @@ namespace Fungus.Script
public class Set : FungusCommand
{
public enum SetOperator
{
Assign, // =
Negate, // !
Add, // +
Subtract, // -
Multiply, // *
Divide // /
}
public string variableKey;
public SetOperator setOperator;
public BooleanData booleanData;
public IntegerData integerData;
@ -34,16 +46,73 @@ namespace Fungus.Script
switch (v.type)
{
case VariableType.Boolean:
v.booleanValue = booleanData.value;
switch (setOperator)
{
default:
case SetOperator.Assign:
v.booleanValue = booleanData.value;
break;
case SetOperator.Negate:
v.booleanValue = !booleanData.value;
break;
}
break;
case VariableType.Integer:
v.integerValue = integerData.value;
switch (setOperator)
{
default:
case SetOperator.Assign:
v.integerValue = integerData.value;
break;
case SetOperator.Negate:
v.integerValue = -integerData.value;
break;
case SetOperator.Add:
v.integerValue += integerData.value;
break;
case SetOperator.Subtract:
v.integerValue -= integerData.value;
break;
case SetOperator.Multiply:
v.integerValue *= integerData.value;
break;
case SetOperator.Divide:
v.integerValue /= integerData.value;
break;
}
break;
case VariableType.Float:
v.floatValue = floatData.value;
switch (setOperator)
{
default:
case SetOperator.Assign:
v.floatValue = floatData.value;
break;
case SetOperator.Negate:
v.floatValue = -floatData.value;
break;
case SetOperator.Add:
v.floatValue += floatData.value;
break;
case SetOperator.Subtract:
v.floatValue -= floatData.value;
break;
case SetOperator.Multiply:
v.floatValue *= floatData.value;
break;
case SetOperator.Divide:
v.floatValue /= floatData.value;
break;
}
break;
case VariableType.String:
v.stringValue = stringData.value;
switch (setOperator)
{
default:
case SetOperator.Assign:
v.stringValue = stringData.value;
break;
}
break;
}
}

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save