Browse Source

FlowchartWindow Variable list perfermance Improvements

- changes cause repaint of flowhcart window
- Var list drawing performance improvements, cache styles and widths
master
desktop-maesty/steve 6 years ago
parent
commit
b4588f17b0
  1. 2
      Assets/Fungus/Scripts/Components/Flowchart.cs
  2. 79
      Assets/Fungus/Scripts/Editor/FlowchartWindow.cs
  3. 44
      Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs

2
Assets/Fungus/Scripts/Components/Flowchart.cs

@ -366,6 +366,8 @@ namespace Fungus
/// </summary> /// </summary>
public virtual List<Variable> Variables { get { return variables; } } public virtual List<Variable> Variables { get { return variables; } }
public virtual int VariableCount { get { return variables.Count; } }
/// <summary> /// <summary>
/// Description text displayed in the Flowchart editor window /// Description text displayed in the Flowchart editor window
/// </summary> /// </summary>

79
Assets/Fungus/Scripts/Editor/FlowchartWindow.cs

@ -181,6 +181,7 @@ namespace Fungus.EditorUtils
protected static BlockInspector blockInspector; protected static BlockInspector blockInspector;
protected int forceRepaintCount; protected int forceRepaintCount;
protected Texture2D addTexture; protected Texture2D addTexture;
protected GUIContent addButtonContent;
protected Texture2D connectionPointTexture; protected Texture2D connectionPointTexture;
protected Rect selectionBox; protected Rect selectionBox;
protected Vector2 startSelectionBoxPosition = -Vector2.one; protected Vector2 startSelectionBoxPosition = -Vector2.one;
@ -199,6 +200,7 @@ namespace Fungus.EditorUtils
protected int blockPopupSelection = -1; protected int blockPopupSelection = -1;
protected Vector2 popupScroll; protected Vector2 popupScroll;
protected Flowchart flowchart, prevFlowchart; protected Flowchart flowchart, prevFlowchart;
protected int prevVarCount;
protected Block[] blocks = new Block[0]; protected Block[] blocks = new Block[0];
protected Block dragBlock; protected Block dragBlock;
protected static FungusState fungusState; protected static FungusState fungusState;
@ -209,6 +211,29 @@ namespace Fungus.EditorUtils
private bool wasControl; private bool wasControl;
private ExecutingBlocks executingBlocks = new ExecutingBlocks(); private ExecutingBlocks executingBlocks = new ExecutingBlocks();
private GUIStyle toolbarSeachTextFieldStyle;
protected GUIStyle ToolbarSeachTextFieldStyle
{
get
{
if(toolbarSeachTextFieldStyle == null)
toolbarSeachTextFieldStyle = GUI.skin.FindStyle("ToolbarSeachTextField");
return toolbarSeachTextFieldStyle;
}
}
private GUIStyle toolbarSeachCancelButtonStyle;
protected GUIStyle ToolbarSeachCancelButtonStyle
{
get
{
if(toolbarSeachCancelButtonStyle == null)
toolbarSeachCancelButtonStyle = GUI.skin.FindStyle("ToolbarSeachCancelButton");
return toolbarSeachCancelButtonStyle;
}
}
[MenuItem("Tools/Fungus/Flowchart Window")] [MenuItem("Tools/Fungus/Flowchart Window")]
static void Init() static void Init()
{ {
@ -225,6 +250,7 @@ namespace Fungus.EditorUtils
nodeStyle.wordWrap = true; nodeStyle.wordWrap = true;
addTexture = FungusEditorResources.AddSmall; addTexture = FungusEditorResources.AddSmall;
addButtonContent = new GUIContent(addTexture, "Add a new block");
connectionPointTexture = FungusEditorResources.ConnectionPoint; connectionPointTexture = FungusEditorResources.ConnectionPoint;
gridLineColor.a = EditorGUIUtility.isProSkin ? 0.5f : 0.25f; gridLineColor.a = EditorGUIUtility.isProSkin ? 0.5f : 0.25f;
@ -248,6 +274,20 @@ namespace Fungus.EditorUtils
{ {
HandleFlowchartSelectionChange(); HandleFlowchartSelectionChange();
if(flowchart != null)
{
var varcount = flowchart.VariableCount;
if (varcount != prevVarCount)
{
prevVarCount = varcount;
Repaint();
}
}
else
{
prevVarCount = 0;
}
if (Application.isPlaying) if (Application.isPlaying)
{ {
executingBlocks.ProcessAllBlocks(blocks); executingBlocks.ProcessAllBlocks(blocks);
@ -604,7 +644,7 @@ namespace Fungus.EditorUtils
GUILayout.Space(2); GUILayout.Space(2);
// Draw add block button // Draw add block button
if (GUILayout.Button(new GUIContent(addTexture, "Add a new block"), EditorStyles.toolbarButton)) if (GUILayout.Button(addButtonContent, EditorStyles.toolbarButton))
{ {
DeselectAll(); DeselectAll();
Vector2 newNodePosition = new Vector2( Vector2 newNodePosition = new Vector2(
@ -638,7 +678,7 @@ namespace Fungus.EditorUtils
// Draw search bar // Draw search bar
GUI.SetNextControlName(searchFieldName); GUI.SetNextControlName(searchFieldName);
var newString = EditorGUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSeachTextField"), GUILayout.Width(150)); var newString = EditorGUILayout.TextField(searchString, ToolbarSeachTextFieldStyle, GUILayout.Width(150));
if (newString != searchString) if (newString != searchString)
{ {
searchString = newString; searchString = newString;
@ -654,7 +694,7 @@ namespace Fungus.EditorUtils
popupRect.height = Mathf.Min(filteredBlocks.Length * 16, position.height - 22); popupRect.height = Mathf.Min(filteredBlocks.Length * 16, position.height - 22);
} }
if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton"))) if (GUILayout.Button("", ToolbarSeachCancelButtonStyle))
{ {
CloseBlockPopup(); CloseBlockPopup();
} }
@ -689,7 +729,18 @@ namespace Fungus.EditorUtils
GUILayout.EndVertical(); GUILayout.EndVertical();
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
DrawVariablesBlock(e);
// Draw block search popup on top of other controls
if (GUI.GetNameOfFocusedControl() == searchFieldName && filteredBlocks.Length > 0)
{
DrawBlockPopup(e);
}
}
protected virtual void DrawVariablesBlock(Event e)
{
// Variables group // Variables group
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
{ {
@ -716,11 +767,17 @@ namespace Fungus.EditorUtils
} }
} }
if(EditorGUI.EndChangeCheck()) if (EditorGUI.EndChangeCheck())
{ {
EditorUtility.SetDirty(flowchart); EditorUtility.SetDirty(flowchart);
} }
}
GUILayout.EndScrollView();
// Eat mouse events
if (e.type == EventType.MouseDown)
{
Rect variableWindowRect = GUILayoutUtility.GetLastRect(); Rect variableWindowRect = GUILayoutUtility.GetLastRect();
if (flowchart.VariablesExpanded && flowchart.Variables.Count > 0) if (flowchart.VariablesExpanded && flowchart.Variables.Count > 0)
{ {
@ -728,29 +785,17 @@ namespace Fungus.EditorUtils
variableWindowRect.height += 20; variableWindowRect.height += 20;
} }
// Eat mouse events if (variableWindowRect.Contains(e.mousePosition))
if (e.type == EventType.MouseDown)
{
if (e.mousePosition.x <= variableWindowRect.width &&
e.mousePosition.y <= variableWindowRect.height)
{ {
e.Use(); e.Use();
} }
} }
} }
GUILayout.EndScrollView();
}
GUILayout.EndVertical(); GUILayout.EndVertical();
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
// Draw block search popup on top of other controls
if (GUI.GetNameOfFocusedControl() == searchFieldName && filteredBlocks.Length > 0)
{
DrawBlockPopup(e);
}
} }
protected virtual void DrawBlockPopup(Event e) protected virtual void DrawBlockPopup(Event e)

44
Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs

@ -30,6 +30,10 @@ namespace Fungus.EditorUtils
private ReorderableList list; private ReorderableList list;
public Flowchart TargetFlowchart { get; private set; } public Flowchart TargetFlowchart { get; private set; }
private float[] itemWidths = new float[4];
private Rect[] itemRects = new Rect[4];
private GUIContent emptyGUIContent = new GUIContent("");
public SerializedProperty this[int index] public SerializedProperty this[int index]
{ {
get { return _arrayProperty.GetArrayElementAtIndex(index); } get { return _arrayProperty.GetArrayElementAtIndex(index); }
@ -111,9 +115,18 @@ namespace Fungus.EditorUtils
if (_arrayProperty == null || _arrayProperty.serializedObject == null) if (_arrayProperty == null || _arrayProperty.serializedObject == null)
return; return;
_arrayProperty.serializedObject.Update(); _arrayProperty.serializedObject.Update();
this.widthOfList = (w == 0 ? VariableListAdaptor.DefaultWidth : w) - ScrollSpacer; this.widthOfList = (w == 0 ? VariableListAdaptor.DefaultWidth : w) - ScrollSpacer;
int width = widthOfList;
int totalRatio = DefaultWidth;
itemWidths[0] = (80.0f / totalRatio) * width;
itemWidths[1] = (100.0f / totalRatio) * width;
itemWidths[2] = (140.0f / totalRatio) * width;
itemWidths[3] = (60.0f / totalRatio) * width;
if (GUILayout.Button("Variables")) if (GUILayout.Button("Variables"))
{ {
_arrayProperty.isExpanded = !_arrayProperty.isExpanded; _arrayProperty.isExpanded = !_arrayProperty.isExpanded;
@ -139,24 +152,14 @@ namespace Fungus.EditorUtils
return; return;
} }
int width = widthOfList;
int totalRatio = DefaultWidth;
float[] widths = { (80.0f/ totalRatio) * width,
(100.0f / totalRatio) * width,
(140.0f/ totalRatio) * width,
(60.0f/ totalRatio) * width };
Rect[] rects = new Rect[4];
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
{ {
rects[i] = position; itemRects[i] = position;
rects[i].width = widths[i] - 5; itemRects[i].width = itemWidths[i] - 5;
for (int j = 0; j < i; ++j) for (int j = 0; j < i; ++j)
{ {
rects[i].x += widths[j]; itemRects[i].x += itemWidths[j];
} }
} }
@ -213,14 +216,19 @@ namespace Fungus.EditorUtils
variableObject.Update(); variableObject.Update();
GUI.Label(rects[0], variableInfo.VariableType); GUI.Label(itemRects[0], variableInfo.VariableType);
key = EditorGUI.TextField(rects[1], variable.Key);
SerializedProperty keyProp = variableObject.FindProperty("key"); SerializedProperty keyProp = variableObject.FindProperty("key");
SerializedProperty defaultProp = variableObject.FindProperty("value"); SerializedProperty defaultProp = variableObject.FindProperty("value");
SerializedProperty scopeProp = variableObject.FindProperty("scope"); SerializedProperty scopeProp = variableObject.FindProperty("scope");
EditorGUI.BeginChangeCheck();
key = EditorGUI.TextField(itemRects[1], variable.Key);
if (EditorGUI.EndChangeCheck())
{
keyProp.stringValue = flowchart.GetUniqueVariableKey(key, variable); keyProp.stringValue = flowchart.GetUniqueVariableKey(key, variable);
}
bool isGlobal = scopeProp.enumValueIndex == (int)VariableScope.Global; bool isGlobal = scopeProp.enumValueIndex == (int)VariableScope.Global;
@ -236,18 +244,18 @@ namespace Fungus.EditorUtils
var prevEnabled = GUI.enabled; var prevEnabled = GUI.enabled;
GUI.enabled = false; GUI.enabled = false;
EditorGUI.PropertyField(rects[2], globalValProp, new GUIContent("")); EditorGUI.PropertyField(itemRects[2], globalValProp, emptyGUIContent);
GUI.enabled = prevEnabled; GUI.enabled = prevEnabled;
} }
} }
else else
{ {
EditorGUI.PropertyField(rects[2], defaultProp, new GUIContent("")); EditorGUI.PropertyField(itemRects[2], defaultProp, emptyGUIContent);
} }
scope = (VariableScope)EditorGUI.EnumPopup(rects[3], variable.Scope); scope = (VariableScope)EditorGUI.EnumPopup(itemRects[3], variable.Scope);
scopeProp.enumValueIndex = (int)scope; scopeProp.enumValueIndex = (int)scope;
variableObject.ApplyModifiedProperties(); variableObject.ApplyModifiedProperties();

Loading…
Cancel
Save