Browse Source

Moved variables list over the Fungus Script window

master
chrisgregan 10 years ago
parent
commit
63e597492c
  1. 68
      Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs
  2. 131
      Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs
  3. 9
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs

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

@ -97,35 +97,65 @@ namespace Fungus
EditorGUILayout.Separator();
DrawVariablesGUI();
serializedObject.ApplyModifiedProperties();
}
public virtual void DrawVariablesGUI()
{
serializedObject.Update();
FungusScript t = target as FungusScript;
ReorderableListGUI.Title("Variables");
VariableListAdaptor adaptor = new VariableListAdaptor(variablesProp, 0);
ReorderableListControl.DrawControlFromState(adaptor, null, ReorderableListFlags.DisableContextMenu | ReorderableListFlags.HideAddButton);
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (!Application.isPlaying && GUILayout.Button("Add Variable"))
if (!t.variablesExpanded)
{
GenericMenu menu = new GenericMenu ();
menu.AddItem(new GUIContent ("Boolean"), false, AddVariable<BooleanVariable>, t);
menu.AddItem (new GUIContent ("Integer"), false, AddVariable<IntegerVariable>, t);
menu.AddItem (new GUIContent ("Float"), false, AddVariable<FloatVariable>, t);
menu.AddItem (new GUIContent ("String"), false, AddVariable<StringVariable>, t);
if (GUILayout.Button ("Variables", GUILayout.Height(24)))
{
t.variablesExpanded = true;
}
}
else
{
ReorderableListGUI.Title("Variables");
VariableListAdaptor adaptor = new VariableListAdaptor(variablesProp, 0);
ReorderableListControl.DrawControlFromState(adaptor, null, ReorderableListFlags.DisableContextMenu | ReorderableListFlags.HideAddButton);
float plusWidth = 32;
float plusHeight = 24;
Rect listRect = GUILayoutUtility.GetLastRect();
Rect buttonRect = listRect;
float buttonHeight = 24;
buttonRect.x = 4;
buttonRect.y -= buttonHeight - 1;
buttonRect.width -= 30;
buttonRect.height = buttonHeight;
menu.ShowAsContext ();
if (GUI.Button (buttonRect, "Variables"))
{
t.variablesExpanded = false;
}
Rect plusRect = listRect;
plusRect.x += plusRect.width - plusWidth;
plusRect.y -= plusHeight - 1;
plusRect.width = plusWidth;
plusRect.height = plusHeight;
if (!Application.isPlaying && GUI.Button(plusRect, FungusEditorResources.texAddButton))
{
GenericMenu menu = new GenericMenu ();
menu.AddItem(new GUIContent ("Boolean"), false, AddVariable<BooleanVariable>, t);
menu.AddItem (new GUIContent ("Integer"), false, AddVariable<IntegerVariable>, t);
menu.AddItem (new GUIContent ("Float"), false, AddVariable<FloatVariable>, t);
menu.AddItem (new GUIContent ("String"), false, AddVariable<StringVariable>, t);
menu.ShowAsContext ();
}
}
GUILayout.EndHorizontal();
serializedObject.ApplyModifiedProperties();
}
protected virtual void AddVariable<T>(object obj) where T : Variable

131
Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs

