Browse Source

Merge pull request #728 from stevehalliwell/FlowchartWindowPerfOptimisation

FlowchartWindow performance improvements and optimization
master
Chris Gregan 6 years ago committed by GitHub
parent
commit
2da8a0f7ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      Assets/Fungus/Scripts/Components/Block.cs
  2. 53
      Assets/Fungus/Scripts/Components/Flowchart.cs
  3. 17
      Assets/Fungus/Scripts/Editor/BlockEditor.cs
  4. 6
      Assets/Fungus/Scripts/Editor/CommandEditor.cs
  5. 11
      Assets/Fungus/Scripts/Editor/FlowchartEditor.cs
  6. 763
      Assets/Fungus/Scripts/Editor/FlowchartWindow.cs
  7. 2
      Assets/Fungus/Scripts/Editor/PopupContent/EventSelectorPopupWindowContent.cs
  8. 46
      Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs
  9. 20382
      Assets/Tests/Perf/ManyBlocks_700+.unity
  10. 7
      Assets/Tests/Perf/ManyBlocks_700+.unity.meta

5
Assets/Fungus/Scripts/Components/Block.cs

@ -111,6 +111,11 @@ namespace Fungus
command.CommandIndex = index++;
}
}
//editor only state for speeding up flowchart window drawing
public bool IsSelected { get; set; } //local cache of selectedness
public bool IsFiltered { get; set; } //local cache of filteredness
public bool IsControlSelected { get; set; } //local cache of being part of the control exclusion group
#endif
#region Public members

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

@ -88,6 +88,10 @@ namespace Fungus
protected StringSubstituter stringSubstituer;
#if UNITY_EDITOR
public bool SelectedCommandsStale { get; set; }
#endif
#if UNITY_5_4_OR_NEWER
#else
protected virtual void OnLevelWasLoaded(int level)
@ -335,6 +339,7 @@ namespace Fungus
/// </summary>
public virtual Rect ScrollViewRect { get { return scrollViewRect; } set { scrollViewRect = value; } }
#if UNITY_EDITOR
/// <summary>
/// Current actively selected block in the Flowchart editor.
/// </summary>
@ -342,17 +347,21 @@ namespace Fungus
{
get
{
return selectedBlocks.FirstOrDefault();
if (selectedBlocks == null || selectedBlocks.Count == 0)
return null;
return selectedBlocks[0];
}
set
{
selectedBlocks.Clear();
selectedBlocks.Add(value);
ClearSelectedBlocks();
AddSelectedBlock(value);
}
}
public virtual List<Block> SelectedBlocks { get { return selectedBlocks; } set { selectedBlocks = value; } }
#endif
/// <summary>
/// Currently selected command in the Flowchart editor.
/// </summary>
@ -363,6 +372,8 @@ namespace Fungus
/// </summary>
public virtual List<Variable> Variables { get { return variables; } }
public virtual int VariableCount { get { return variables.Count; } }
/// <summary>
/// Description text displayed in the Flowchart editor window
/// </summary>
@ -1096,6 +1107,9 @@ namespace Fungus
public virtual void ClearSelectedCommands()
{
selectedCommands.Clear();
#if UNITY_EDITOR
SelectedCommandsStale = true;
#endif
}
/// <summary>
@ -1106,14 +1120,22 @@ namespace Fungus
if (!selectedCommands.Contains(command))
{
selectedCommands.Add(command);
#if UNITY_EDITOR
SelectedCommandsStale = true;
#endif
}
}
#if UNITY_EDITOR
/// <summary>
/// Clears the list of selected blocks.
/// </summary>
public virtual void ClearSelectedBlocks()
{
foreach (var item in selectedBlocks)
{
item.IsSelected = false;
}
selectedBlocks.Clear();
}
@ -1124,10 +1146,35 @@ namespace Fungus
{
if (!selectedBlocks.Contains(block))
{
block.IsSelected = true;
selectedBlocks.Add(block);
}
}
public virtual bool DeselectBlock(Block block)
{
if (selectedBlocks.Contains(block))
{
DeselectBlockNoCheck(block);
return true;
}
return false;
}
public virtual void DeselectBlockNoCheck(Block b)
{
b.IsSelected = false;
selectedBlocks.Remove(b);
}
public void UpdateSelectedCache()
{
selectedBlocks.Clear();
var res = gameObject.GetComponents<Block>();
selectedBlocks = res.Where(x => x.IsSelected).ToList();
}
#endif
/// <summary>
/// Reset the commands and variables in the Flowchart.
/// </summary>

17
Assets/Fungus/Scripts/Editor/BlockEditor.cs

