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.
147 lines
3.6 KiB
147 lines
3.6 KiB
10 years ago
|
using UnityEditor;
|
||
10 years ago
|
using UnityEngine;
|
||
|
using System.Collections;
|
||
10 years ago
|
using System.Collections.Generic;
|
||
10 years ago
|
|
||
10 years ago
|
namespace Fungus.Script
|
||
10 years ago
|
{
|
||
|
|
||
10 years ago
|
[CustomEditor (typeof(Set))]
|
||
10 years ago
|
public class SetEditor : FungusCommandEditor
|
||
10 years ago
|
{
|
||
10 years ago
|
public override void DrawCommandGUI()
|
||
10 years ago
|
{
|
||
10 years ago
|
serializedObject.Update();
|
||
|
|
||
10 years ago
|
Set t = target as Set;
|
||
10 years ago
|
|
||
10 years ago
|
FungusScript fungusScript = t.GetFungusScript();
|
||
10 years ago
|
if (fungusScript == null)
|
||
10 years ago
|
{
|
||
10 years ago
|
return;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
FungusVariable variable = FungusVariableEditor.VariableField(new GUIContent("Variable", "Variable to set"),
|
||
|
fungusScript,
|
||
|
t.variable);
|
||
10 years ago
|
|
||
|
if (variable != t.variable)
|
||
10 years ago
|
{
|
||
10 years ago
|
Undo.RecordObject(t, "Set Variable Key");
|
||
10 years ago
|
t.variable = variable;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
if (t.variable == null)
|
||
10 years ago
|
{
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
|
||
|
List<GUIContent> operatorsList = new List<GUIContent>();
|
||
|
operatorsList.Add(new GUIContent("="));
|
||
10 years ago
|
if (variable.GetType() == typeof(BooleanVariable))
|
||
10 years ago
|
{
|
||
|
operatorsList.Add(new GUIContent("!"));
|
||
|
}
|
||
10 years ago
|
else if (variable.GetType() == typeof(IntegerVariable) ||
|
||
|
variable.GetType() == typeof(FloatVariable))
|
||
10 years ago
|
{
|
||
10 years ago
|
operatorsList.Add(new GUIContent("+="));
|
||
|
operatorsList.Add(new GUIContent("-="));
|
||
|
operatorsList.Add(new GUIContent("*="));
|
||
|
operatorsList.Add(new GUIContent("/="));
|
||
10 years ago
|
}
|
||
|
|
||
|
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;
|
||
10 years ago
|
if (variable.GetType() == typeof(BooleanVariable) ||
|
||
|
variable.GetType() == typeof(StringVariable))
|
||
10 years ago
|
{
|
||
|
switch (selectedIndex)
|
||
|
{
|
||
|
default:
|
||
|
case 0:
|
||
|
setOperator = Set.SetOperator.Assign;
|
||
|
break;
|
||
|
case 1:
|
||
|
setOperator = Set.SetOperator.Negate;
|
||
|
break;
|
||
|
}
|
||
10 years ago
|
}
|
||
|
else if (variable.GetType() == typeof(IntegerVariable) ||
|
||
|
variable.GetType() == typeof(FloatVariable))
|
||
|
{
|
||
10 years ago
|
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;
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
if (setOperator != t.setOperator)
|
||
|
{
|
||
|
Undo.RecordObject(t, "Set Operator");
|
||
|
t.setOperator = setOperator;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
if (variable.GetType() == typeof(BooleanVariable))
|
||
10 years ago
|
{
|
||
10 years ago
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("booleanData"));
|
||
10 years ago
|
}
|
||
10 years ago
|
else if (variable.GetType() == typeof(IntegerVariable))
|
||
10 years ago
|
{
|
||
10 years ago
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("integerData"));
|
||
10 years ago
|
}
|
||
10 years ago
|
else if (variable.GetType() == typeof(FloatVariable))
|
||
|
{
|
||
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("floatData"));
|
||
|
}
|
||
|
else if (variable.GetType() == typeof(StringVariable))
|
||
|
{
|
||
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("stringData"));
|
||
|
}
|
||
|
|
||
|
serializedObject.ApplyModifiedProperties();
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
}
|