diff --git a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs index 8bb3373c..7f12d680 100644 --- a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs @@ -90,15 +90,9 @@ namespace Fungus.Script if (GUILayout.Button(t.selectedSequence == null ? "Create Sequence" : "Create", t.selectedSequence == null ? EditorStyles.miniButton : EditorStyles.miniButtonLeft)) { - GameObject go = new GameObject("Sequence"); - go.transform.parent = t.transform; - go.transform.hideFlags = HideFlags.HideInHierarchy; - Sequence s = go.AddComponent(); - s.nodeRect.x = t.scrollPos.x; - s.nodeRect.y = t.scrollPos.y; - Undo.RegisterCreatedObjectUndo(go, "Sequence"); - t.selectedSequence = s; - return; + Sequence newSequence = t.CreateSequence(t.scrollPos); + Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence"); + t.selectedSequence = newSequence; } if (t.selectedSequence == null) diff --git a/Assets/Fungus/Editor/FungusScript/FungusScriptWindow.cs b/Assets/Fungus/Editor/FungusScript/FungusScriptWindow.cs index c39f923b..fe4df2b0 100755 --- a/Assets/Fungus/Editor/FungusScript/FungusScriptWindow.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusScriptWindow.cs @@ -71,6 +71,17 @@ namespace Fungus.Script fungusScript.scrollPos = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), fungusScript.scrollPos, scrollViewRect); + if (Event.current.type == EventType.ContextClick) + { + GenericMenu menu = new GenericMenu(); + Vector2 mousePos = Event.current.mousePosition; + mousePos += fungusScript.scrollPos; + menu.AddItem (new GUIContent ("Create Sequence"), false, CreateSequenceCallback, mousePos); + menu.ShowAsContext (); + + Event.current.Use(); + } + BeginWindows(); GUIStyle windowStyle = new GUIStyle(GUI.skin.window); @@ -138,10 +149,23 @@ namespace Fungus.Script GUILayout.EndHorizontal(); GUILayout.Space(20); GUILayout.EndVertical(); - } + } - void DrawWindow(int windowId) - { + void CreateSequenceCallback(object item) + { + FungusScript fungusScript = GetFungusScript(); + if (fungusScript != null) + { + Vector2 position = (Vector2)item; + position -= fungusScript.scrollPos; + Sequence newSequence = fungusScript.CreateSequence(position); + Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence"); + fungusScript.selectedSequence = newSequence; + } + } + + void DrawWindow(int windowId) + { // Select sequence when node is clicked if (Event.current.button == 0 && Event.current.type == EventType.MouseDown) diff --git a/Assets/Fungus/VisualScripting/FungusScript.cs b/Assets/Fungus/VisualScripting/FungusScript.cs index 797d546b..d16f2e7a 100644 --- a/Assets/Fungus/VisualScripting/FungusScript.cs +++ b/Assets/Fungus/VisualScripting/FungusScript.cs @@ -41,6 +41,17 @@ namespace Fungus.Script } } + public Sequence CreateSequence(Vector2 position) + { + GameObject go = new GameObject("Sequence"); + go.transform.parent = transform; + go.transform.hideFlags = HideFlags.HideInHierarchy; + Sequence s = go.AddComponent(); + s.nodeRect.x = position.x; + s.nodeRect.y = position.y; + return s; + } + public void Execute() { if (startSequence == null) diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index 3ba0ac22..4feb0250 100644 Binary files a/Assets/Shuttle/ShuttleGame.unity and b/Assets/Shuttle/ShuttleGame.unity differ