@ -19,6 +19,8 @@ namespace Fungus.EditorUtils
{
public static List<Action> actionList = new List<Action>();
public static bool SelectedBlockDataStale { get; set; }
protected Texture2D upIcon;
protected Texture2D downIcon;
protected Texture2D addIcon;
@ -110,6 +112,8 @@ namespace Fungus.EditorUtils
}
EditorGUI.BeginChangeCheck();
if (block == flowchart.SelectedBlock)
{
// Custom tinting
@ -261,6 +265,12 @@ namespace Fungus.EditorUtils
}
}
if (EditorGUI.EndChangeCheck())
{
SelectedBlockDataStale = true;
}
serializedObject.ApplyModifiedProperties();
}
@ -374,7 +384,14 @@ namespace Fungus.EditorUtils
EventHandlerEditor eventHandlerEditor = Editor.CreateEditor(block._EventHandler) as EventHandlerEditor;
if (eventHandlerEditor != null)
{
EditorGUI.BeginChangeCheck();
eventHandlerEditor.DrawInspectorGUI();
if(EditorGUI.EndChangeCheck())
{
SelectedBlockDataStale = true;
}
DestroyImmediate(eventHandlerEditor);
}
}

6
Assets/Fungus/Scripts/Editor/CommandEditor.cs

@ -13,6 +13,7 @@ namespace Fungus.EditorUtils
{
#region statics
public static Command selectedCommand;
public static bool SelectedCommandDataStale { get; set; }
public static CommandInfoAttribute GetCommandInfo(System.Type commandType)
{
@ -109,7 +110,12 @@ namespace Fungus.EditorUtils
EditorGUILayout.Separator();
EditorGUI.BeginChangeCheck();
DrawCommandGUI();
if(EditorGUI.EndChangeCheck())
{
SelectedCommandDataStale = true;
}
EditorGUILayout.Separator();

11
Assets/Fungus/Scripts/Editor/FlowchartEditor.cs

@ -28,6 +28,9 @@ namespace Fungus.EditorUtils
protected VariableListAdaptor variableListAdaptor;
public static bool FlowchartDataStale { get; set; }
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
@ -58,6 +61,8 @@ namespace Fungus.EditorUtils
flowchart.UpdateHideFlags();
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(descriptionProp);
EditorGUILayout.PropertyField(colorCommandsProp);
EditorGUILayout.PropertyField(hideComponentsProp);
@ -73,6 +78,12 @@ namespace Fungus.EditorUtils
//ReorderableListGUI.ListField(hideCommandsProp);
EditorGUILayout.PropertyField(hideCommandsProp, new GUIContent(hideCommandsProp.displayName, hideCommandsProp.tooltip), true);
if(EditorGUI.EndChangeCheck())
{
FlowchartDataStale = true;
}
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button(new GUIContent("Open Flowchart Window", "Opens the Flowchart Window")))

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

File diff suppressed because it is too large Load Diff

2
Assets/Fungus/Scripts/Editor/PopupContent/EventSelectorPopupWindowContent.cs

@ -149,6 +149,8 @@ namespace Fungus.EditorUtils
block._EventHandler = newHandler;
}
BlockEditor.SelectedBlockDataStale = true;
// Because this is an async call, we need to force prefab instances to record changes
PrefabUtility.RecordPrefabInstancePropertyModifications(block);
}

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

@ -30,6 +30,10 @@ namespace Fungus.EditorUtils
private ReorderableList list;
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]
{
get { return _arrayProperty.GetArrayElementAtIndex(index); }
@ -111,9 +115,18 @@ namespace Fungus.EditorUtils
if (_arrayProperty == null || _arrayProperty.serializedObject == null)
return;
_arrayProperty.serializedObject.Update();
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"))
{
_arrayProperty.isExpanded = !_arrayProperty.isExpanded;
@ -139,24 +152,14 @@ namespace Fungus.EditorUtils
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)
{
rects[i] = position;
rects[i].width = widths[i] - 5;
itemRects[i] = position;
itemRects[i].width = itemWidths[i] - 5;
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();
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 defaultProp = variableObject.FindProperty("value");
SerializedProperty scopeProp = variableObject.FindProperty("scope");
keyProp.stringValue = flowchart.GetUniqueVariableKey(key, variable);
EditorGUI.BeginChangeCheck();
key = EditorGUI.TextField(itemRects[1], variable.Key);
if (EditorGUI.EndChangeCheck())
{
keyProp.stringValue = flowchart.GetUniqueVariableKey(key, variable);
}
bool isGlobal = scopeProp.enumValueIndex == (int)VariableScope.Global;
@ -236,18 +244,18 @@ namespace Fungus.EditorUtils
var prevEnabled = GUI.enabled;
GUI.enabled = false;
EditorGUI.PropertyField(rects[2], globalValProp, new GUIContent(""));
EditorGUI.PropertyField(itemRects[2], globalValProp, emptyGUIContent);
GUI.enabled = prevEnabled;
}
}
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;
variableObject.ApplyModifiedProperties();

20382
Assets/Tests/Perf/ManyBlocks_700+.unity

File diff suppressed because it is too large Load Diff

7
Assets/Tests/Perf/ManyBlocks_700+.unity.meta

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c4d1692b35ae833488af6eacb8029e26
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save