diff --git a/Assets/Fungus/Audio/Commands/PlayMusic.cs b/Assets/Fungus/Audio/Commands/PlayMusic.cs index e22dfee0..dee22250 100644 --- a/Assets/Fungus/Audio/Commands/PlayMusic.cs +++ b/Assets/Fungus/Audio/Commands/PlayMusic.cs @@ -3,6 +3,7 @@ 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.")] public class PlayMusic : FungusCommand diff --git a/Assets/Fungus/Audio/Commands/PlaySound.cs b/Assets/Fungus/Audio/Commands/PlaySound.cs index 4c0d9400..8ac91ac5 100644 --- a/Assets/Fungus/Audio/Commands/PlaySound.cs +++ b/Assets/Fungus/Audio/Commands/PlaySound.cs @@ -3,6 +3,7 @@ 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.")] public class PlaySound : FungusCommand diff --git a/Assets/Fungus/Audio/Commands/SetMusicVolume.cs b/Assets/Fungus/Audio/Commands/SetMusicVolume.cs index b02e85d9..5d0e31c9 100644 --- a/Assets/Fungus/Audio/Commands/SetMusicVolume.cs +++ b/Assets/Fungus/Audio/Commands/SetMusicVolume.cs @@ -3,6 +3,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Audio")] [CommandName("Set Music Volume")] [HelpText("Sets the game music volume level.")] public class SetMusicVolume : FungusCommand diff --git a/Assets/Fungus/Audio/Commands/StopMusic.cs b/Assets/Fungus/Audio/Commands/StopMusic.cs index 062c25cf..ceb92e20 100644 --- a/Assets/Fungus/Audio/Commands/StopMusic.cs +++ b/Assets/Fungus/Audio/Commands/StopMusic.cs @@ -3,6 +3,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Audio")] [CommandName("Stop Music")] [HelpText("Stops the currently playing game music.")] public class StopMusic : FungusCommand diff --git a/Assets/Fungus/Camera/Commands/FadeToView.cs b/Assets/Fungus/Camera/Commands/FadeToView.cs index 5e62899a..a6ee8b3f 100644 --- a/Assets/Fungus/Camera/Commands/FadeToView.cs +++ b/Assets/Fungus/Camera/Commands/FadeToView.cs @@ -4,6 +4,7 @@ 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.")] public class FadeToView : FungusCommand diff --git a/Assets/Fungus/Camera/Commands/MoveToView.cs b/Assets/Fungus/Camera/Commands/MoveToView.cs index 97dbb3d1..101be2eb 100644 --- a/Assets/Fungus/Camera/Commands/MoveToView.cs +++ b/Assets/Fungus/Camera/Commands/MoveToView.cs @@ -4,6 +4,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Camera")] [CommandName("Move To View")] [HelpText("Moves the camera to a location specified by a View object.")] public class MoveToView : FungusCommand diff --git a/Assets/Fungus/Dialog/Commands/AddOption.cs b/Assets/Fungus/Dialog/Commands/AddOption.cs index 8e590487..ec80688f 100644 --- a/Assets/Fungus/Dialog/Commands/AddOption.cs +++ b/Assets/Fungus/Dialog/Commands/AddOption.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; namespace Fungus.Script { + [CommandCategory("Dialog")] [CommandName("Add Option")] [HelpText("Adds an option button to be displayed by the next Say command. The target sequence is run when the player selects the option. A condition can be specified for when the option should be shown.")] public class AddOption : FungusCommand diff --git a/Assets/Fungus/Dialog/Commands/Say.cs b/Assets/Fungus/Dialog/Commands/Say.cs index 067278f4..da1fe1bc 100644 --- a/Assets/Fungus/Dialog/Commands/Say.cs +++ b/Assets/Fungus/Dialog/Commands/Say.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; namespace Fungus.Script { + [CommandCategory("Dialog")] [HelpText("Writes a line of story text to the dialog. A condition can be specified for when the story text should be shown.")] public class Say : FungusCommand { diff --git a/Assets/Fungus/FungusScript/Commands/Call.cs b/Assets/Fungus/FungusScript/Commands/Call.cs index 12fae471..87db0705 100644 --- a/Assets/Fungus/FungusScript/Commands/Call.cs +++ b/Assets/Fungus/FungusScript/Commands/Call.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; namespace Fungus.Script { + [CommandCategory("Scripting")] [HelpText("Execute another sequence.")] public class Call : FungusCommand { diff --git a/Assets/Fungus/FungusScript/Commands/If.cs b/Assets/Fungus/FungusScript/Commands/If.cs index 5492eda4..ca48c70b 100644 --- a/Assets/Fungus/FungusScript/Commands/If.cs +++ b/Assets/Fungus/FungusScript/Commands/If.cs @@ -14,6 +14,7 @@ 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.")] public class If : FungusCommand { diff --git a/Assets/Fungus/FungusScript/Commands/LoadGlobals.cs b/Assets/Fungus/FungusScript/Commands/LoadGlobals.cs index a3bb2547..2b27d6d5 100644 --- a/Assets/Fungus/FungusScript/Commands/LoadGlobals.cs +++ b/Assets/Fungus/FungusScript/Commands/LoadGlobals.cs @@ -4,6 +4,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Scripting")] [CommandName("Load Globals")] [HelpText("Loads a set of global variables previously saved using the SaveGlobals command.")] public class LoadGlobals : FungusCommand diff --git a/Assets/Fungus/FungusScript/Commands/LoadScene.cs b/Assets/Fungus/FungusScript/Commands/LoadScene.cs index 78422551..0a1f6099 100644 --- a/Assets/Fungus/FungusScript/Commands/LoadScene.cs +++ b/Assets/Fungus/FungusScript/Commands/LoadScene.cs @@ -4,6 +4,7 @@ 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 " + diff --git a/Assets/Fungus/FungusScript/Commands/SaveGlobals.cs b/Assets/Fungus/FungusScript/Commands/SaveGlobals.cs index 7a8c544f..4a9c5365 100644 --- a/Assets/Fungus/FungusScript/Commands/SaveGlobals.cs +++ b/Assets/Fungus/FungusScript/Commands/SaveGlobals.cs @@ -4,6 +4,7 @@ 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.")] public class SaveGlobals : FungusCommand diff --git a/Assets/Fungus/FungusScript/Commands/Set.cs b/Assets/Fungus/FungusScript/Commands/Set.cs index 652718a3..10611e8a 100644 --- a/Assets/Fungus/FungusScript/Commands/Set.cs +++ b/Assets/Fungus/FungusScript/Commands/Set.cs @@ -3,6 +3,7 @@ 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.")] public class Set : FungusCommand { diff --git a/Assets/Fungus/FungusScript/Commands/Wait.cs b/Assets/Fungus/FungusScript/Commands/Wait.cs index abb29b8e..dca69418 100644 --- a/Assets/Fungus/FungusScript/Commands/Wait.cs +++ b/Assets/Fungus/FungusScript/Commands/Wait.cs @@ -4,6 +4,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Scripting")] [HelpText("Waits for period of time before executing the next command in the sequence.")] public class Wait : FungusCommand { diff --git a/Assets/Fungus/FungusScript/Editor/CallEditor.cs b/Assets/Fungus/FungusScript/Editor/CallEditor.cs index 9c9ee618..99ed0495 100644 --- a/Assets/Fungus/FungusScript/Editor/CallEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/CallEditor.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; namespace Fungus.Script { - [CustomEditor (typeof(Call))] public class CallEditor : FungusCommandEditor { diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs index 752c983c..6e0a0610 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs @@ -95,9 +95,7 @@ namespace Fungus.Script sequence.description = desc; } - GUI.backgroundColor = Color.yellow; GUILayout.Box("Commands", GUILayout.ExpandWidth(true)); - GUI.backgroundColor = Color.white; FungusCommand[] commands = sequence.GetComponents(); int index = 1; @@ -113,52 +111,90 @@ namespace Fungus.Script } EditorGUILayout.Separator(); - - GUI.backgroundColor = Color.yellow; + GUILayout.Box("New Command", GUILayout.ExpandWidth(true)); - GUI.backgroundColor = Color.white; + List categories = new List(); + // Build list of categories - List commandTypes = EditorExtensions.FindDerivedTypes(typeof(FungusCommand)).ToList(); - if (commandTypes.Count == 0) + List subTypes = EditorExtensions.FindDerivedTypes(typeof(FungusCommand)).ToList(); + foreach(System.Type type in subTypes) { - return; + object[] attributes = type.GetCustomAttributes(false); + foreach (object obj in attributes) + { + CommandCategoryAttribute categoryAttr = obj as CommandCategoryAttribute; + if (categoryAttr != null) + { + if (!categories.Contains(categoryAttr.Category)) + { + categories.Add(categoryAttr.Category); + } + } + } } - List commandNames = new List(); - foreach(System.Type type in commandTypes) - { - commandNames.Add(GetCommandName(type)); - } + categories.Sort(); EditorGUI.BeginChangeCheck(); - int selectedCommandIndex = EditorGUILayout.Popup("Command", fungusScript.selectedCommandIndex, commandNames.ToArray()); + EditorGUILayout.BeginHorizontal(); + int selectedCategoryIndex = EditorGUILayout.Popup(fungusScript.selectedCategoryIndex, categories.ToArray()); + + List commandNames = new List(); + List commandTypes = new List(); + + string categoryName = categories[selectedCategoryIndex]; + foreach (System.Type type in subTypes) + { + object[] attributes = type.GetCustomAttributes(false); + foreach (object obj in attributes) + { + CommandCategoryAttribute categoryAttr = obj as CommandCategoryAttribute; + if (categoryAttr != null) + { + if (categoryAttr.Category == categoryName) + { + commandNames.Add(type.Name); + commandTypes.Add(type); + } + } + } + } + + int selectedCommandIndex = EditorGUILayout.Popup(fungusScript.selectedCommandIndex, commandNames.ToArray()); + + if (selectedCategoryIndex != fungusScript.selectedCategoryIndex) + { + // Default to first item in list if category has changed + selectedCommandIndex = 0; + } + if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(fungusScript, "Select Command"); + fungusScript.selectedCategoryIndex = selectedCategoryIndex; fungusScript.selectedCommandIndex = selectedCommandIndex; } System.Type selectedType = commandTypes[selectedCommandIndex]; - if (selectedType == null) + if (fungusScript.selectedSequence == null || + selectedType == null) { + EditorGUILayout.EndHorizontal(); return; } - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - if (GUILayout.Button(new GUIContent("Add Command", "Add the selected command to the sequence"))) + if (GUILayout.Button(new GUIContent("Add", "Add the selected command to the sequence"), EditorStyles.miniButton)) { - Undo.AddComponent(sequence.gameObject, selectedType); + Undo.AddComponent(fungusScript.selectedSequence.gameObject, selectedType); } - GUILayout.EndHorizontal(); + + EditorGUILayout.EndHorizontal(); - EditorGUILayout.Separator(); - - object[] attributes = selectedType.GetCustomAttributes(typeof(HelpTextAttribute), false); - foreach (object obj in attributes) + object[] helpAttributes = selectedType.GetCustomAttributes(typeof(HelpTextAttribute), false); + foreach (object obj in helpAttributes) { HelpTextAttribute helpTextAttr = obj as HelpTextAttribute; if (helpTextAttr != null) @@ -169,6 +205,8 @@ namespace Fungus.Script break; } } + + EditorGUILayout.Separator(); } public void DrawVariablesGUI() diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs index 59e64430..fe3a6dac 100755 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs @@ -190,11 +190,8 @@ namespace Fungus.Script EditorGUILayout.BeginVertical(); - EditorGUILayout.Separator(); - GUI.backgroundColor = Color.yellow; GUILayout.Box("Sequence", GUILayout.ExpandWidth(true)); - GUI.backgroundColor = Color.white; - + GUILayout.BeginHorizontal(); if (fungusScript.selectedSequence == null) diff --git a/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs b/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs index c3e73774..eef19df5 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs @@ -28,6 +28,16 @@ namespace Fungus.Script public string HelpText { get; set; } } + public class CommandCategoryAttribute : Attribute + { + public CommandCategoryAttribute(string categoryText) + { + this.Category = categoryText; + } + + public string Category { get; set; } + } + [RequireComponent(typeof(Sequence))] public class FungusCommand : MonoBehaviour { diff --git a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs index 383243e7..e01d7861 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs @@ -15,6 +15,9 @@ namespace Fungus.Script [System.NonSerialized] public FungusCommand copyCommand; + [HideInInspector] + public int selectedCategoryIndex; + [HideInInspector] public int selectedCommandIndex; diff --git a/Assets/Fungus/Sprite/Commands/FadeSprite.cs b/Assets/Fungus/Sprite/Commands/FadeSprite.cs index 1c898356..e9c2f8de 100644 --- a/Assets/Fungus/Sprite/Commands/FadeSprite.cs +++ b/Assets/Fungus/Sprite/Commands/FadeSprite.cs @@ -4,6 +4,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Sprite")] [CommandName("Fade Sprite")] [HelpText("Fades a sprite to a target color over a period of time.")] public class FadeSprite : FungusCommand diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index a2879f9e..54f03d44 100644 Binary files a/Assets/Shuttle/ShuttleGame.unity and b/Assets/Shuttle/ShuttleGame.unity differ