Browse Source

Merge pull request #637 from stevehalliwell/MultipleCommandInfos

Allow multiple CommandInfos to be added to a class
master
Steve Halliwell 7 years ago committed by GitHub
parent
commit
5389e97ce6
  1. 6
      Assets/Fungus/Scripts/Commands/SpawnObject.cs
  2. 2
      Assets/Fungus/Scripts/Components/Command.cs
  3. 9
      Assets/Fungus/Scripts/Editor/CommandEditor.cs

6
Assets/Fungus/Scripts/Commands/SpawnObject.cs

@ -11,7 +11,11 @@ namespace Fungus
/// </summary> /// </summary>
[CommandInfo("Scripting", [CommandInfo("Scripting",
"Spawn Object", "Spawn Object",
"Spawns a new object based on a reference to a scene or prefab game object.")] "Spawns a new object based on a reference to a scene or prefab game object.",
Priority = 10)]
[CommandInfo("GameObject",
"Instantiate",
"Instantiate a game object")]
[AddComponentMenu("")] [AddComponentMenu("")]
[ExecuteInEditMode] [ExecuteInEditMode]
public class SpawnObject : Command public class SpawnObject : Command

2
Assets/Fungus/Scripts/Components/Command.cs

@ -11,6 +11,8 @@ namespace Fungus
/// <summary> /// <summary>
/// Attribute class for Fungus commands. /// Attribute class for Fungus commands.
/// </summary> /// </summary>
///
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class CommandInfoAttribute : Attribute public class CommandInfoAttribute : Attribute
{ {
/// <summary> /// <summary>

9
Assets/Fungus/Scripts/Editor/CommandEditor.cs

@ -16,17 +16,22 @@ namespace Fungus.EditorUtils
public static CommandInfoAttribute GetCommandInfo(System.Type commandType) public static CommandInfoAttribute GetCommandInfo(System.Type commandType)
{ {
CommandInfoAttribute retval = null;
object[] attributes = commandType.GetCustomAttributes(typeof(CommandInfoAttribute), false); object[] attributes = commandType.GetCustomAttributes(typeof(CommandInfoAttribute), false);
foreach (object obj in attributes) foreach (object obj in attributes)
{ {
CommandInfoAttribute commandInfoAttr = obj as CommandInfoAttribute; CommandInfoAttribute commandInfoAttr = obj as CommandInfoAttribute;
if (commandInfoAttr != null) if (commandInfoAttr != null)
{ {
return commandInfoAttr; if (retval == null)
retval = commandInfoAttr;
else if (retval.Priority < commandInfoAttr.Priority)
retval = commandInfoAttr;
} }
} }
return null; return retval;
} }
public virtual void DrawCommandInspectorGUI() public virtual void DrawCommandInspectorGUI()

Loading…
Cancel
Save