From 295411ae9e6915824b82af5c4de3e8a3f5d27052 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Fri, 10 Oct 2014 11:42:18 +0100 Subject: [PATCH] Fixed #45 by merging branch 'Exort-develop' --- .../FungusScript/Editor/CommandListAdaptor.cs | 49 ++++++++++++++----- Assets/Fungus/FungusScript/Scripts/Command.cs | 4 +- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Assets/Fungus/FungusScript/Editor/CommandListAdaptor.cs b/Assets/Fungus/FungusScript/Editor/CommandListAdaptor.cs index aed01f8e..0427d360 100644 --- a/Assets/Fungus/FungusScript/Editor/CommandListAdaptor.cs +++ b/Assets/Fungus/FungusScript/Editor/CommandListAdaptor.cs @@ -337,7 +337,28 @@ namespace Fungus // Build menu list List menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList(); - foreach(System.Type type in menuTypes) + List> filteredAttributes = GetFilteredCommandInfoAttribute(menuTypes); + + foreach(var keyPair in filteredAttributes) + { + SetCommandOperation commandOperation = new SetCommandOperation(); + + commandOperation.sequence = sequence; + commandOperation.commandType = keyPair.Key; + commandOperation.index = index; + + commandMenu.AddItem (new GUIContent (keyPair.Value.Category + "/" + keyPair.Value.CommandName), + false, Callback, commandOperation); + } + + commandMenu.ShowAsContext(); + } + + List> GetFilteredCommandInfoAttribute(List menuTypes) + { + Dictionary> filteredAttributes = new Dictionary>(); + + foreach (System.Type type in menuTypes) { object[] attributes = type.GetCustomAttributes(false); foreach (object obj in attributes) @@ -345,21 +366,25 @@ namespace Fungus CommandInfoAttribute infoAttr = obj as CommandInfoAttribute; if (infoAttr != null) { - SetCommandOperation commandOperation = new SetCommandOperation(); - - commandOperation.sequence = sequence; - commandOperation.commandType = type; - commandOperation.index = index; - - commandMenu.AddItem (new GUIContent (infoAttr.Category + "/" + infoAttr.CommandName), - false, Callback, commandOperation); + string dictionaryName = string.Format("{0}/{1}", infoAttr.Category, infoAttr.CommandName); + + int existingItemPriority = -1; + if (filteredAttributes.ContainsKey(dictionaryName)) + { + existingItemPriority = filteredAttributes[dictionaryName].Value.Priority; + } + + if (infoAttr.Priority > existingItemPriority) + { + KeyValuePair keyValuePair = new KeyValuePair(type, infoAttr); + filteredAttributes[dictionaryName] = keyValuePair; + } } } } - - commandMenu.ShowAsContext(); + return filteredAttributes.Values.ToList>(); } - + void Callback(object obj) { SetCommandOperation commandOperation = obj as SetCommandOperation; diff --git a/Assets/Fungus/FungusScript/Scripts/Command.cs b/Assets/Fungus/FungusScript/Scripts/Command.cs index a4065832..76b3d4ce 100644 --- a/Assets/Fungus/FungusScript/Scripts/Command.cs +++ b/Assets/Fungus/FungusScript/Scripts/Command.cs @@ -8,16 +8,18 @@ namespace Fungus public class CommandInfoAttribute : Attribute { - public CommandInfoAttribute(string category, string commandName, string helpText) + public CommandInfoAttribute(string category, string commandName, string helpText, int priority = 0) { this.Category = category; this.CommandName = commandName; this.HelpText = helpText; + this.Priority = priority; } public string Category { get; set; } public string CommandName { get; set; } public string HelpText { get; set; } + public int Priority { get; set; } } public class Command : MonoBehaviour