Browse Source

Initial support for variables

master
chrisgregan 11 years ago
parent
commit
ea3687c4f6
  1. 6
      Assets/Fungus/Editor/FungusCommandEditor.cs
  2. 12
      Assets/Fungus/Editor/SequenceControllerEditor.cs
  3. 15
      Assets/Fungus/Editor/SetVariableCommandEditor.cs
  4. 8
      Assets/Fungus/Editor/SetVariableCommandEditor.cs.meta
  5. BIN
      Assets/Fungus/Tests/Sequence/SequenceTest.unity
  6. 40
      Assets/Fungus/VisualScripting/CompareCommand.cs
  7. 8
      Assets/Fungus/VisualScripting/CompareCommand.cs.meta
  8. 32
      Assets/Fungus/VisualScripting/SequenceController.cs
  9. 51
      Assets/Fungus/VisualScripting/SetVariableCommand.cs
  10. 8
      Assets/Fungus/VisualScripting/SetVariableCommand.cs.meta
  11. 23
      Assets/Fungus/VisualScripting/Variable.cs
  12. 8
      Assets/Fungus/VisualScripting/Variable.cs.meta
  13. 1
      Assets/Fungus/VisualScripting/WaitCommand.cs

6
Assets/Fungus/Editor/FungusCommandEditor.cs

@ -14,7 +14,7 @@ public class FungusCommandEditor : Editor
{ {
Rect rect = EditorGUILayout.BeginVertical(); Rect rect = EditorGUILayout.BeginVertical();
DrawDefaultInspector(); DrawCommandInspectorGUI();
FungusCommand t = target as FungusCommand; FungusCommand t = target as FungusCommand;
if (t != null) if (t != null)
@ -36,4 +36,8 @@ public class FungusCommandEditor : Editor
EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical();
} }
public virtual void DrawCommandInspectorGUI()
{
DrawDefaultInspector();
}
} }

12
Assets/Fungus/Editor/SequenceControllerEditor.cs

@ -6,7 +6,7 @@ using Fungus;
using Rotorz.ReorderableList; using Rotorz.ReorderableList;
using System.Linq; using System.Linq;
[CustomPropertyDrawer (typeof(SequenceController.Variable))] [CustomPropertyDrawer (typeof(Variable))]
public class VariableDrawer : PropertyDrawer public class VariableDrawer : PropertyDrawer
{ {
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
@ -25,7 +25,7 @@ public class VariableDrawer : PropertyDrawer
typeRect.width -= keyRect.width; typeRect.width -= keyRect.width;
string keyValue = EditorGUI.TextField(keyRect, label, keyProp.stringValue); string keyValue = EditorGUI.TextField(keyRect, label, keyProp.stringValue);
int selectedEnum = (int)(SequenceController.VariableType)EditorGUI.EnumPopup(typeRect, (SequenceController.VariableType)typeProp.enumValueIndex); int selectedEnum = (int)(VariableType)EditorGUI.EnumPopup(typeRect, (VariableType)typeProp.enumValueIndex);
if (EditorGUI.EndChangeCheck ()) if (EditorGUI.EndChangeCheck ())
{ {
@ -47,8 +47,7 @@ public class SequenceControllerEditor : Editor
void OnEnable() void OnEnable()
{ {
globalVariablesProperty = serializedObject.FindProperty("globalVariables"); localVariablesProperty = serializedObject.FindProperty("variables");
localVariablesProperty = serializedObject.FindProperty("localVariables");
} }
public override void OnInspectorGUI() public override void OnInspectorGUI()
@ -92,12 +91,9 @@ public class SequenceControllerEditor : Editor
EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style); EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style);
} }
ReorderableListGUI.Title("Local Variables"); ReorderableListGUI.Title("Variables");
ReorderableListGUI.ListField(localVariablesProperty); ReorderableListGUI.ListField(localVariablesProperty);
ReorderableListGUI.Title("Global Variables");
ReorderableListGUI.ListField(globalVariablesProperty);
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
} }
} }

15
Assets/Fungus/Editor/SetVariableCommandEditor.cs

