Browse Source

Moved new visual scripting code to its own namespace

master
chrisgregan 11 years ago
parent
commit
d0c2e9c961
  1. 2
      Assets/Fungus/Editor/AddOptionCommandEditor.cs
  2. 2
      Assets/Fungus/Editor/CompareCommandEditor.cs
  3. 58
      Assets/Fungus/Editor/FungusCommandEditor.cs
  4. 426
      Assets/Fungus/Editor/FungusEditorWindow.cs
  5. 141
      Assets/Fungus/Editor/FungusScriptEditor.cs
  6. 2
      Assets/Fungus/Editor/SayCommandEditor.cs
  7. 111
      Assets/Fungus/Editor/SequenceEditor.cs
  8. 2
      Assets/Fungus/Editor/SetVariableCommandEditor.cs
  9. BIN
      Assets/Fungus/Tests/Sequence/SequenceTest.unity
  10. 1
      Assets/Fungus/Tests/Sequence/SequenceTestRoom.cs
  11. 2
      Assets/Fungus/VisualScripting/AddOptionCommand.cs
  12. 2
      Assets/Fungus/VisualScripting/CompareCommand.cs
  13. 2
      Assets/Fungus/VisualScripting/ExecuteCommand.cs
  14. 2
      Assets/Fungus/VisualScripting/FungusCommand.cs
  15. 74
      Assets/Fungus/VisualScripting/FungusScript.cs
  16. 2
      Assets/Fungus/VisualScripting/SayCommand.cs
  17. 2
      Assets/Fungus/VisualScripting/Sequence.cs
  18. 76
      Assets/Fungus/VisualScripting/SetVariableCommand.cs
  19. 2
      Assets/Fungus/VisualScripting/Variable.cs
  20. 2
      Assets/Fungus/VisualScripting/WaitCommand.cs

2
Assets/Fungus/Editor/AddOptionCommandEditor.cs

