From 39552da96ac3cf37b7429e5813610b9270fe6842 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Mon, 18 Aug 2014 16:52:04 +0100 Subject: [PATCH] Context sensitive Create Sequence menu --- .../Editor/FungusScript/FungusScriptEditor.cs | 12 ++----- .../Editor/FungusScript/FungusScriptWindow.cs | 30 ++++++++++++++++-- Assets/Fungus/VisualScripting/FungusScript.cs | 11 +++++++ Assets/Shuttle/ShuttleGame.unity | Bin 83452 -> 93756 bytes 4 files changed, 41 insertions(+), 12 deletions(-) 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 3ba0ac22c788dc03fee54abb199f869c852283d3..4feb0250b312231fed968d01ab6b4e876318df1e 100644 GIT binary patch delta 8054 zcmaKwdvH|M9mmfh8wi1f<(cqENO*35KzPLksVq-7QD8|x0eLJhi6ziL3#J{%8?}^J z#jZ-&*xF&~Fdb@B8wT3t51{F^9pY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