@ -0,0 +1,15 @@
using UnityEditor;
using UnityEngine;
using System.Collections;
[CustomEditor (typeof(SetVariableCommand))]
public class SetVariableCommandEditor : FungusCommandEditor
{
public override void DrawCommandInspectorGUI()
{
SetVariableCommand t = target as SetVariableCommand;
t.variableKey = EditorGUILayout.TextField(new GUIContent("Variable Key", "The name of the variable to set"), t.variableKey);
t.booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), t.booleanValue);
}
}

8
Assets/Fungus/Editor/SetVariableCommandEditor.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d0cbb7e4ccb4a41db8ced7c87070df1d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

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

Binary file not shown.

40
Assets/Fungus/VisualScripting/CompareCommand.cs

@ -0,0 +1,40 @@
using UnityEngine;
using System.Collections;
using Fungus;
public class CompareCommand : FungusCommand
{
public string variableKey;
public bool booleanValue;
public Sequence trueSequence;
public Sequence falseSequence;
public override void OnEnter()
{
Variable v = parentSequenceController.GetVariable(variableKey);
if (v != null)
{
if (v.booleanValue == booleanValue)
{
if (trueSequence != null)
{
ExecuteSequence(trueSequence);
return;
}
}
else
{
if (falseSequence != null)
{
ExecuteSequence(falseSequence);
return;
}
}
}
Finish();
}
}

8
Assets/Fungus/VisualScripting/CompareCommand.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 050fb9e6e72f442b3b883da8a965bdeb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

32
Assets/Fungus/VisualScripting/SequenceController.cs

@ -15,25 +15,9 @@ public class SequenceController : MonoBehaviour
[System.NonSerialized] [System.NonSerialized]
public Sequence activeSequence; public Sequence activeSequence;
public enum VariableType
{
String,
Integer,
Float,
Boolean
};
[Serializable]
public class Variable
{
public string key;
public VariableType type;
}
public List<Variable> localVariables = new List<Variable>();
public List<Variable> globalVariables = new List<Variable>();
public List<Variable> variables = new List<Variable>();
public void Execute() public void Execute()
{ {
if (startSequence == null) if (startSequence == null)
@ -58,4 +42,16 @@ public class SequenceController : MonoBehaviour
activeSequence = sequence; activeSequence = sequence;
sequence.ExecuteNextCommand(); sequence.ExecuteNextCommand();
} }
public Variable GetVariable(string key)
{
foreach (Variable v in variables)
{
if (v.key == key)
{
return v;
}
}
return null;
}
} }

51
Assets/Fungus/VisualScripting/SetVariableCommand.cs

@ -0,0 +1,51 @@
using UnityEngine;
using System.Collections;
using Fungus;
public class SetVariableCommand : FungusCommand
{
public string variableKey;
public string stringValue;
public int integerValue;
public bool booleanValue;
public float floatValue;
public override void OnEnter()
{
if (variableKey.Length == 0)
{
Finish();
return;
}
Variable v = parentSequenceController.GetVariable(variableKey);
if (v == null)
{
Debug.LogError("Variable " + variableKey + " not defined.");
}
else
{
switch (v.type)
{
case VariableType.String:
v.stringValue = stringValue;
break;
case VariableType.Integer:
v.integerValue = integerValue;
break;
case VariableType.Float:
v.floatValue = floatValue;
break;
case VariableType.Boolean:
v.booleanValue = booleanValue;
break;
}
}
Finish();
}
}

8
Assets/Fungus/VisualScripting/SetVariableCommand.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fb77d0ce495044f6e9feb91b31798e8c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

23
Assets/Fungus/VisualScripting/Variable.cs

@ -0,0 +1,23 @@
using UnityEngine;
using System;
using System.Collections;
public enum VariableType
{
Boolean,
Integer,
Float,
String
};
[Serializable]
public class Variable
{
public string key;
public VariableType type;
public string stringValue;
public int integerValue;
public float floatValue;
public bool booleanValue;
}

8
Assets/Fungus/VisualScripting/Variable.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2f3853d313cd94fe184e3478cefc11f2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

1
Assets/Fungus/VisualScripting/WaitCommand.cs

@ -1,7 +1,6 @@
using UnityEngine; using UnityEngine;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
namespace Fungus namespace Fungus
{ {

Loading…
Cancel
Save