@ -4,7 +4,7 @@ using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace Fungus namespace Fungus.Script
{ {
[CustomEditor (typeof(AddOptionCommand))] [CustomEditor (typeof(AddOptionCommand))]

2
Assets/Fungus/Editor/CompareCommandEditor.cs

@ -3,7 +3,7 @@ using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace Fungus namespace Fungus.Script
{ {
[CustomEditor (typeof(CompareCommand))] [CustomEditor (typeof(CompareCommand))]

58
Assets/Fungus/Editor/FungusCommandEditor.cs

@ -2,45 +2,49 @@ using UnityEditor;
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Fungus;
[CustomEditor (typeof(FungusCommand), true)] namespace Fungus.Script
public class FungusCommandEditor : Editor
{ {
public static FungusCommand selectedCommand; [CustomEditor (typeof(FungusCommand), true)]
public class FungusCommandEditor : Editor
public override void OnInspectorGUI()
{ {
Rect rect = EditorGUILayout.BeginVertical();
DrawCommandInspectorGUI(); public static FungusCommand selectedCommand;
FungusCommand t = target as FungusCommand; public override void OnInspectorGUI()
if (t != null)
{ {
if (t.errorMessage.Length > 0) Rect rect = EditorGUILayout.BeginVertical();
{
GUIStyle style = new GUIStyle(GUI.skin.label);
style.normal.textColor = new Color(1,0,0);
EditorGUILayout.LabelField(new GUIContent("Error: " + t.errorMessage), style);
}
if (t.IsExecuting()) DrawCommandInspectorGUI();
{
EditorGUI.DrawRect(rect, new Color(0f, 1f, 0f, 0.25f)); FungusCommand t = target as FungusCommand;
} if (t != null)
else if (t == selectedCommand)
{ {
EditorGUI.DrawRect(rect, new Color(1f, 1f, 0f, 0.25f)); if (t.errorMessage.Length > 0)
{
GUIStyle style = new GUIStyle(GUI.skin.label);
style.normal.textColor = new Color(1,0,0);
EditorGUILayout.LabelField(new GUIContent("Error: " + t.errorMessage), style);
}
if (t.IsExecuting())
{
EditorGUI.DrawRect(rect, new Color(0f, 1f, 0f, 0.25f));
}
else if (t == selectedCommand)
{
EditorGUI.DrawRect(rect, new Color(1f, 1f, 0f, 0.25f));
}
} }
EditorGUILayout.EndVertical();
} }
EditorGUILayout.EndVertical(); public virtual void DrawCommandInspectorGUI()
{
DrawDefaultInspector();
}
} }
public virtual void DrawCommandInspectorGUI()
{
DrawDefaultInspector();
}
} }

426
Assets/Fungus/Editor/FungusEditorWindow.cs

@ -3,284 +3,288 @@ using UnityEditor;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Fungus;
public class FungusEditorWindow : EditorWindow namespace Fungus.Script
{ {
[System.NonSerialized]
public Vector2 scrollPos; // ScrollViews use a Vector2 to track the state of each scroll bar
private List<Sequence> windowSequenceMap = new List<Sequence>();
private GameObject cachedSelection;
[MenuItem("Window/Fungus Editor")]
static void Init()
{
GetWindow(typeof(FungusEditorWindow), false, "Fungus Editor");
}
public void OnInspectorUpdate()
{
Repaint();
}
FungusScript GetFungusScript() public class FungusEditorWindow : EditorWindow
{ {
GameObject activeObject = Selection.activeGameObject; [System.NonSerialized]
public Vector2 scrollPos; // ScrollViews use a Vector2 to track the state of each scroll bar
private List<Sequence> windowSequenceMap = new List<Sequence>();
private GameObject cachedSelection;
while (activeObject != null) [MenuItem("Window/Fungus Editor")]
static void Init()
{
GetWindow(typeof(FungusEditorWindow), false, "Fungus Editor");
}
public void OnInspectorUpdate()
{ {
FungusScript fungusScript = activeObject.GetComponent<FungusScript>(); Repaint();
Sequence sequence = activeObject.GetComponent<Sequence>(); }
if (fungusScript != null) FungusScript GetFungusScript()
{ {
// Found sequence controller GameObject activeObject = Selection.activeGameObject;
return fungusScript;
} while (activeObject != null)
else if (sequence != null &&
sequence.transform.parent != null)
{
// Check parent for sequence controller
activeObject = sequence.transform.parent.gameObject;
}
else
{ {
activeObject = null; FungusScript fungusScript = activeObject.GetComponent<FungusScript>();
} Sequence sequence = activeObject.GetComponent<Sequence>();
}
return null; if (fungusScript != null)
} {
// Found sequence controller
return fungusScript;
}
else if (sequence != null &&
sequence.transform.parent != null)
{
// Check parent for sequence controller
activeObject = sequence.transform.parent.gameObject;
}
else
{
activeObject = null;
}
}
void OnGUI() return null;
{
FungusScript fungusScript = GetFungusScript();
if (fungusScript == null)
{
return;
} }
Sequence[] sequences = fungusScript.GetComponentsInChildren<Sequence>(); void OnGUI()
{
FungusScript fungusScript = GetFungusScript();
if (fungusScript == null)
{
return;
}
Rect scrollViewRect = new Rect(); Sequence[] sequences = fungusScript.GetComponentsInChildren<Sequence>();
foreach (Sequence s in sequences) Rect scrollViewRect = new Rect();
{
scrollViewRect.xMin = Mathf.Min(scrollViewRect.xMin, s.nodeRect.xMin);
scrollViewRect.xMax = Mathf.Max(scrollViewRect.xMax, s.nodeRect.xMax);
scrollViewRect.yMin = Mathf.Min(scrollViewRect.yMin, s.nodeRect.yMin);
scrollViewRect.yMax = Mathf.Max(scrollViewRect.yMax, s.nodeRect.yMax);
}
// Empty buffer area around edges of scroll rect foreach (Sequence s in sequences)
float bufferScale = 0.1f; {
scrollViewRect.xMin -= position.width * bufferScale; scrollViewRect.xMin = Mathf.Min(scrollViewRect.xMin, s.nodeRect.xMin);
scrollViewRect.yMin -= position.height * bufferScale; scrollViewRect.xMax = Mathf.Max(scrollViewRect.xMax, s.nodeRect.xMax);
scrollViewRect.xMax += position.width * bufferScale; scrollViewRect.yMin = Mathf.Min(scrollViewRect.yMin, s.nodeRect.yMin);
scrollViewRect.yMax += position.height * bufferScale; scrollViewRect.yMax = Mathf.Max(scrollViewRect.yMax, s.nodeRect.yMax);
}
scrollPos = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), scrollPos, scrollViewRect); // Empty buffer area around edges of scroll rect
float bufferScale = 0.1f;
scrollViewRect.xMin -= position.width * bufferScale;
scrollViewRect.yMin -= position.height * bufferScale;
scrollViewRect.xMax += position.width * bufferScale;
scrollViewRect.yMax += position.height * bufferScale;
// In games, GUI.Window pops up a window on your screen. In the Editor, GUI.Window shows a sub-window inside an EditorWindow. scrollPos = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), scrollPos, scrollViewRect);
// All calls to GUI.Window need to be wrapped in a BeginWindows / EndWindows pair.
// http://docs.unity3d.com/Documentation/ScriptReference/EditorWindow.BeginWindows.html
BeginWindows();
windowSequenceMap.Clear(); // In games, GUI.Window pops up a window on your screen. In the Editor, GUI.Window shows a sub-window inside an EditorWindow.
for (int i = 0; i < sequences.Length; ++i) // All calls to GUI.Window need to be wrapped in a BeginWindows / EndWindows pair.
{ // http://docs.unity3d.com/Documentation/ScriptReference/EditorWindow.BeginWindows.html
Sequence sequence = sequences[i]; BeginWindows();
sequence.nodeRect = GUILayout.Window(i, sequence.nodeRect, DrawWindow, sequence.name, GUILayout.Width(100), GUILayout.Height(100), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
windowSequenceMap.Add(sequence);
}
// Draw connections windowSequenceMap.Clear();
foreach (Sequence s in windowSequenceMap) for (int i = 0; i < sequences.Length; ++i)
{ {
DrawConnections(s, false); Sequence sequence = sequences[i];
} sequence.nodeRect = GUILayout.Window(i, sequence.nodeRect, DrawWindow, sequence.name, GUILayout.Width(100), GUILayout.Height(100), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
foreach (Sequence s in windowSequenceMap) windowSequenceMap.Add(sequence);
{ }
DrawConnections(s, true);
}
EndWindows(); // Draw connections
foreach (Sequence s in windowSequenceMap)
{
DrawConnections(s, false);
}
foreach (Sequence s in windowSequenceMap)
{
DrawConnections(s, true);
}
GUI.EndScrollView(); EndWindows();
string labelText = fungusScript.name; GUI.EndScrollView();
if (Application.isPlaying)
{ string labelText = fungusScript.name;
if (fungusScript.activeSequence == null) if (Application.isPlaying)
{ {
labelText += " (Idle)"; if (fungusScript.activeSequence == null)
{
labelText += " (Idle)";
}
else
{
labelText += " (Running)";
}
} }
else else
{ {
labelText += " (Running)"; labelText += " (Edit)";
} }
}
else GUILayout.BeginVertical();
{ GUILayout.FlexibleSpace();
labelText += " (Edit)"; GUILayout.BeginHorizontal();
} GUILayout.Space(15);
if (GUILayout.Button(labelText))
GUILayout.BeginVertical(); {
GUILayout.FlexibleSpace(); Selection.activeGameObject = fungusScript.gameObject;
GUILayout.BeginHorizontal(); }
GUILayout.Space(15); GUILayout.FlexibleSpace();
if (GUILayout.Button(labelText)) GUILayout.EndHorizontal();
{ GUILayout.Space(15);
Selection.activeGameObject = fungusScript.gameObject; GUILayout.EndVertical();
} }
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal(); void DrawWindow(int windowId)
GUILayout.Space(15); {
GUILayout.EndVertical(); // Select game object when node is clicked
} if (Event.current.button == 0 &&
Event.current.type == EventType.MouseUp)
void DrawWindow(int windowId)
{
// Select game object when node is clicked
if (Event.current.button == 0 &&
Event.current.type == EventType.MouseUp)
{
if (windowId < windowSequenceMap.Count)
{ {
Sequence s = windowSequenceMap[windowId]; if (windowId < windowSequenceMap.Count)
if (s != null)
{ {
Selection.activeGameObject = s.gameObject; Sequence s = windowSequenceMap[windowId];
if (s != null)
{
Selection.activeGameObject = s.gameObject;
}
} }
} }
}
if (FungusCommandEditor.selectedCommand != null) if (FungusCommandEditor.selectedCommand != null)
{
if (Selection.activeGameObject == null)
{ {
FungusCommandEditor.selectedCommand = null; if (Selection.activeGameObject == null)
}
else
{
FungusCommand command = Selection.activeGameObject.GetComponent<FungusCommand>();
if (command == null)
{ {
FungusCommandEditor.selectedCommand = null; FungusCommandEditor.selectedCommand = null;
} }
else if (command.gameObject != FungusCommandEditor.selectedCommand.gameObject) else
{ {
FungusCommandEditor.selectedCommand = null; FungusCommand command = Selection.activeGameObject.GetComponent<FungusCommand>();
if (command == null)
{
FungusCommandEditor.selectedCommand = null;
}
else if (command.gameObject != FungusCommandEditor.selectedCommand.gameObject)
{
FungusCommandEditor.selectedCommand = null;
}
} }
} }
}
Sequence sequence = windowSequenceMap[windowId];
GUIStyle style = new GUIStyle(GUI.skin.button); Sequence sequence = windowSequenceMap[windowId];
FungusCommand[] commands = sequence.gameObject.GetComponents<FungusCommand>(); GUIStyle style = new GUIStyle(GUI.skin.button);
foreach (FungusCommand command in commands)
{
string commandName = command.GetType().Name;
commandName = commandName.Replace("Command", "");
if (command.errorMessage.Length > 0) FungusCommand[] commands = sequence.gameObject.GetComponents<FungusCommand>();
{ foreach (FungusCommand command in commands)
GUI.backgroundColor = Color.red;
}
else if (ShouldHighlight(command))
{ {
if (command.IsExecuting()) string commandName = command.GetType().Name;
commandName = commandName.Replace("Command", "");
if (command.errorMessage.Length > 0)
{ {
GUI.backgroundColor = Color.green; GUI.backgroundColor = Color.red;
}
else if (ShouldHighlight(command))
{
if (command.IsExecuting())
{
GUI.backgroundColor = Color.green;
}
else
{
GUI.backgroundColor = Color.yellow;
}
} }
else else
{ {
GUI.backgroundColor = Color.yellow; GUI.backgroundColor = Color.white;
} }
}
else if (GUILayout.Button(commandName, style, GUILayout.ExpandWidth(true)))
{ {
GUI.backgroundColor = Color.white; // Highlight the command in inspector
FungusCommandEditor.selectedCommand = command;
}
EditorUtility.SetDirty( command );
} }
if (GUILayout.Button(commandName, style, GUILayout.ExpandWidth(true))) // Add an invisible element if there are no commands to avoid window width/height collapsing
if (commands.Length == 0)
{ {
// Highlight the command in inspector GUILayout.Space(10);
FungusCommandEditor.selectedCommand = command;
} }
EditorUtility.SetDirty( command ); GUI.DragWindow();
} }
// Add an invisible element if there are no commands to avoid window width/height collapsing void DrawConnections(Sequence sequence, bool highlightedOnly)
if (commands.Length == 0)
{ {
GUILayout.Space(10); List<Sequence> connectedSequences = new List<Sequence>();
}
GUI.DragWindow(); FungusCommand[] commands = sequence.GetComponentsInChildren<FungusCommand>();
} foreach (FungusCommand command in commands)
void DrawConnections(Sequence sequence, bool highlightedOnly)
{
List<Sequence> connectedSequences = new List<Sequence>();
FungusCommand[] commands = sequence.GetComponentsInChildren<FungusCommand>();
foreach (FungusCommand command in commands)
{
bool highlight = ShouldHighlight(command);
if (highlightedOnly && !highlight ||
!highlightedOnly && highlight)
{ {
continue; bool highlight = ShouldHighlight(command);
}
connectedSequences.Clear(); if (highlightedOnly && !highlight ||
command.GetConnectedSequences(ref connectedSequences); !highlightedOnly && highlight)
{
continue;
}
foreach (Sequence sequenceB in connectedSequences) connectedSequences.Clear();
{ command.GetConnectedSequences(ref connectedSequences);
Rect rectA = sequence.nodeRect;
Rect rectB = sequenceB.nodeRect;
Vector2 pointA; foreach (Sequence sequenceB in connectedSequences)
Vector2 pointB; {
Rect rectA = sequence.nodeRect;
Rect rectB = sequenceB.nodeRect;
Vector2 p1 = rectA.center; Vector2 pointA;
Vector2 p2 = rectB.center; Vector2 pointB;
GLDraw.segment_rect_intersection(rectA, ref p1, ref p2);
pointA = p2;
p1 = rectB.center; Vector2 p1 = rectA.center;
p2 = rectA.center; Vector2 p2 = rectB.center;
GLDraw.segment_rect_intersection(rectB, ref p1, ref p2); GLDraw.segment_rect_intersection(rectA, ref p1, ref p2);
pointB = p2; pointA = p2;
Color color = Color.grey; p1 = rectB.center;
if (highlight) p2 = rectA.center;
{ GLDraw.segment_rect_intersection(rectB, ref p1, ref p2);
if (command.IsExecuting()) pointB = p2;
{
color = Color.green; Color color = Color.grey;
} if (highlight)
else
{ {
color = Color.yellow; if (command.IsExecuting())
{
color = Color.green;
}
else
{
color = Color.yellow;
}
} }
}
GLDraw.DrawConnectingCurve(pointA, pointB, color, 2); GLDraw.DrawConnectingCurve(pointA, pointB, color, 2);
}
} }
} }
}
bool ShouldHighlight(FungusCommand command) bool ShouldHighlight(FungusCommand command)
{ {
return (command.IsExecuting() || (FungusCommandEditor.selectedCommand == command)); return (command.IsExecuting() || (FungusCommandEditor.selectedCommand == command));
}
} }
}
}

141
Assets/Fungus/Editor/FungusScriptEditor.cs

@ -6,93 +6,98 @@ using Fungus;
using Rotorz.ReorderableList; using Rotorz.ReorderableList;
using System.Linq; using System.Linq;
[CustomPropertyDrawer (typeof(Variable))] namespace Fungus.Script
public class VariableDrawer : PropertyDrawer {
{
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
{
SerializedProperty keyProp = property.FindPropertyRelative("key");
SerializedProperty typeProp = property.FindPropertyRelative("type");
// Draw the text field control GUI. [CustomPropertyDrawer (typeof(Variable))]
EditorGUI.BeginChangeCheck(); public class VariableDrawer : PropertyDrawer
{
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
{
SerializedProperty keyProp = property.FindPropertyRelative("key");
SerializedProperty typeProp = property.FindPropertyRelative("type");
Rect keyRect = position; // Draw the text field control GUI.
keyRect.width *= 0.5f; EditorGUI.BeginChangeCheck();
Rect typeRect = position; Rect keyRect = position;
typeRect.x += keyRect.width; keyRect.width *= 0.5f;
typeRect.width -= keyRect.width;
string keyValue = EditorGUI.TextField(keyRect, label, keyProp.stringValue); Rect typeRect = position;
int selectedEnum = (int)(VariableType)EditorGUI.EnumPopup(typeRect, (VariableType)typeProp.enumValueIndex); typeRect.x += keyRect.width;
typeRect.width -= keyRect.width;
if (EditorGUI.EndChangeCheck ()) string keyValue = EditorGUI.TextField(keyRect, label, keyProp.stringValue);
{ int selectedEnum = (int)(VariableType)EditorGUI.EnumPopup(typeRect, (VariableType)typeProp.enumValueIndex);
char[] arr = keyValue.Where(c => (char.IsLetterOrDigit(c) || c == '_')).ToArray();
keyValue = new string(arr);
keyProp.stringValue = keyValue; if (EditorGUI.EndChangeCheck ())
typeProp.enumValueIndex = selectedEnum; {
} char[] arr = keyValue.Where(c => (char.IsLetterOrDigit(c) || c == '_')).ToArray();
}
} keyValue = new string(arr);
[CustomEditor (typeof(FungusScript))]
public class FungusScriptEditor : Editor
{
SerializedProperty variablesProperty;
void OnEnable() keyProp.stringValue = keyValue;
{ typeProp.enumValueIndex = selectedEnum;
variablesProperty = serializedObject.FindProperty("variables"); }
}
} }
public override void OnInspectorGUI() [CustomEditor (typeof(FungusScript))]
public class FungusScriptEditor : Editor
{ {
serializedObject.Update(); SerializedProperty variablesProperty;
FungusScript t = target as FungusScript; void OnEnable()
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Open Fungus Editor"))
{ {
EditorWindow.GetWindow(typeof(FungusEditorWindow), false, "Fungus Editor"); variablesProperty = serializedObject.FindProperty("variables");
} }
if (GUILayout.Button("New Sequence")) public override void OnInspectorGUI()
{ {
GameObject go = new GameObject("Sequence"); serializedObject.Update();
go.transform.parent = t.transform;
Sequence s = go.AddComponent<Sequence>(); FungusScript t = target as FungusScript;
FungusEditorWindow fungusEditorWindow = EditorWindow.GetWindow(typeof(FungusEditorWindow), false, "Fungus Editor") as FungusEditorWindow;
s.nodeRect.x = fungusEditorWindow.scrollPos.x;
s.nodeRect.y = fungusEditorWindow.scrollPos.y;
Undo.RegisterCreatedObjectUndo(go, "Sequence");
Selection.activeGameObject = go;
}
GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal();
GUILayout.EndHorizontal(); GUILayout.FlexibleSpace();
if (GUILayout.Button("Open Fungus Editor"))
{
EditorWindow.GetWindow(typeof(FungusEditorWindow), false, "Fungus Editor");
}
if (GUILayout.Button("New Sequence"))
{
GameObject go = new GameObject("Sequence");
go.transform.parent = t.transform;
Sequence s = go.AddComponent<Sequence>();
FungusEditorWindow fungusEditorWindow = EditorWindow.GetWindow(typeof(FungusEditorWindow), false, "Fungus Editor") as FungusEditorWindow;
s.nodeRect.x = fungusEditorWindow.scrollPos.x;
s.nodeRect.y = fungusEditorWindow.scrollPos.y;
Undo.RegisterCreatedObjectUndo(go, "Sequence");
Selection.activeGameObject = go;
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUIContent stepTimeLabel = new GUIContent("Step Time", "Minimum time to execute each step"); GUIContent stepTimeLabel = new GUIContent("Step Time", "Minimum time to execute each step");
t.stepTime = EditorGUILayout.FloatField(stepTimeLabel, t.stepTime); t.stepTime = EditorGUILayout.FloatField(stepTimeLabel, t.stepTime);
GUIContent startSequenceLabel = new GUIContent("Start Sequence", "Sequence to be executed when controller starts."); GUIContent startSequenceLabel = new GUIContent("Start Sequence", "Sequence to be executed when controller starts.");
t.startSequence = SequenceEditor.SequenceField(startSequenceLabel, t, t.startSequence); t.startSequence = SequenceEditor.SequenceField(startSequenceLabel, t, t.startSequence);
if (t.startSequence == null) if (t.startSequence == null)
{ {
GUIStyle style = new GUIStyle(GUI.skin.label); GUIStyle style = new GUIStyle(GUI.skin.label);
style.normal.textColor = new Color(1,0,0); style.normal.textColor = new Color(1,0,0);
EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style); EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style);
} }
ReorderableListGUI.Title("Variables"); ReorderableListGUI.Title("Variables");
ReorderableListGUI.ListField(variablesProperty); ReorderableListGUI.ListField(variablesProperty);
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
}
} }
} }

2
Assets/Fungus/Editor/SayCommandEditor.cs

@ -4,7 +4,7 @@ using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace Fungus namespace Fungus.Script
{ {
[CustomEditor (typeof(SayCommand))] [CustomEditor (typeof(SayCommand))]

111
Assets/Fungus/Editor/SequenceEditor.cs

@ -2,73 +2,76 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Fungus;
[CustomEditor (typeof(Sequence))] namespace Fungus.Script
public class SequenceEditor : Editor
{ {
static public Sequence SequenceField(GUIContent label, FungusScript fungusScript, Sequence sequence) [CustomEditor (typeof(Sequence))]
public class SequenceEditor : Editor
{ {
if (fungusScript == null) static public Sequence SequenceField(GUIContent label, FungusScript fungusScript, Sequence sequence)
{ {
return null; if (fungusScript == null)
} {
return null;
Sequence result = sequence; }
// Build dictionary of child sequences
List<GUIContent> sequenceNames = new List<GUIContent>();
int selectedIndex = 0;
sequenceNames.Add(new GUIContent("<None>"));
Sequence[] sequences = fungusScript.GetComponentsInChildren<Sequence>();
for (int i = 0; i < sequences.Length; ++i)
{
sequenceNames.Add(new GUIContent(sequences[i].name));
if (sequence == sequences[i]) Sequence result = sequence;
// Build dictionary of child sequences
List<GUIContent> sequenceNames = new List<GUIContent>();
int selectedIndex = 0;
sequenceNames.Add(new GUIContent("<None>"));
Sequence[] sequences = fungusScript.GetComponentsInChildren<Sequence>();
for (int i = 0; i < sequences.Length; ++i)
{ {
selectedIndex = i + 1; sequenceNames.Add(new GUIContent(sequences[i].name));
if (sequence == sequences[i])
{
selectedIndex = i + 1;
}
} }
selectedIndex = EditorGUILayout.Popup(label, selectedIndex, sequenceNames.ToArray());
if (selectedIndex == 0)
{
result = null; // Option 'None'
}
else
{
result = sequences[selectedIndex - 1];
}
return result;
} }
selectedIndex = EditorGUILayout.Popup(label, selectedIndex, sequenceNames.ToArray());
if (selectedIndex == 0)
{
result = null; // Option 'None'
}
else
{
result = sequences[selectedIndex - 1];
}
return result;
}
static public string VariableField(GUIContent label, FungusScript fungusScript, string variableKey, ref VariableType variableType) static public string VariableField(GUIContent label, FungusScript fungusScript, string variableKey, ref VariableType variableType)
{
List<string> keys = new List<string>();
keys.Add("<None>");
int index = 0;
for (int i = 0; i < fungusScript.variables.Count; ++i)
{ {
Variable v = fungusScript.variables[i]; List<string> keys = new List<string>();
keys.Add(v.key); keys.Add("<None>");
if (v.key == variableKey && int index = 0;
index == 0) for (int i = 0; i < fungusScript.variables.Count; ++i)
{ {
index = i + 1; Variable v = fungusScript.variables[i];
keys.Add(v.key);
if (v.key == variableKey &&
index == 0)
{
index = i + 1;
}
} }
int newIndex = EditorGUILayout.Popup(label.text, index, keys.ToArray());
if (newIndex > 0)
{
variableType = fungusScript.variables[newIndex - 1].type;
}
return keys[newIndex];
} }
int newIndex = EditorGUILayout.Popup(label.text, index, keys.ToArray());
if (newIndex > 0)
{
variableType = fungusScript.variables[newIndex - 1].type;
}
return keys[newIndex];
} }
} }

2
Assets/Fungus/Editor/SetVariableCommandEditor.cs

@ -3,7 +3,7 @@ using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace Fungus namespace Fungus.Script
{ {
[CustomEditor (typeof(SetVariableCommand))] [CustomEditor (typeof(SetVariableCommand))]

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

Binary file not shown.

1
Assets/Fungus/Tests/Sequence/SequenceTestRoom.cs

@ -1,6 +1,7 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using Fungus; using Fungus;
using Fungus.Script;
public class SequenceTestRoom : Room public class SequenceTestRoom : Room
{ {

2
Assets/Fungus/VisualScripting/AddOptionCommand.cs

@ -2,7 +2,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace Fungus namespace Fungus.Script
{ {
public class AddOptionCommand : FungusCommand public class AddOptionCommand : FungusCommand

2
Assets/Fungus/VisualScripting/CompareCommand.cs

@ -2,7 +2,7 @@ using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace Fungus namespace Fungus.Script
{ {
public enum CompareOperator public enum CompareOperator

2
Assets/Fungus/VisualScripting/ExecuteCommand.cs

@ -3,7 +3,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace Fungus namespace Fungus.Script
{ {
public class ExecuteCommand : FungusCommand public class ExecuteCommand : FungusCommand

2
Assets/Fungus/VisualScripting/FungusCommand.cs

@ -5,7 +5,7 @@ using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace Fungus namespace Fungus.Script
{ {
[RequireComponent(typeof(Sequence))] [RequireComponent(typeof(Sequence))]
public class FungusCommand : MonoBehaviour public class FungusCommand : MonoBehaviour

74
Assets/Fungus/VisualScripting/FungusScript.cs

@ -5,53 +5,57 @@ using UnityEngine;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Fungus;
public class FungusScript : MonoBehaviour namespace Fungus.Script
{ {
public float stepTime;
public Sequence startSequence; public class FungusScript : MonoBehaviour
{
public float stepTime;
[System.NonSerialized] public Sequence startSequence;
public Sequence activeSequence;
public List<Variable> variables = new List<Variable>();
public void Execute() [System.NonSerialized]
{ public Sequence activeSequence;
if (startSequence == null)
public List<Variable> variables = new List<Variable>();
public void Execute()
{ {
return; if (startSequence == null)
} {
return;
}
ExecuteSequence(startSequence); ExecuteSequence(startSequence);
} }
public void ExecuteSequence(Sequence sequence) public void ExecuteSequence(Sequence sequence)
{
if (sequence == null)
{ {
return; if (sequence == null)
} {
return;
}
#if UNITY_EDITOR #if UNITY_EDITOR
Selection.activeGameObject = sequence.gameObject; Selection.activeGameObject = sequence.gameObject;
#endif #endif
activeSequence = sequence; activeSequence = sequence;
sequence.ExecuteNextCommand(); sequence.ExecuteNextCommand();
} }
public Variable GetVariable(string key) public Variable GetVariable(string key)
{
foreach (Variable v in variables)
{ {
if (v.key == key) foreach (Variable v in variables)
{ {
return v; if (v.key == key)
{
return v;
}
} }
} return null;
return null; }
} }
}
}

2
Assets/Fungus/VisualScripting/SayCommand.cs

@ -3,7 +3,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace Fungus namespace Fungus.Script
{ {
public class SayCommand : FungusCommand public class SayCommand : FungusCommand
{ {

2
Assets/Fungus/VisualScripting/Sequence.cs

@ -6,7 +6,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace Fungus namespace Fungus.Script
{ {
public class Sequence : MonoBehaviour public class Sequence : MonoBehaviour

76
Assets/Fungus/VisualScripting/SetVariableCommand.cs

@ -1,51 +1,55 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using Fungus;
public class SetVariableCommand : FungusCommand namespace Fungus.Script
{ {
public string variableKey;
public BooleanData booleanData; public class SetVariableCommand : FungusCommand
{
public string variableKey;
public IntegerData integerData; public BooleanData booleanData;
public FloatData floatData; public IntegerData integerData;
public StringData stringData; public FloatData floatData;
public override void OnEnter()
{
if (variableKey.Length == 0)
{
Continue();
return;
}
Variable v = parentFungusScript.GetVariable(variableKey); public StringData stringData;
if (v == null)
{ public override void OnEnter()
Debug.LogError("Variable " + variableKey + " not defined.");
}
else
{ {
switch (v.type) if (variableKey.Length == 0)
{ {
case VariableType.Boolean: Continue();
v.booleanValue = booleanData.value; return;
break;
case VariableType.Integer:
v.integerValue = integerData.value;
break;
case VariableType.Float:
v.floatValue = floatData.value;
break;
case VariableType.String:
v.stringValue = stringData.value;
break;
} }
}
Continue(); Variable v = parentFungusScript.GetVariable(variableKey);
if (v == null)
{
Debug.LogError("Variable " + variableKey + " not defined.");
}
else
{
switch (v.type)
{
case VariableType.Boolean:
v.booleanValue = booleanData.value;
break;
case VariableType.Integer:
v.integerValue = integerData.value;
break;
case VariableType.Float:
v.floatValue = floatData.value;
break;
case VariableType.String:
v.stringValue = stringData.value;
break;
}
}
Continue();
}
} }
} }

2
Assets/Fungus/VisualScripting/Variable.cs

@ -2,7 +2,7 @@
using System; using System;
using System.Collections; using System.Collections;
namespace Fungus namespace Fungus.Script
{ {
public enum VariableType public enum VariableType

2
Assets/Fungus/VisualScripting/WaitCommand.cs

@ -2,7 +2,7 @@ using UnityEngine;
using System; using System;
using System.Collections; using System.Collections;
namespace Fungus namespace Fungus.Script
{ {
public class WaitCommand : FungusCommand public class WaitCommand : FungusCommand

Loading…
Cancel
Save