Browse Source

Replaced slow calls to FindObjectOfType() and FindDerivedTypes()

master
Christopher 8 years ago
parent
commit
367f0527f4
  1. 22
      Assets/Fungus/Scripts/Editor/BlockEditor.cs
  2. 12
      Assets/Fungus/Scripts/Editor/FlowchartWindow.cs
  3. 2
      Assets/Fungus/Scripts/Editor/VariableEditor.cs

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

@ -39,6 +39,21 @@ namespace Fungus.EditorUtils
protected Texture2D duplicateIcon; protected Texture2D duplicateIcon;
protected Texture2D deleteIcon; protected Texture2D deleteIcon;
static List<System.Type> commandTypes;
static List<System.Type> eventHandlerTypes;
static void CacheEventHandlerTypes()
{
eventHandlerTypes = EditorExtensions.FindDerivedTypes(typeof(EventHandler)).ToList();
commandTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList();
}
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnScriptsReloaded()
{
CacheEventHandlerTypes();
}
protected virtual void OnEnable() protected virtual void OnEnable()
{ {
upIcon = FungusEditorResources.Up; upIcon = FungusEditorResources.Up;
@ -46,6 +61,8 @@ namespace Fungus.EditorUtils
addIcon = FungusEditorResources.Add; addIcon = FungusEditorResources.Add;
duplicateIcon = FungusEditorResources.Duplicate; duplicateIcon = FungusEditorResources.Duplicate;
deleteIcon = FungusEditorResources.Delete; deleteIcon = FungusEditorResources.Delete;
CacheEventHandlerTypes();
} }
public virtual void DrawBlockName(Flowchart flowchart) public virtual void DrawBlockName(Flowchart flowchart)
@ -317,8 +334,6 @@ namespace Fungus.EditorUtils
{ {
// Show available Event Handlers in a drop down list with type of current // Show available Event Handlers in a drop down list with type of current
// event handler selected. // event handler selected.
List<System.Type> eventHandlerTypes = EditorExtensions.FindDerivedTypes(typeof(EventHandler)).ToList();
Block block = target as Block; Block block = target as Block;
System.Type currentType = null; System.Type currentType = null;
if (block._EventHandler != null) if (block._EventHandler != null)
@ -667,8 +682,7 @@ namespace Fungus.EditorUtils
GenericMenu commandMenu = new GenericMenu(); GenericMenu commandMenu = new GenericMenu();
// Build menu list // Build menu list
List<System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList(); List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = GetFilteredCommandInfoAttribute(commandTypes);
List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = GetFilteredCommandInfoAttribute(menuTypes);
filteredAttributes.Sort( CompareCommandAttributes ); filteredAttributes.Sort( CompareCommandAttributes );

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

@ -133,6 +133,7 @@ namespace Fungus.EditorUtils
protected Flowchart flowchart; protected Flowchart flowchart;
protected Block[] blocks; protected Block[] blocks;
protected Block dragBlock; protected Block dragBlock;
protected static FungusState fungusState;
[MenuItem("Tools/Fungus/Flowchart Window")] [MenuItem("Tools/Fungus/Flowchart Window")]
static void Init() static void Init()
@ -205,12 +206,15 @@ namespace Fungus.EditorUtils
{ {
// Using a temp hidden object to track the active Flowchart across // Using a temp hidden object to track the active Flowchart across
// serialization / deserialization when playing the game in the editor. // serialization / deserialization when playing the game in the editor.
FungusState fungusState = GameObject.FindObjectOfType<FungusState>();
if (fungusState == null) if (fungusState == null)
{ {
GameObject go = new GameObject("_FungusState"); fungusState = GameObject.FindObjectOfType<FungusState>();
go.hideFlags = HideFlags.HideInHierarchy; if (fungusState == null)
fungusState = go.AddComponent<FungusState>(); {
GameObject go = new GameObject("_FungusState");
go.hideFlags = HideFlags.HideInHierarchy;
fungusState = go.AddComponent<FungusState>();
}
} }
if (Selection.activeGameObject != null) if (Selection.activeGameObject != null)

2
Assets/Fungus/Scripts/Editor/VariableEditor.cs

@ -86,7 +86,7 @@ namespace Fungus.EditorUtils
} }
} }
Flowchart[] fsList = GameObject.FindObjectsOfType<Flowchart>(); List<Flowchart> fsList = Flowchart.CachedFlowcharts;
foreach (Flowchart fs in fsList) foreach (Flowchart fs in fsList)
{ {
if (fs == flowchart) if (fs == flowchart)

Loading…
Cancel
Save