Browse Source

Context sensitive Create Sequence menu

master
chrisgregan 11 years ago
parent
commit
39552da96a
  1. 12
      Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs
  2. 30
      Assets/Fungus/Editor/FungusScript/FungusScriptWindow.cs
  3. 11
      Assets/Fungus/VisualScripting/FungusScript.cs
  4. BIN
      Assets/Shuttle/ShuttleGame.unity

12
Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs

@ -90,15 +90,9 @@ namespace Fungus.Script
if (GUILayout.Button(t.selectedSequence == null ? "Create Sequence" : "Create", if (GUILayout.Button(t.selectedSequence == null ? "Create Sequence" : "Create",
t.selectedSequence == null ? EditorStyles.miniButton : EditorStyles.miniButtonLeft)) t.selectedSequence == null ? EditorStyles.miniButton : EditorStyles.miniButtonLeft))
{ {
GameObject go = new GameObject("Sequence"); Sequence newSequence = t.CreateSequence(t.scrollPos);
go.transform.parent = t.transform; Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence");
go.transform.hideFlags = HideFlags.HideInHierarchy; t.selectedSequence = newSequence;
Sequence s = go.AddComponent<Sequence>();
s.nodeRect.x = t.scrollPos.x;
s.nodeRect.y = t.scrollPos.y;
Undo.RegisterCreatedObjectUndo(go, "Sequence");
t.selectedSequence = s;
return;
} }
if (t.selectedSequence == null) if (t.selectedSequence == null)

30
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); 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(); BeginWindows();
GUIStyle windowStyle = new GUIStyle(GUI.skin.window); GUIStyle windowStyle = new GUIStyle(GUI.skin.window);
@ -138,10 +149,23 @@ namespace Fungus.Script
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
GUILayout.Space(20); GUILayout.Space(20);
GUILayout.EndVertical(); 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 // Select sequence when node is clicked
if (Event.current.button == 0 && if (Event.current.button == 0 &&
Event.current.type == EventType.MouseDown) Event.current.type == EventType.MouseDown)

11
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<Sequence>();
s.nodeRect.x = position.x;
s.nodeRect.y = position.y;
return s;
}
public void Execute() public void Execute()
{ {
if (startSequence == null) if (startSequence == null)

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save