Browse Source

Fixed #45 by merging branch 'Exort-develop'

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

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

@ -337,7 +337,28 @@ namespace Fungus
// Build menu list
List<System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList();
foreach(System.Type type in menuTypes)
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)
{
object[] attributes = type.GetCustomAttributes(false);
foreach (object obj in attributes)
@ -345,19 +366,23 @@ 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<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)

4
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

Loading…
Cancel
Save