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 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()
{
upIcon = FungusEditorResources.Up;
@ -46,6 +61,8 @@ namespace Fungus.EditorUtils
addIcon = FungusEditorResources.Add;
duplicateIcon = FungusEditorResources.Duplicate;
deleteIcon = FungusEditorResources.Delete;
CacheEventHandlerTypes();
}
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
// event handler selected.
List<System.Type> eventHandlerTypes = EditorExtensions.FindDerivedTypes(typeof(EventHandler)).ToList();
Block block = target as Block;
System.Type currentType = null;
if (block._EventHandler != null)
@ -667,8 +682,7 @@ namespace Fungus.EditorUtils
GenericMenu commandMenu = new GenericMenu();
// Build menu list
List<System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList();
List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = GetFilteredCommandInfoAttribute(menuTypes);
List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = GetFilteredCommandInfoAttribute(commandTypes);
filteredAttributes.Sort( CompareCommandAttributes );

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

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

Loading…
Cancel
Save