diff --git a/Assets/Fungus/Audio/Commands/PlayMusic.cs b/Assets/Fungus/Audio/Commands/PlayMusic.cs index dee22250..12851f56 100644 --- a/Assets/Fungus/Audio/Commands/PlayMusic.cs +++ b/Assets/Fungus/Audio/Commands/PlayMusic.cs @@ -3,9 +3,10 @@ using System.Collections; namespace Fungus.Script { - [CommandCategory("Audio")] - [CommandName("Play Music")] - [HelpText("Plays game music. If any game music is already playing, it is stopped. Music continues playing across scene loads.")] + [CommandInfo("Audio", + "Play Music", + "Plays game music. If any game music is already playing, it is stopped. Music continues playing across scene loads.", + 1,1,1)] public class PlayMusic : FungusCommand { public AudioClip musicClip; diff --git a/Assets/Fungus/Audio/Commands/PlaySound.cs b/Assets/Fungus/Audio/Commands/PlaySound.cs index 8ac91ac5..033e4496 100644 --- a/Assets/Fungus/Audio/Commands/PlaySound.cs +++ b/Assets/Fungus/Audio/Commands/PlaySound.cs @@ -3,9 +3,10 @@ using System.Collections; namespace Fungus.Script { - [CommandCategory("Audio")] - [CommandName("Play Sound")] - [HelpText("Plays a sound effect. Multiple sound effects can play at the same time.")] + [CommandInfo("Audio", + "Play Sound", + "Plays a sound effect. Multiple sound effects can play at the same time.", + 1,1,1)] public class PlaySound : FungusCommand { public AudioClip soundClip; diff --git a/Assets/Fungus/Audio/Commands/SetMusicVolume.cs b/Assets/Fungus/Audio/Commands/SetMusicVolume.cs index 5d0e31c9..be4a01b3 100644 --- a/Assets/Fungus/Audio/Commands/SetMusicVolume.cs +++ b/Assets/Fungus/Audio/Commands/SetMusicVolume.cs @@ -3,9 +3,10 @@ using System.Collections; namespace Fungus.Script { - [CommandCategory("Audio")] - [CommandName("Set Music Volume")] - [HelpText("Sets the game music volume level.")] + [CommandInfo("Audio", + "Set Music Volume", + "Sets the game music volume level.", + 1,1,1)] public class SetMusicVolume : FungusCommand { [Range(0,1)] diff --git a/Assets/Fungus/Audio/Commands/StopMusic.cs b/Assets/Fungus/Audio/Commands/StopMusic.cs index ceb92e20..c9257f62 100644 --- a/Assets/Fungus/Audio/Commands/StopMusic.cs +++ b/Assets/Fungus/Audio/Commands/StopMusic.cs @@ -3,9 +3,10 @@ using System.Collections; namespace Fungus.Script { - [CommandCategory("Audio")] - [CommandName("Stop Music")] - [HelpText("Stops the currently playing game music.")] + [CommandInfo("Audio", + "Stop Music", + "Stops the currently playing game music.", + 1,1,1)] public class StopMusic : FungusCommand { public override void OnEnter() diff --git a/Assets/Fungus/Camera/Commands/FadeToView.cs b/Assets/Fungus/Camera/Commands/FadeToView.cs index a6ee8b3f..7ce041f5 100644 --- a/Assets/Fungus/Camera/Commands/FadeToView.cs +++ b/Assets/Fungus/Camera/Commands/FadeToView.cs @@ -4,9 +4,10 @@ using System.Collections; namespace Fungus.Script { - [CommandCategory("Camera")] - [CommandName("Fade To View")] - [HelpText("Fades the camera out and in again at a location specified by a View object.")] + [CommandInfo("Camera", + "Fade To View", + "Fades the camera out and in again at a location specified by a View object.", + 1,1,1)] public class FadeToView : FungusCommand { public float duration; diff --git a/Assets/Fungus/Camera/Commands/MoveToView.cs b/Assets/Fungus/Camera/Commands/MoveToView.cs index 101be2eb..f0957778 100644 --- a/Assets/Fungus/Camera/Commands/MoveToView.cs +++ b/Assets/Fungus/Camera/Commands/MoveToView.cs @@ -4,9 +4,10 @@ using System.Collections; namespace Fungus.Script { - [CommandCategory("Camera")] - [CommandName("Move To View")] - [HelpText("Moves the camera to a location specified by a View object.")] + [CommandInfo("Camera", + "Move To View", + "Moves the camera to a location specified by a View object.", + 1,1,1)] public class MoveToView : FungusCommand { public float duration; diff --git a/Assets/Fungus/Dialog/Commands/AddOption.cs b/Assets/Fungus/Dialog/Commands/AddOption.cs index 1feeaf5e..5e26e745 100644 --- a/Assets/Fungus/Dialog/Commands/AddOption.cs +++ b/Assets/Fungus/Dialog/Commands/AddOption.cs @@ -5,9 +5,10 @@ using System.Collections.Generic; namespace Fungus.Script { - [CommandName("Add Option")] - [CommandCategory("Dialog")] - [HelpText("Adds an option for the player to select, displayed by the next Say command.")] + [CommandInfo("Dialog", + "Add Option", + "Adds an option for the player to select, displayed by the next Say command.", + 1,1,1)] public class AddOption : FungusCommand { public string optionText; diff --git a/Assets/Fungus/Dialog/Commands/Choose.cs b/Assets/Fungus/Dialog/Commands/Choose.cs index 22942f96..5dd50029 100644 --- a/Assets/Fungus/Dialog/Commands/Choose.cs +++ b/Assets/Fungus/Dialog/Commands/Choose.cs @@ -5,8 +5,10 @@ using System.Collections.Generic; namespace Fungus.Script { - [CommandCategory("Dialog")] - [HelpText("Presents a list of options for the player to choose from, with an optional timeout. Add options using preceding AddOption commands.")] + [CommandInfo("Dialog", + "Choose", + "Presents a list of options for the player to choose from, with an optional timeout. Add options using preceding AddOption commands.", + 1,1,1)] public class Choose : FungusCommand { public ChooseDialog dialog; diff --git a/Assets/Fungus/Dialog/Commands/Say.cs b/Assets/Fungus/Dialog/Commands/Say.cs index 8f91a5d3..e3ff846b 100644 --- a/Assets/Fungus/Dialog/Commands/Say.cs +++ b/Assets/Fungus/Dialog/Commands/Say.cs @@ -5,8 +5,10 @@ using System.Collections.Generic; namespace Fungus.Script { - [CommandCategory("Dialog")] - [HelpText("Writes a line of story text to the dialog. A list of options can be specified for the player to choose from. Use a non-zero timeout to give the player a limited time to choose.")] + [CommandInfo("Dialog", + "Say", + "Writes a line of story text to the dialog. A list of options can be specified for the player to choose from. Use a non-zero timeout to give the player a limited time to choose.", + 1,1,1)] public class Say : FungusCommand { public SayDialog dialog; diff --git a/Assets/Fungus/FungusScript/Commands/Call.cs b/Assets/Fungus/FungusScript/Commands/Call.cs index 87db0705..e62a83af 100644 --- a/Assets/Fungus/FungusScript/Commands/Call.cs +++ b/Assets/Fungus/FungusScript/Commands/Call.cs @@ -4,8 +4,10 @@ using System.Collections.Generic; namespace Fungus.Script { - [CommandCategory("Scripting")] - [HelpText("Execute another sequence.")] + [CommandInfo("Scripting", + "Call", + "Execute another sequence.", + 1,1,1)] public class Call : FungusCommand { public Sequence targetSequence; diff --git a/Assets/Fungus/FungusScript/Commands/If.cs b/Assets/Fungus/FungusScript/Commands/If.cs index ca48c70b..8d07b23e 100644 --- a/Assets/Fungus/FungusScript/Commands/If.cs +++ b/Assets/Fungus/FungusScript/Commands/If.cs @@ -14,8 +14,10 @@ namespace Fungus.Script GreaterThanOrEquals // >= } - [CommandCategory("Scripting")] - [HelpText("Execute another sequence IF a condition is true. Sequences can be specified for both true (THEN) and false (ELSE) conditions.")] + [CommandInfo("Scripting", + "If", + "Execute another sequence IF a condition is true. Sequences can be specified for both true (THEN) and false (ELSE) conditions.", + 1,1,1)] public class If : FungusCommand { public FungusVariable variable; diff --git a/Assets/Fungus/FungusScript/Commands/LoadGlobals.cs b/Assets/Fungus/FungusScript/Commands/LoadGlobals.cs index 2b27d6d5..d12af87d 100644 --- a/Assets/Fungus/FungusScript/Commands/LoadGlobals.cs +++ b/Assets/Fungus/FungusScript/Commands/LoadGlobals.cs @@ -4,9 +4,10 @@ using System.Collections; namespace Fungus.Script { - [CommandCategory("Scripting")] - [CommandName("Load Globals")] - [HelpText("Loads a set of global variables previously saved using the SaveGlobals command.")] + [CommandInfo("Scripting", + "Load Globals", + "Loads a set of global variables previously saved using the SaveGlobals command.", + 1,1,1)] public class LoadGlobals : FungusCommand { public string saveName = ""; diff --git a/Assets/Fungus/FungusScript/Commands/LoadScene.cs b/Assets/Fungus/FungusScript/Commands/LoadScene.cs index 0a1f6099..9cd5c758 100644 --- a/Assets/Fungus/FungusScript/Commands/LoadScene.cs +++ b/Assets/Fungus/FungusScript/Commands/LoadScene.cs @@ -4,12 +4,13 @@ using System.Collections; namespace Fungus.Script { - [CommandCategory("Scripting")] - [CommandName("Load Scene")] - [HelpText("Loads a new scene and displays an optional loading image. This is useful " + - "for splitting a large game across multiple scene files to reduce peak memory " + - "usage. All previously loaded assets (including textures and audio) will be released." + - "The scene to be loaded must be added to the scene list in Build Settings.")] + [CommandInfo("Scripting", + "Load Scene", + "Loads a new scene and displays an optional loading image. This is useful " + + "for splitting a large game across multiple scene files to reduce peak memory " + + "usage. All previously loaded assets (including textures and audio) will be released." + + "The scene to be loaded must be added to the scene list in Build Settings.", + 1,1,1)] public class LoadScene : FungusCommand { public string sceneName = ""; diff --git a/Assets/Fungus/FungusScript/Commands/SaveGlobals.cs b/Assets/Fungus/FungusScript/Commands/SaveGlobals.cs index 4a9c5365..810e22b8 100644 --- a/Assets/Fungus/FungusScript/Commands/SaveGlobals.cs +++ b/Assets/Fungus/FungusScript/Commands/SaveGlobals.cs @@ -4,9 +4,10 @@ using System.Collections; namespace Fungus.Script { - [CommandCategory("Scripting")] - [CommandName("Save Globals")] - [HelpText("Saves all current global variables to be loaded again later using the LoadGlobals command. This provides a basic save game system.")] + [CommandInfo("Scripting", + "Save Globals", + "Saves all current global variables to be loaded again later using the LoadGlobals command. This provides a basic save game system.", + 1,1,1)] public class SaveGlobals : FungusCommand { public string saveName = ""; diff --git a/Assets/Fungus/FungusScript/Commands/Set.cs b/Assets/Fungus/FungusScript/Commands/Set.cs index 10611e8a..657d37ed 100644 --- a/Assets/Fungus/FungusScript/Commands/Set.cs +++ b/Assets/Fungus/FungusScript/Commands/Set.cs @@ -3,8 +3,10 @@ using System.Collections; namespace Fungus.Script { - [CommandCategory("Scripting")] - [HelpText("Sets a variable to a new value using simple arithmetic operations. The value can be a constant or another variable.")] + [CommandInfo("Scripting", + "Set", + "Sets a variable to a new value using simple arithmetic operations. The value can be a constant or another variable.", + 1,1,1)] public class Set : FungusCommand { public enum SetOperator diff --git a/Assets/Fungus/FungusScript/Commands/Wait.cs b/Assets/Fungus/FungusScript/Commands/Wait.cs index dca69418..e96ac26c 100644 --- a/Assets/Fungus/FungusScript/Commands/Wait.cs +++ b/Assets/Fungus/FungusScript/Commands/Wait.cs @@ -4,8 +4,10 @@ using System.Collections; namespace Fungus.Script { - [CommandCategory("Scripting")] - [HelpText("Waits for period of time before executing the next command in the sequence.")] + [CommandInfo("Scripting", + "Wait", + "Waits for period of time before executing the next command in the sequence.", + 1,1,1)] public class Wait : FungusCommand { public float duration = 1; diff --git a/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs index f6d0dd5f..41fdf41f 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs @@ -21,6 +21,21 @@ namespace Fungus.Script } } + public static CommandInfoAttribute GetCommandInfo(System.Type commandType) + { + object[] attributes = commandType.GetCustomAttributes(typeof(CommandInfoAttribute), false); + foreach (object obj in attributes) + { + CommandInfoAttribute commandInfoAttr = obj as CommandInfoAttribute; + if (commandInfoAttr != null) + { + return commandInfoAttr; + } + } + + return null; + } + public virtual void DrawCommandRowGUI() { FungusCommand t = target as FungusCommand; @@ -57,7 +72,13 @@ namespace Fungus.Script GUI.backgroundColor = Color.yellow; } - string commandName = FungusScriptEditor.GetCommandName(t.GetType()); + CommandInfoAttribute commandInfoAttr = FungusCommandEditor.GetCommandInfo(t.GetType()); + if (commandInfoAttr == null) + { + return; + } + + string commandName = commandInfoAttr.CommandName; if (GUILayout.Button(commandName, EditorStyles.miniButton, GUILayout.MinWidth(80))) { fungusScript.selectedCommand = t; @@ -110,7 +131,15 @@ namespace Fungus.Script t.enabled = enabled; } - string commandName = FungusScriptEditor.GetCommandName(t.GetType()); + CommandInfoAttribute commandInfoAttr = FungusCommandEditor.GetCommandInfo(t.GetType()); + if (commandInfoAttr == null) + { + GUILayout.EndHorizontal(); + GUILayout.EndVertical(); + return; + } + + string commandName = commandInfoAttr.CommandName; GUILayout.Label(commandName + " Command", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); diff --git a/Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs b/Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs index 87541f06..f164fcfa 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs @@ -124,7 +124,13 @@ namespace Fungus.Script summaryRect.x += 85; summaryRect.width -= 85; - string commandName = FungusScriptEditor.GetCommandName(command.GetType()); + CommandInfoAttribute commandInfoAttr = FungusCommandEditor.GetCommandInfo(command.GetType()); + if (commandInfoAttr == null) + { + return; + } + + string commandName = commandInfoAttr.CommandName; GUIStyle commandStyle = new GUIStyle(GUI.skin.box); if (GUI.Button(buttonRect, commandName, commandStyle)) { diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs index a9d807da..a48abf9f 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs @@ -117,21 +117,6 @@ namespace Fungus.Script variable.key = fungusScript.GetUniqueVariableKey(""); fungusScript.variables.Add(variable); } - - public static string GetCommandName(System.Type commandType) - { - object[] attributes = commandType.GetCustomAttributes(typeof(CommandNameAttribute), false); - foreach (object obj in attributes) - { - CommandNameAttribute commandNameAttr = obj as CommandNameAttribute; - if (commandNameAttr != null) - { - return commandNameAttr.CommandName; - } - } - - return commandType.Name; - } } } \ No newline at end of file diff --git a/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs b/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs index 09f07a61..5c60641b 100644 --- a/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs @@ -66,7 +66,7 @@ namespace Fungus.Script object[] attributes = type.GetCustomAttributes(false); foreach (object obj in attributes) { - CommandCategoryAttribute categoryAttr = obj as CommandCategoryAttribute; + CommandInfoAttribute categoryAttr = obj as CommandInfoAttribute; if (categoryAttr != null) { if (!categories.Contains(categoryAttr.Category)) @@ -88,18 +88,16 @@ namespace Fungus.Script string categoryName = categories[selectedCategoryIndex]; foreach (System.Type type in subTypes) { - object[] attributes = type.GetCustomAttributes(false); - foreach (object obj in attributes) + CommandInfoAttribute commandInfoAttr = FungusCommandEditor.GetCommandInfo(type); + if (commandInfoAttr == null) { - CommandCategoryAttribute categoryAttr = obj as CommandCategoryAttribute; - if (categoryAttr != null) - { - if (categoryAttr.Category == categoryName) - { - commandNames.Add(FungusScriptEditor.GetCommandName(type)); - commandTypes.Add(type); - } - } + continue; + } + + if (categoryName == commandInfoAttr.Category) + { + commandNames.Add(commandInfoAttr.CommandName); + commandTypes.Add(type); } } @@ -152,17 +150,12 @@ namespace Fungus.Script EditorGUILayout.EndHorizontal(); - object[] helpAttributes = selectedType.GetCustomAttributes(typeof(HelpTextAttribute), false); - foreach (object obj in helpAttributes) + CommandInfoAttribute infoAttr = FungusCommandEditor.GetCommandInfo(selectedType); + if (infoAttr != null) { - HelpTextAttribute helpTextAttr = obj as HelpTextAttribute; - if (helpTextAttr != null) - { - GUIStyle labelStyle = new GUIStyle(EditorStyles.miniLabel); - labelStyle.wordWrap = true; - EditorGUILayout.HelpBox(helpTextAttr.HelpText, MessageType.Info); - break; - } + GUIStyle labelStyle = new GUIStyle(EditorStyles.miniLabel); + labelStyle.wordWrap = true; + EditorGUILayout.HelpBox(infoAttr.HelpText, MessageType.Info); } serializedObject.ApplyModifiedProperties(); diff --git a/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs b/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs index f8eb4b12..925c295e 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs @@ -8,34 +8,21 @@ using System.Collections.Generic; namespace Fungus.Script { - public class CommandNameAttribute : Attribute - { - public CommandNameAttribute(string commandName) - { - this.CommandName = commandName; - } - - public string CommandName { get; set; } - } - public class HelpTextAttribute : Attribute + public class CommandInfoAttribute : Attribute { - public HelpTextAttribute(string helpText) + public CommandInfoAttribute(string category, string commandName, string helpText, float red, float green, float blue) { + this.Category = category; + this.CommandName = commandName; this.HelpText = helpText; + this.ButtonColor = new Color(red, green, blue); } - - public string HelpText { get; set; } - } - public class CommandCategoryAttribute : Attribute - { - public CommandCategoryAttribute(string categoryText) - { - this.Category = categoryText; - } - public string Category { get; set; } + public string CommandName { get; set; } + public string HelpText { get; set; } + public Color ButtonColor { get; set; } } [RequireComponent(typeof(Sequence))] diff --git a/Assets/Fungus/Sprite/Commands/FadeSprite.cs b/Assets/Fungus/Sprite/Commands/FadeSprite.cs index e9c2f8de..5a0bca68 100644 --- a/Assets/Fungus/Sprite/Commands/FadeSprite.cs +++ b/Assets/Fungus/Sprite/Commands/FadeSprite.cs @@ -4,9 +4,10 @@ using System.Collections; namespace Fungus.Script { - [CommandCategory("Sprite")] - [CommandName("Fade Sprite")] - [HelpText("Fades a sprite to a target color over a period of time.")] + [CommandInfo("Sprite", + "Fade Sprite", + "Fades a sprite to a target color over a period of time.", + 1,1,1)] public class FadeSprite : FungusCommand { public SpriteRenderer spriteRenderer;