Browse Source

Initial implementation of SetVariable custom editor

master
chrisgregan 11 years ago
parent
commit
607ad2eba4
  1. 69
      Assets/Fungus/Editor/SetVariableCommandEditor.cs
  2. BIN
      Assets/Fungus/Tests/Sequence/SequenceTest.unity
  3. 6
      Assets/Fungus/VisualScripting/CompareCommand.cs
  4. 15
      Assets/Fungus/VisualScripting/Variable.cs

69
Assets/Fungus/Editor/SetVariableCommandEditor.cs

@ -3,9 +3,12 @@ using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
[CustomEditor (typeof(SetVariableCommand))] namespace Fungus
public class SetVariableCommandEditor : FungusCommandEditor
{ {
[CustomEditor (typeof(SetVariableCommand))]
public class SetVariableCommandEditor : FungusCommandEditor
{
public override void DrawCommandInspectorGUI() public override void DrawCommandInspectorGUI()
{ {
SetVariableCommand t = target as SetVariableCommand; SetVariableCommand t = target as SetVariableCommand;
@ -16,42 +19,86 @@ public class SetVariableCommandEditor : FungusCommandEditor
return; return;
} }
int index = -1;
List<string> keys = new List<string>(); List<string> keys = new List<string>();
keys.Add("<None>");
int index = 0;
for (int i = 0; i < sc.variables.Count; ++i) for (int i = 0; i < sc.variables.Count; ++i)
{ {
Variable v = sc.variables[i]; Variable v = sc.variables[i];
keys.Add(v.key); keys.Add(v.key);
if (v.key == t.variableKey && if (v.key == t.variableKey &&
index == -1) index == 0)
{ {
index = i; index = i + 1;
}
} }
int newIndex = EditorGUILayout.Popup("Variable", index, keys.ToArray());
if (newIndex != index)
{
Undo.RecordObject(t, "Select variable");
} }
index = EditorGUILayout.Popup("Variable", index, keys.ToArray()); if (newIndex == 0)
{
t.variableKey = "";
return;
}
Variable variable = sc.variables[index]; Variable variable = sc.variables[newIndex - 1];
if (t.variableKey != variable.key)
{
Undo.RecordObject(t, "Select variable");
t.variableKey = variable.key; t.variableKey = variable.key;
}
bool booleanValue = t.booleanValue;
int integerValue = t.integerValue;
float floatValue = t.floatValue;
string stringValue = t.stringValue;
switch (variable.type) switch (variable.type)
{ {
case VariableType.Boolean: case VariableType.Boolean:
t.booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), t.booleanValue); booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), t.booleanValue);
break; break;
case VariableType.Integer: case VariableType.Integer:
t.integerValue = EditorGUILayout.IntField(new GUIContent("Integer Value", "The integer value to set the variable with"), t.integerValue); integerValue = EditorGUILayout.IntField(new GUIContent("Integer Value", "The integer value to set the variable with"), t.integerValue);
break; break;
case VariableType.Float: case VariableType.Float:
t.floatValue = EditorGUILayout.FloatField(new GUIContent("Float Value", "The float value to set the variable with"), t.floatValue); floatValue = EditorGUILayout.FloatField(new GUIContent("Float Value", "The float value to set the variable with"), t.floatValue);
break; break;
case VariableType.String: case VariableType.String:
t.stringValue = EditorGUILayout.TextField(new GUIContent("String Value", "The string value to set the variable with"), t.stringValue); stringValue = EditorGUILayout.TextField(new GUIContent("String Value", "The string value to set the variable with"), t.stringValue);
break; break;
} }
if (booleanValue != t.booleanValue)
{
Undo.RecordObject(t, "Set boolean value");
t.booleanValue = booleanValue;
}
else if (integerValue != t.integerValue)
{
Undo.RecordObject(t, "Set integer value");
t.integerValue = integerValue;
}
else if (floatValue != t.floatValue)
{
Undo.RecordObject(t, "Set float value");
t.floatValue = floatValue;
}
else if (stringValue != t.stringValue)
{
Undo.RecordObject(t, "Set string value");
t.stringValue = stringValue;
} }
}
}
} }

BIN
Assets/Fungus/Tests/Sequence/SequenceTest.unity

Binary file not shown.

6
Assets/Fungus/VisualScripting/CompareCommand.cs

@ -8,6 +8,12 @@ public class CompareCommand : FungusCommand
public bool booleanValue; public bool booleanValue;
public int integerValue;
public float floatValue;
public string stringValue;
public Sequence trueSequence; public Sequence trueSequence;
public Sequence falseSequence; public Sequence falseSequence;

15
Assets/Fungus/VisualScripting/Variable.cs

@ -2,17 +2,20 @@
using System; using System;
using System.Collections; using System.Collections;
public enum VariableType namespace Fungus
{ {
public enum VariableType
{
Boolean, Boolean,
Integer, Integer,
Float, Float,
String String
}; };
[Serializable] [Serializable]
public class Variable public class Variable
{ {
public string key; public string key;
public VariableType type; public VariableType type;
@ -20,4 +23,6 @@ public class Variable
public int integerValue; public int integerValue;
public float floatValue; public float floatValue;
public bool booleanValue; public bool booleanValue;
}
} }
Loading…
Cancel
Save