From b209d4fcd20b93893329c2dbddafd22eb6f48d68 Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Tue, 12 Sep 2017 20:00:27 +1000 Subject: [PATCH 1/2] Allow multiple CommandInfos to be added to a class SpawnObject can now also be found under GameObject/Instantiate --- Assets/Fungus/Scripts/Commands/SpawnObject.cs | 3 +++ Assets/Fungus/Scripts/Components/Command.cs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Assets/Fungus/Scripts/Commands/SpawnObject.cs b/Assets/Fungus/Scripts/Commands/SpawnObject.cs index 734243f3..a5d4f6c8 100644 --- a/Assets/Fungus/Scripts/Commands/SpawnObject.cs +++ b/Assets/Fungus/Scripts/Commands/SpawnObject.cs @@ -12,6 +12,9 @@ namespace Fungus [CommandInfo("Scripting", "Spawn Object", "Spawns a new object based on a reference to a scene or prefab game object.")] + [CommandInfo("GameObject", + "Instantiate", + "Instantiate a game object")] [AddComponentMenu("")] [ExecuteInEditMode] public class SpawnObject : Command diff --git a/Assets/Fungus/Scripts/Components/Command.cs b/Assets/Fungus/Scripts/Components/Command.cs index 64407984..0c63df11 100644 --- a/Assets/Fungus/Scripts/Components/Command.cs +++ b/Assets/Fungus/Scripts/Components/Command.cs @@ -11,6 +11,8 @@ namespace Fungus /// /// Attribute class for Fungus commands. /// + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public class CommandInfoAttribute : Attribute { /// From cc7bbf0db19666efc901a9fc48d13ee5463f5518 Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Tue, 19 Sep 2017 17:31:15 +1000 Subject: [PATCH 2/2] GetCommandInfo returns the highest priority CommandInfo to better support multiple names while maintaining what is shown in the inspector --- Assets/Fungus/Scripts/Commands/SpawnObject.cs | 3 ++- Assets/Fungus/Scripts/Editor/CommandEditor.cs | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Assets/Fungus/Scripts/Commands/SpawnObject.cs b/Assets/Fungus/Scripts/Commands/SpawnObject.cs index a5d4f6c8..35fed925 100644 --- a/Assets/Fungus/Scripts/Commands/SpawnObject.cs +++ b/Assets/Fungus/Scripts/Commands/SpawnObject.cs @@ -11,7 +11,8 @@ namespace Fungus /// [CommandInfo("Scripting", "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")] diff --git a/Assets/Fungus/Scripts/Editor/CommandEditor.cs b/Assets/Fungus/Scripts/Editor/CommandEditor.cs index 4f9f43f1..05ae1e17 100644 --- a/Assets/Fungus/Scripts/Editor/CommandEditor.cs +++ b/Assets/Fungus/Scripts/Editor/CommandEditor.cs @@ -16,17 +16,22 @@ namespace Fungus.EditorUtils public static CommandInfoAttribute GetCommandInfo(System.Type commandType) { + CommandInfoAttribute retval = null; + object[] attributes = commandType.GetCustomAttributes(typeof(CommandInfoAttribute), false); foreach (object obj in attributes) { CommandInfoAttribute commandInfoAttr = obj as CommandInfoAttribute; 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()