@ -92,7 +92,7 @@ namespace Fungus
deleteList.Clear();
DrawScriptView(fungusScript);
DrawControls(fungusScript);
DrawOverlay(fungusScript);
if (Event.current.type == EventType.Repaint &&
showContextMenu)
@ -102,7 +102,7 @@ namespace Fungus
}
}
protected virtual void DrawControls(FungusScript fungusScript)
protected virtual void DrawOverlay(FungusScript fungusScript)
{
GUILayout.Space(8);
@ -116,11 +116,39 @@ namespace Fungus
50 - fungusScript.scrollPos.y);
CreateSequence(fungusScript, newNodePosition);
}
GUILayout.FlexibleSpace();
GUILayout.Space(8);
fungusScript.zoom = GUILayout.HorizontalSlider(fungusScript.zoom, minZoomValue, maxZoomValue, GUILayout.Width(100));
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
GUILayout.BeginVertical(GUILayout.Width(300));
GUILayout.FlexibleSpace();
fungusScript.variablesScrollPos = GUILayout.BeginScrollView(fungusScript.variablesScrollPos, GUILayout.MaxHeight(position.height * 0.75f));
GUILayout.FlexibleSpace();
GUILayout.Space(8);
FungusScriptEditor fungusScriptEditor = Editor.CreateEditor (fungusScript) as FungusScriptEditor;
fungusScriptEditor.DrawVariablesGUI();
DestroyImmediate(fungusScriptEditor);
GUILayout.EndScrollView();
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
@ -271,101 +299,6 @@ namespace Fungus
}
}
/*
protected virtual void ResizeViews(FungusScript fungusScript)
{
cursorChangeRect = new Rect(this.position.width - fungusScript.commandViewWidth, 0, 4f, this.position.height);
GUI.color = Color.grey;
GUI.DrawTexture(cursorChangeRect, EditorGUIUtility.whiteTexture);
GUI.color = Color.white;
EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeHorizontal);
if (Event.current.type == EventType.mouseDown && cursorChangeRect.Contains(Event.current.mousePosition))
{
resize = true;
}
if (resize)
{
fungusScript.commandViewWidth = this.position.width - Event.current.mousePosition.x;
fungusScript.commandViewWidth = Mathf.Max(minViewWidth, fungusScript.commandViewWidth);
fungusScript.commandViewWidth = Mathf.Min(this.position.width - minViewWidth, fungusScript.commandViewWidth);
}
if(Event.current.type == EventType.MouseUp)
{
resize = false;
}
}
protected virtual void DrawSequenceView(FungusScript fungusScript)
{
GUILayout.Space(5);
fungusScript.commandScrollPos = GUILayout.BeginScrollView(fungusScript.commandScrollPos);
EditorGUILayout.BeginVertical();
GUILayout.Box("Sequence", GUILayout.ExpandWidth(true));
GUILayout.BeginHorizontal();
if (fungusScript.selectedSequence == null)
{
GUILayout.FlexibleSpace();
}
if (GUILayout.Button(fungusScript.selectedSequence == null ? "Create Sequence" : "Create",
fungusScript.selectedSequence == null ? EditorStyles.miniButton : EditorStyles.miniButtonLeft))
{
Vector2 newPosition;
if (fungusScript.selectedSequence == null)
{
newPosition = newNodePosition;
}
else
{
Rect selectedRect = fungusScript.selectedSequence.nodeRect;
newPosition = new Vector2(selectedRect.position.x + selectedRect.width + 20, selectedRect.y);
}
CreateSequence(fungusScript, newPosition);
}
if (fungusScript.selectedSequence == null)
{
GUILayout.FlexibleSpace();
}
else
{
if (GUILayout.Button("Delete", EditorStyles.miniButtonMid))
{
DeleteSequence(fungusScript, fungusScript.selectedSequence);
}
if (GUILayout.Button("Duplicate", EditorStyles.miniButtonRight))
{
DuplicateSequence(fungusScript, fungusScript.selectedSequence);
}
}
GUILayout.EndHorizontal();
if (fungusScript.selectedSequence != null)
{
EditorGUILayout.Separator();
SequenceEditor sequenceEditor = Editor.CreateEditor(fungusScript.selectedSequence) as SequenceEditor;
sequenceEditor.DrawSequenceGUI(fungusScript);
DestroyImmediate(sequenceEditor);
GUILayout.FlexibleSpace();
}
EditorGUILayout.EndVertical();
GUILayout.EndScrollView();
}
*/
public static Sequence CreateSequence(FungusScript fungusScript, Vector2 position)
{
Sequence newSequence = fungusScript.CreateSequence(position);

9
Assets/Fungus/FungusScript/Scripts/FungusScript.cs

@ -25,6 +25,15 @@ namespace Fungus
[HideInInspector]
public Vector2 scrollPos;
/**
* Scroll position of Fungus Script variables window.
*/
[HideInInspector]
public Vector2 variablesScrollPos;
[HideInInspector]
public bool variablesExpanded = true;
/**
* Zoom level of Fungus Script editor window
*/

Loading…
Cancel
Save