Browse Source

Fixed #45 by merging branch 'Exort-develop'

master
chrisgregan 10 years ago
parent
commit
295411ae9e
  1. 41
      Assets/Fungus/FungusScript/Editor/CommandListAdaptor.cs
  2. 4
      Assets/Fungus/FungusScript/Scripts/Command.cs

41
Assets/Fungus/FungusScript/Editor/CommandListAdaptor.cs

@ -337,6 +337,27 @@ namespace Fungus
// Build menu list // Build menu list
List<System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList(); List<System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList();
List<KeyValuePair<System.Type, CommandInfoAttribute>> 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<KeyValuePair<System.Type,CommandInfoAttribute>> GetFilteredCommandInfoAttribute(List<System.Type> menuTypes)
{
Dictionary<string, KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = new Dictionary<string, KeyValuePair<System.Type, CommandInfoAttribute>>();
foreach (System.Type type in menuTypes) foreach (System.Type type in menuTypes)
{ {
object[] attributes = type.GetCustomAttributes(false); object[] attributes = type.GetCustomAttributes(false);
@ -345,19 +366,23 @@ namespace Fungus
CommandInfoAttribute infoAttr = obj as CommandInfoAttribute; CommandInfoAttribute infoAttr = obj as CommandInfoAttribute;
if (infoAttr != null) if (infoAttr != null)
{ {
SetCommandOperation commandOperation = new SetCommandOperation(); string dictionaryName = string.Format("{0}/{1}", infoAttr.Category, infoAttr.CommandName);
commandOperation.sequence = sequence; int existingItemPriority = -1;
commandOperation.commandType = type; if (filteredAttributes.ContainsKey(dictionaryName))
commandOperation.index = index; {
existingItemPriority = filteredAttributes[dictionaryName].Value.Priority;
}
commandMenu.AddItem (new GUIContent (infoAttr.Category + "/" + infoAttr.CommandName), if (infoAttr.Priority > existingItemPriority)
false, Callback, commandOperation); {
KeyValuePair<System.Type, CommandInfoAttribute> keyValuePair = new KeyValuePair<System.Type, CommandInfoAttribute>(type, infoAttr);
filteredAttributes[dictionaryName] = keyValuePair;
} }
} }
} }
}
commandMenu.ShowAsContext(); return filteredAttributes.Values.ToList<KeyValuePair<System.Type,CommandInfoAttribute>>();
} }
void Callback(object obj) void Callback(object obj)

4
Assets/Fungus/FungusScript/Scripts/Command.cs

@ -8,16 +8,18 @@ namespace Fungus
public class CommandInfoAttribute : Attribute 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.Category = category;
this.CommandName = commandName; this.CommandName = commandName;
this.HelpText = helpText; this.HelpText = helpText;
this.Priority = priority;
} }
public string Category { get; set; } public string Category { get; set; }
public string CommandName { get; set; } public string CommandName { get; set; }
public string HelpText { get; set; } public string HelpText { get; set; }
public int Priority { get; set; }
} }
public class Command : MonoBehaviour public class Command : MonoBehaviour

Loading…
Cancel
Save