|
|
@ -6,9 +6,13 @@ using System.Collections.Generic; |
|
|
|
|
|
|
|
|
|
|
|
namespace Fungus.Script |
|
|
|
namespace Fungus.Script |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
public class FungusScriptWindow : EditorWindow |
|
|
|
public class FungusScriptWindow : EditorWindow |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
float commandViewWidth; |
|
|
|
|
|
|
|
bool resize = false; |
|
|
|
|
|
|
|
Rect cursorChangeRect; |
|
|
|
|
|
|
|
public const float minViewWidth = 300; |
|
|
|
|
|
|
|
|
|
|
|
private List<Sequence> windowSequenceMap = new List<Sequence>(); |
|
|
|
private List<Sequence> windowSequenceMap = new List<Sequence>(); |
|
|
|
|
|
|
|
|
|
|
|
[MenuItem("Window/Fungus Script")] |
|
|
|
[MenuItem("Window/Fungus Script")] |
|
|
@ -17,6 +21,12 @@ namespace Fungus.Script |
|
|
|
GetWindow(typeof(FungusScriptWindow), false, "Fungus Script"); |
|
|
|
GetWindow(typeof(FungusScriptWindow), false, "Fungus Script"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void OnEnable() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
commandViewWidth = minViewWidth; |
|
|
|
|
|
|
|
cursorChangeRect = new Rect(this.position.width - commandViewWidth, 0, 4f, this.position.height); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void OnInspectorUpdate() |
|
|
|
public void OnInspectorUpdate() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Repaint(); |
|
|
|
Repaint(); |
|
|
@ -32,8 +42,8 @@ namespace Fungus.Script |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void OnGUI() |
|
|
|
void OnGUI() |
|
|
|
{ |
|
|
|
{ |
|
|
|
FungusScript fungusScript = GetFungusScript(); |
|
|
|
FungusScript fungusScript = GetFungusScript(); |
|
|
|
if (fungusScript == null) |
|
|
|
if (fungusScript == null) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -41,6 +51,15 @@ namespace Fungus.Script |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUILayout.BeginHorizontal(); |
|
|
|
|
|
|
|
DrawScriptView(fungusScript); |
|
|
|
|
|
|
|
ResizeViews(); |
|
|
|
|
|
|
|
DrawCommandView(fungusScript); |
|
|
|
|
|
|
|
GUILayout.EndHorizontal(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DrawScriptView(FungusScript fungusScript) |
|
|
|
|
|
|
|
{ |
|
|
|
EditorUtility.SetDirty(fungusScript); |
|
|
|
EditorUtility.SetDirty(fungusScript); |
|
|
|
|
|
|
|
|
|
|
|
Sequence[] sequences = fungusScript.GetComponentsInChildren<Sequence>(); |
|
|
|
Sequence[] sequences = fungusScript.GetComponentsInChildren<Sequence>(); |
|
|
@ -62,28 +81,31 @@ namespace Fungus.Script |
|
|
|
scrollViewRect.xMax += position.width * bufferScale; |
|
|
|
scrollViewRect.xMax += position.width * bufferScale; |
|
|
|
scrollViewRect.yMax += position.height * bufferScale; |
|
|
|
scrollViewRect.yMax += position.height * bufferScale; |
|
|
|
|
|
|
|
|
|
|
|
Rect windowRect = new Rect(0, 0, position.width, position.height); |
|
|
|
// Calc rect for left hand script view |
|
|
|
|
|
|
|
Rect scriptViewRect = new Rect(0, 0, this.position.width - commandViewWidth, this.position.height); |
|
|
|
|
|
|
|
|
|
|
|
// Clip GL drawing so not to overlap scrollbars |
|
|
|
// Clip GL drawing so not to overlap scrollbars |
|
|
|
Rect clipRect = new Rect(fungusScript.scrollPos.x + scrollViewRect.x, |
|
|
|
Rect clipRect = new Rect(fungusScript.scriptScrollPos.x + scrollViewRect.x, |
|
|
|
fungusScript.scrollPos.y + scrollViewRect.y, |
|
|
|
fungusScript.scriptScrollPos.y + scrollViewRect.y, |
|
|
|
windowRect.width - 15, |
|
|
|
scriptViewRect.width - 15, |
|
|
|
windowRect.height - 15); |
|
|
|
scriptViewRect.height - 15); |
|
|
|
|
|
|
|
|
|
|
|
fungusScript.scrollPos = GLDraw.BeginScrollView(windowRect, fungusScript.scrollPos, scrollViewRect, clipRect); |
|
|
|
GUILayoutUtility.GetRect(scriptViewRect.width, scriptViewRect.height); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fungusScript.scriptScrollPos = GLDraw.BeginScrollView(scriptViewRect, fungusScript.scriptScrollPos, scrollViewRect, clipRect); |
|
|
|
|
|
|
|
|
|
|
|
if (Event.current.type == EventType.ContextClick) |
|
|
|
if (Event.current.type == EventType.ContextClick) |
|
|
|
{ |
|
|
|
{ |
|
|
|
GenericMenu menu = new GenericMenu(); |
|
|
|
GenericMenu menu = new GenericMenu(); |
|
|
|
Vector2 mousePos = Event.current.mousePosition; |
|
|
|
Vector2 mousePos = Event.current.mousePosition; |
|
|
|
mousePos += fungusScript.scrollPos; |
|
|
|
mousePos += fungusScript.scriptScrollPos; |
|
|
|
menu.AddItem (new GUIContent ("Create Sequence"), false, CreateSequenceCallback, mousePos); |
|
|
|
menu.AddItem (new GUIContent ("Create Sequence"), false, CreateSequenceCallback, mousePos); |
|
|
|
menu.ShowAsContext (); |
|
|
|
menu.ShowAsContext (); |
|
|
|
|
|
|
|
|
|
|
|
Event.current.Use(); |
|
|
|
Event.current.Use(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BeginWindows(); |
|
|
|
BeginWindows(); |
|
|
|
|
|
|
|
|
|
|
|
GUIStyle windowStyle = new GUIStyle(GUI.skin.window); |
|
|
|
GUIStyle windowStyle = new GUIStyle(GUI.skin.window); |
|
|
|
|
|
|
|
|
|
|
@ -110,7 +132,7 @@ namespace Fungus.Script |
|
|
|
DrawConnections(fungusScript, s, true); |
|
|
|
DrawConnections(fungusScript, s, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
EndWindows(); |
|
|
|
EndWindows(); |
|
|
|
|
|
|
|
|
|
|
|
if (fungusScript.selectedSequence != null || |
|
|
|
if (fungusScript.selectedSequence != null || |
|
|
|
fungusScript.executingSequence != null) |
|
|
|
fungusScript.executingSequence != null) |
|
|
@ -132,24 +154,101 @@ namespace Fungus.Script |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GLDraw.EndScrollView(); |
|
|
|
GLDraw.EndScrollView(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GUILayout.BeginVertical(); |
|
|
|
void ResizeViews() |
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
{ |
|
|
|
GUILayout.BeginHorizontal(); |
|
|
|
cursorChangeRect.x = this.position.width - commandViewWidth; |
|
|
|
GUILayout.Space(10); |
|
|
|
cursorChangeRect.height = this.position.height; |
|
|
|
GUILayout.Label(fungusScript.name, EditorStyles.miniLabel); |
|
|
|
|
|
|
|
GUILayout.EndHorizontal(); |
|
|
|
GUI.color = Color.grey; |
|
|
|
GUILayout.BeginHorizontal(); |
|
|
|
GUI.DrawTexture(cursorChangeRect, EditorGUIUtility.whiteTexture); |
|
|
|
GUILayout.Space(10); |
|
|
|
GUI.color = Color.white; |
|
|
|
|
|
|
|
EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeHorizontal); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Event.current.type == EventType.mouseDown && cursorChangeRect.Contains(Event.current.mousePosition)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
resize = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (resize) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
commandViewWidth = this.position.width - Event.current.mousePosition.x; |
|
|
|
|
|
|
|
commandViewWidth = Mathf.Max(minViewWidth, commandViewWidth); |
|
|
|
|
|
|
|
commandViewWidth = Mathf.Min(this.position.width - minViewWidth, commandViewWidth); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(Event.current.type == EventType.MouseUp) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
resize = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DrawCommandView(FungusScript fungusScript) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
GUILayout.Space(5); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fungusScript.commandScrollPos = GUILayout.BeginScrollView(fungusScript.commandScrollPos); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.BeginVertical(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.Separator(); |
|
|
|
|
|
|
|
GUI.backgroundColor = Color.yellow; |
|
|
|
|
|
|
|
GUILayout.Box("Sequence", GUILayout.ExpandWidth(true)); |
|
|
|
GUI.backgroundColor = Color.white; |
|
|
|
GUI.backgroundColor = Color.white; |
|
|
|
if (GUILayout.Button("Show Variables")) |
|
|
|
|
|
|
|
|
|
|
|
GUILayout.BeginHorizontal(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fungusScript.selectedSequence == null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
EditorWindow.GetWindow<VariablesWindow>("Fungus Variables"); |
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
} |
|
|
|
} |
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
|
|
|
|
|
|
|
|
if (GUILayout.Button(fungusScript.selectedSequence == null ? "Create Sequence" : "Create", |
|
|
|
|
|
|
|
fungusScript.selectedSequence == null ? EditorStyles.miniButton : EditorStyles.miniButtonLeft)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Sequence newSequence = fungusScript.CreateSequence(fungusScript.scriptScrollPos); |
|
|
|
|
|
|
|
Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence"); |
|
|
|
|
|
|
|
fungusScript.selectedSequence = newSequence; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fungusScript.selectedSequence == null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fungusScript.selectedSequence != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (GUILayout.Button("Delete", EditorStyles.miniButtonMid)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Undo.DestroyObjectImmediate(fungusScript.selectedSequence.gameObject); |
|
|
|
|
|
|
|
fungusScript.selectedSequence = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (GUILayout.Button("Duplicate", EditorStyles.miniButtonRight)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
GameObject copy = GameObject.Instantiate(fungusScript.selectedSequence.gameObject) as GameObject; |
|
|
|
|
|
|
|
copy.transform.parent = fungusScript.transform; |
|
|
|
|
|
|
|
copy.transform.hideFlags = HideFlags.HideInHierarchy; |
|
|
|
|
|
|
|
copy.name = fungusScript.selectedSequence.name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sequence sequenceCopy = copy.GetComponent<Sequence>(); |
|
|
|
|
|
|
|
sequenceCopy.nodeRect.x += sequenceCopy.nodeRect.width + 10; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Undo.RegisterCreatedObjectUndo(copy, "Duplicate Sequence"); |
|
|
|
|
|
|
|
fungusScript.selectedSequence = sequenceCopy; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GUILayout.EndHorizontal(); |
|
|
|
GUILayout.EndHorizontal(); |
|
|
|
GUILayout.Space(20); |
|
|
|
|
|
|
|
GUILayout.EndVertical(); |
|
|
|
EditorGUILayout.Separator(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FungusScriptEditor editor = Editor.CreateEditor(fungusScript) as FungusScriptEditor; |
|
|
|
|
|
|
|
editor.DrawSequenceGUI(fungusScript); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.EndVertical(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUILayout.EndScrollView(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void CreateSequenceCallback(object item) |
|
|
|
void CreateSequenceCallback(object item) |
|
|
@ -158,7 +257,7 @@ namespace Fungus.Script |
|
|
|
if (fungusScript != null) |
|
|
|
if (fungusScript != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Vector2 position = (Vector2)item; |
|
|
|
Vector2 position = (Vector2)item; |
|
|
|
position -= fungusScript.scrollPos; |
|
|
|
position -= fungusScript.scriptScrollPos; |
|
|
|
Sequence newSequence = fungusScript.CreateSequence(position); |
|
|
|
Sequence newSequence = fungusScript.CreateSequence(position); |
|
|
|
Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence"); |
|
|
|
Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence"); |
|
|
|
fungusScript.selectedSequence = newSequence; |
|
|
|
fungusScript.selectedSequence = newSequence; |
|
|
|