Browse Source

Merge pull request #738 from stevehalliwell/CorrectionOfStaticListCaching

Editor List Caching Fix
master
Steve Halliwell 6 years ago committed by GitHub
parent
commit
8a06c583f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      Assets/Fungus/Scripts/Editor/PopupContent/CommandSelectorPopupWindowContent.cs
  2. 27
      Assets/Fungus/Scripts/Editor/PopupContent/EventSelectorPopupWindowContent.cs
  3. 27
      Assets/Fungus/Scripts/Editor/PopupContent/VariableSelectPopupWindowContent.cs

26
Assets/Fungus/Scripts/Editor/PopupContent/CommandSelectorPopupWindowContent.cs

@ -11,11 +11,21 @@ namespace Fungus.EditorUtils
/// </summary> /// </summary>
public class CommandSelectorPopupWindowContent : BasePopupWindowContent public class CommandSelectorPopupWindowContent : BasePopupWindowContent
{ {
static List<System.Type> commandTypes; static List<System.Type> _commandTypes;
static List<System.Type> CommandTypes
{
get
{
if (_commandTypes == null || _commandTypes.Count == 0)
CacheCommandTypes();
return _commandTypes;
}
}
static void CacheCommandTypes() static void CacheCommandTypes()
{ {
commandTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).Where(x => !x.IsAbstract).ToList(); _commandTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).Where(x => !x.IsAbstract).ToList();
} }
[UnityEditor.Callbacks.DidReloadScripts] [UnityEditor.Callbacks.DidReloadScripts]
@ -34,24 +44,18 @@ namespace Fungus.EditorUtils
protected override void SelectByOrigIndex(int index) protected override void SelectByOrigIndex(int index)
{ {
var commandType = (index >= 0 && index < commandTypes.Count) ? commandTypes[index] : null; var commandType = (index >= 0 && index < CommandTypes.Count) ? CommandTypes[index] : null;
AddCommandCallback(commandType); AddCommandCallback(commandType);
} }
protected override void PrepareAllItems() protected override void PrepareAllItems()
{ {
if (commandTypes == null || commandTypes.Count == 0)
{
CacheCommandTypes();
}
filteredAttributes = GetFilteredSupportedCommands(curBlock.GetFlowchart()); filteredAttributes = GetFilteredSupportedCommands(curBlock.GetFlowchart());
foreach (var item in filteredAttributes) foreach (var item in filteredAttributes)
{ {
//force lookup to orig index here to account for commmand lists being filtered by users //force lookup to orig index here to account for commmand lists being filtered by users
var newFilteredItem = new FilteredListItem(commandTypes.IndexOf(item.Key), (item.Value.Category.Length > 0 ? item.Value.Category + CATEGORY_CHAR : "") + item.Value.CommandName, item.Value.HelpText); var newFilteredItem = new FilteredListItem(CommandTypes.IndexOf(item.Key), (item.Value.Category.Length > 0 ? item.Value.Category + CATEGORY_CHAR : "") + item.Value.CommandName, item.Value.HelpText);
allItems.Add(newFilteredItem); allItems.Add(newFilteredItem);
} }
} }
@ -79,7 +83,7 @@ namespace Fungus.EditorUtils
protected static List<KeyValuePair<System.Type, CommandInfoAttribute>> GetFilteredSupportedCommands(Flowchart flowchart) protected static List<KeyValuePair<System.Type, CommandInfoAttribute>> GetFilteredSupportedCommands(Flowchart flowchart)
{ {
List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = BlockEditor.GetFilteredCommandInfoAttribute(commandTypes); List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = BlockEditor.GetFilteredCommandInfoAttribute(CommandTypes);
filteredAttributes.Sort(BlockEditor.CompareCommandAttributes); filteredAttributes.Sort(BlockEditor.CompareCommandAttributes);

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

@ -11,11 +11,21 @@ namespace Fungus.EditorUtils
/// </summary> /// </summary>
public class EventSelectorPopupWindowContent : BasePopupWindowContent public class EventSelectorPopupWindowContent : BasePopupWindowContent
{ {
static List<System.Type> eventHandlerTypes; static List<System.Type> _eventHandlerTypes;
static List<System.Type> EventHandlerTypes
{
get
{
if (_eventHandlerTypes == null || _eventHandlerTypes.Count == 0)
CacheEventHandlerTypes();
return _eventHandlerTypes;
}
}
static void CacheEventHandlerTypes() static void CacheEventHandlerTypes()
{ {
eventHandlerTypes = EditorExtensions.FindDerivedTypes(typeof(EventHandler)).Where(x => !x.IsAbstract).ToList(); _eventHandlerTypes = EditorExtensions.FindDerivedTypes(typeof(EventHandler)).Where(x => !x.IsAbstract).ToList();
} }
[UnityEditor.Callbacks.DidReloadScripts] [UnityEditor.Callbacks.DidReloadScripts]
@ -39,13 +49,8 @@ namespace Fungus.EditorUtils
protected override void PrepareAllItems() protected override void PrepareAllItems()
{ {
if (eventHandlerTypes == null || eventHandlerTypes.Count == 0)
{
CacheEventHandlerTypes();
}
int i = 0; int i = 0;
foreach (System.Type type in eventHandlerTypes) foreach (System.Type type in EventHandlerTypes)
{ {
EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type); EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type);
if (info != null) if (info != null)
@ -65,7 +70,7 @@ namespace Fungus.EditorUtils
{ {
SetEventHandlerOperation operation = new SetEventHandlerOperation(); SetEventHandlerOperation operation = new SetEventHandlerOperation();
operation.block = block; operation.block = block;
operation.eventHandlerType = (index >= 0 && index < eventHandlerTypes.Count) ? eventHandlerTypes[index] : null; operation.eventHandlerType = (index >= 0 && index < EventHandlerTypes.Count) ? EventHandlerTypes[index] : null;
OnSelectEventHandler(operation); OnSelectEventHandler(operation);
} }
@ -93,7 +98,7 @@ namespace Fungus.EditorUtils
eventHandlerMenu.AddItem(new GUIContent("None"), false, OnSelectEventHandler, noneOperation); eventHandlerMenu.AddItem(new GUIContent("None"), false, OnSelectEventHandler, noneOperation);
// Add event handlers with no category first // Add event handlers with no category first
foreach (System.Type type in eventHandlerTypes) foreach (System.Type type in EventHandlerTypes)
{ {
EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type); EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type);
if (info != null && if (info != null &&
@ -108,7 +113,7 @@ namespace Fungus.EditorUtils
} }
// Add event handlers with a category afterwards // Add event handlers with a category afterwards
foreach (System.Type type in eventHandlerTypes) foreach (System.Type type in EventHandlerTypes)
{ {
EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type); EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type);
if (info != null && if (info != null &&

27
Assets/Fungus/Scripts/Editor/PopupContent/VariableSelectPopupWindowContent.cs

@ -12,12 +12,22 @@ namespace Fungus.EditorUtils
public class VariableSelectPopupWindowContent : BasePopupWindowContent public class VariableSelectPopupWindowContent : BasePopupWindowContent
{ {
static readonly int POPUP_WIDTH = 200, POPUP_HEIGHT = 200; static readonly int POPUP_WIDTH = 200, POPUP_HEIGHT = 200;
static List<System.Type> types; static List<System.Type> _variableTypes;
static List<System.Type> VariableTypes
{
get
{
if (_variableTypes == null || _variableTypes.Count == 0)
CacheVariableTypes();
return _variableTypes;
}
}
static void CacheVariableTypes() static void CacheVariableTypes()
{ {
var derivedType = typeof(Variable); var derivedType = typeof(Variable);
types = EditorExtensions.FindDerivedTypes(derivedType) _variableTypes = EditorExtensions.FindDerivedTypes(derivedType)
.Where(x => !x.IsAbstract && derivedType.IsAssignableFrom(x)) .Where(x => !x.IsAbstract && derivedType.IsAssignableFrom(x))
.ToList(); .ToList();
} }
@ -30,13 +40,8 @@ namespace Fungus.EditorUtils
protected override void PrepareAllItems() protected override void PrepareAllItems()
{ {
if(types == null || types.Count == 0)
{
CacheVariableTypes();
}
int i = 0; int i = 0;
foreach (var item in types) foreach (var item in VariableTypes)
{ {
VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(item); VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(item);
if (variableInfo != null) if (variableInfo != null)
@ -50,7 +55,7 @@ namespace Fungus.EditorUtils
protected override void SelectByOrigIndex(int index) protected override void SelectByOrigIndex(int index)
{ {
AddVariable(types[index]); AddVariable(VariableTypes[index]);
} }
static public void DoAddVariable(Rect position, string currentHandlerName, Flowchart flowchart) static public void DoAddVariable(Rect position, string currentHandlerName, Flowchart flowchart)
@ -71,7 +76,7 @@ namespace Fungus.EditorUtils
GenericMenu menu = new GenericMenu(); GenericMenu menu = new GenericMenu();
// Add variable types without a category // Add variable types without a category
foreach (var type in types) foreach (var type in VariableTypes)
{ {
VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type); VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type);
if (variableInfo == null || if (variableInfo == null ||
@ -86,7 +91,7 @@ namespace Fungus.EditorUtils
} }
// Add types with a category // Add types with a category
foreach (var type in types) foreach (var type in VariableTypes)
{ {
VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type); VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type);
if (variableInfo == null || if (variableInfo == null ||

Loading…
Cancel
Save