Browse Source

Added command categories

master
chrisgregan 10 years ago
parent
commit
585efc2526
  1. 1
      Assets/Fungus/Audio/Commands/PlayMusic.cs
  2. 1
      Assets/Fungus/Audio/Commands/PlaySound.cs
  3. 1
      Assets/Fungus/Audio/Commands/SetMusicVolume.cs
  4. 1
      Assets/Fungus/Audio/Commands/StopMusic.cs
  5. 1
      Assets/Fungus/Camera/Commands/FadeToView.cs
  6. 1
      Assets/Fungus/Camera/Commands/MoveToView.cs
  7. 1
      Assets/Fungus/Dialog/Commands/AddOption.cs
  8. 1
      Assets/Fungus/Dialog/Commands/Say.cs
  9. 1
      Assets/Fungus/FungusScript/Commands/Call.cs
  10. 1
      Assets/Fungus/FungusScript/Commands/If.cs
  11. 1
      Assets/Fungus/FungusScript/Commands/LoadGlobals.cs
  12. 1
      Assets/Fungus/FungusScript/Commands/LoadScene.cs
  13. 1
      Assets/Fungus/FungusScript/Commands/SaveGlobals.cs
  14. 1
      Assets/Fungus/FungusScript/Commands/Set.cs
  15. 1
      Assets/Fungus/FungusScript/Commands/Wait.cs
  16. 1
      Assets/Fungus/FungusScript/Editor/CallEditor.cs
  17. 86
      Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs
  18. 5
      Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs
  19. 10
      Assets/Fungus/FungusScript/Scripts/FungusCommand.cs
  20. 3
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs
  21. 1
      Assets/Fungus/Sprite/Commands/FadeSprite.cs
  22. BIN
      Assets/Shuttle/ShuttleGame.unity

1
Assets/Fungus/Audio/Commands/PlayMusic.cs

@ -3,6 +3,7 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Audio")]
[CommandName("Play Music")] [CommandName("Play Music")]
[HelpText("Plays game music. If any game music is already playing, it is stopped. Music continues playing across scene loads.")] [HelpText("Plays game music. If any game music is already playing, it is stopped. Music continues playing across scene loads.")]
public class PlayMusic : FungusCommand public class PlayMusic : FungusCommand

1
Assets/Fungus/Audio/Commands/PlaySound.cs

@ -3,6 +3,7 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Audio")]
[CommandName("Play Sound")] [CommandName("Play Sound")]
[HelpText("Plays a sound effect. Multiple sound effects can play at the same time.")] [HelpText("Plays a sound effect. Multiple sound effects can play at the same time.")]
public class PlaySound : FungusCommand public class PlaySound : FungusCommand

1
Assets/Fungus/Audio/Commands/SetMusicVolume.cs

@ -3,6 +3,7 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Audio")]
[CommandName("Set Music Volume")] [CommandName("Set Music Volume")]
[HelpText("Sets the game music volume level.")] [HelpText("Sets the game music volume level.")]
public class SetMusicVolume : FungusCommand public class SetMusicVolume : FungusCommand

1
Assets/Fungus/Audio/Commands/StopMusic.cs

@ -3,6 +3,7 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Audio")]
[CommandName("Stop Music")] [CommandName("Stop Music")]
[HelpText("Stops the currently playing game music.")] [HelpText("Stops the currently playing game music.")]
public class StopMusic : FungusCommand public class StopMusic : FungusCommand

1
Assets/Fungus/Camera/Commands/FadeToView.cs

@ -4,6 +4,7 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Camera")]
[CommandName("Fade To View")] [CommandName("Fade To View")]
[HelpText("Fades the camera out and in again at a location specified by a View object.")] [HelpText("Fades the camera out and in again at a location specified by a View object.")]
public class FadeToView : FungusCommand public class FadeToView : FungusCommand

1
Assets/Fungus/Camera/Commands/MoveToView.cs

@ -4,6 +4,7 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Camera")]
[CommandName("Move To View")] [CommandName("Move To View")]
[HelpText("Moves the camera to a location specified by a View object.")] [HelpText("Moves the camera to a location specified by a View object.")]
public class MoveToView : FungusCommand public class MoveToView : FungusCommand

1
Assets/Fungus/Dialog/Commands/AddOption.cs

@ -4,6 +4,7 @@ using System.Collections.Generic;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Dialog")]
[CommandName("Add Option")] [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.")] [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 public class AddOption : FungusCommand

1
Assets/Fungus/Dialog/Commands/Say.cs

@ -5,6 +5,7 @@ using System.Collections.Generic;
namespace Fungus.Script 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.")] [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 public class Say : FungusCommand
{ {

1
Assets/Fungus/FungusScript/Commands/Call.cs

@ -4,6 +4,7 @@ using System.Collections.Generic;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Scripting")]
[HelpText("Execute another sequence.")] [HelpText("Execute another sequence.")]
public class Call : FungusCommand public class Call : FungusCommand
{ {

1
Assets/Fungus/FungusScript/Commands/If.cs

@ -14,6 +14,7 @@ namespace Fungus.Script
GreaterThanOrEquals // >= GreaterThanOrEquals // >=
} }
[CommandCategory("Scripting")]
[HelpText("Execute another sequence IF a condition is true. Sequences can be specified for both true (THEN) and false (ELSE) conditions.")] [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 public class If : FungusCommand
{ {

1
Assets/Fungus/FungusScript/Commands/LoadGlobals.cs

@ -4,6 +4,7 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Scripting")]
[CommandName("Load Globals")] [CommandName("Load Globals")]
[HelpText("Loads a set of global variables previously saved using the SaveGlobals command.")] [HelpText("Loads a set of global variables previously saved using the SaveGlobals command.")]
public class LoadGlobals : FungusCommand public class LoadGlobals : FungusCommand

1
Assets/Fungus/FungusScript/Commands/LoadScene.cs

@ -4,6 +4,7 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Scripting")]
[CommandName("Load Scene")] [CommandName("Load Scene")]
[HelpText("Loads a new scene and displays an optional loading image. This is useful " + [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 " + "for splitting a large game across multiple scene files to reduce peak memory " +

1
Assets/Fungus/FungusScript/Commands/SaveGlobals.cs

@ -4,6 +4,7 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Scripting")]
[CommandName("Save Globals")] [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.")] [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 public class SaveGlobals : FungusCommand

1
Assets/Fungus/FungusScript/Commands/Set.cs

@ -3,6 +3,7 @@ using System.Collections;
namespace Fungus.Script 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.")] [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 public class Set : FungusCommand
{ {

1
Assets/Fungus/FungusScript/Commands/Wait.cs

@ -4,6 +4,7 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Scripting")]
[HelpText("Waits for period of time before executing the next command in the sequence.")] [HelpText("Waits for period of time before executing the next command in the sequence.")]
public class Wait : FungusCommand public class Wait : FungusCommand
{ {

1
Assets/Fungus/FungusScript/Editor/CallEditor.cs

@ -5,7 +5,6 @@ using System.Collections.Generic;
namespace Fungus.Script namespace Fungus.Script
{ {
[CustomEditor (typeof(Call))] [CustomEditor (typeof(Call))]
public class CallEditor : FungusCommandEditor public class CallEditor : FungusCommandEditor
{ {

86
Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs

@ -95,9 +95,7 @@ namespace Fungus.Script
sequence.description = desc; sequence.description = desc;
} }
GUI.backgroundColor = Color.yellow;
GUILayout.Box("Commands", GUILayout.ExpandWidth(true)); GUILayout.Box("Commands", GUILayout.ExpandWidth(true));
GUI.backgroundColor = Color.white;
FungusCommand[] commands = sequence.GetComponents<FungusCommand>(); FungusCommand[] commands = sequence.GetComponents<FungusCommand>();
int index = 1; int index = 1;
@ -113,52 +111,90 @@ namespace Fungus.Script
} }
EditorGUILayout.Separator(); EditorGUILayout.Separator();
GUI.backgroundColor = Color.yellow;
GUILayout.Box("New Command", GUILayout.ExpandWidth(true)); GUILayout.Box("New Command", GUILayout.ExpandWidth(true));
GUI.backgroundColor = Color.white;
List<string> categories = new List<string>();
// Build list of categories // Build list of categories
List<System.Type> commandTypes = EditorExtensions.FindDerivedTypes(typeof(FungusCommand)).ToList(); List<System.Type> subTypes = EditorExtensions.FindDerivedTypes(typeof(FungusCommand)).ToList();
if (commandTypes.Count == 0) 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<string> commandNames = new List<string>(); categories.Sort();
foreach(System.Type type in commandTypes)
{
commandNames.Add(GetCommandName(type));
}
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
int selectedCommandIndex = EditorGUILayout.Popup("Command", fungusScript.selectedCommandIndex, commandNames.ToArray()); EditorGUILayout.BeginHorizontal();
int selectedCategoryIndex = EditorGUILayout.Popup(fungusScript.selectedCategoryIndex, categories.ToArray());
List<string> commandNames = new List<string>();
List<System.Type> commandTypes = new List<System.Type>();
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()) if (EditorGUI.EndChangeCheck())
{ {
Undo.RecordObject(fungusScript, "Select Command"); Undo.RecordObject(fungusScript, "Select Command");
fungusScript.selectedCategoryIndex = selectedCategoryIndex;
fungusScript.selectedCommandIndex = selectedCommandIndex; fungusScript.selectedCommandIndex = selectedCommandIndex;
} }
System.Type selectedType = commandTypes[selectedCommandIndex]; System.Type selectedType = commandTypes[selectedCommandIndex];
if (selectedType == null) if (fungusScript.selectedSequence == null ||
selectedType == null)
{ {
EditorGUILayout.EndHorizontal();
return; return;
} }
GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Add", "Add the selected command to the sequence"), EditorStyles.miniButton))
GUILayout.FlexibleSpace();
if (GUILayout.Button(new GUIContent("Add Command", "Add the selected command to the sequence")))
{ {
Undo.AddComponent(sequence.gameObject, selectedType); Undo.AddComponent(fungusScript.selectedSequence.gameObject, selectedType);
} }
GUILayout.EndHorizontal();
EditorGUILayout.EndHorizontal();
EditorGUILayout.Separator(); object[] helpAttributes = selectedType.GetCustomAttributes(typeof(HelpTextAttribute), false);
foreach (object obj in helpAttributes)
object[] attributes = selectedType.GetCustomAttributes(typeof(HelpTextAttribute), false);
foreach (object obj in attributes)
{ {
HelpTextAttribute helpTextAttr = obj as HelpTextAttribute; HelpTextAttribute helpTextAttr = obj as HelpTextAttribute;
if (helpTextAttr != null) if (helpTextAttr != null)
@ -169,6 +205,8 @@ namespace Fungus.Script
break; break;
} }
} }
EditorGUILayout.Separator();
} }
public void DrawVariablesGUI() public void DrawVariablesGUI()

5
Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs

@ -190,11 +190,8 @@ namespace Fungus.Script
EditorGUILayout.BeginVertical(); EditorGUILayout.BeginVertical();
EditorGUILayout.Separator();
GUI.backgroundColor = Color.yellow;
GUILayout.Box("Sequence", GUILayout.ExpandWidth(true)); GUILayout.Box("Sequence", GUILayout.ExpandWidth(true));
GUI.backgroundColor = Color.white;
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
if (fungusScript.selectedSequence == null) if (fungusScript.selectedSequence == null)

10
Assets/Fungus/FungusScript/Scripts/FungusCommand.cs

@ -28,6 +28,16 @@ namespace Fungus.Script
public string HelpText { get; set; } public string HelpText { get; set; }
} }
public class CommandCategoryAttribute : Attribute
{
public CommandCategoryAttribute(string categoryText)
{
this.Category = categoryText;
}
public string Category { get; set; }
}
[RequireComponent(typeof(Sequence))] [RequireComponent(typeof(Sequence))]
public class FungusCommand : MonoBehaviour public class FungusCommand : MonoBehaviour
{ {

3
Assets/Fungus/FungusScript/Scripts/FungusScript.cs

@ -15,6 +15,9 @@ namespace Fungus.Script
[System.NonSerialized] [System.NonSerialized]
public FungusCommand copyCommand; public FungusCommand copyCommand;
[HideInInspector]
public int selectedCategoryIndex;
[HideInInspector] [HideInInspector]
public int selectedCommandIndex; public int selectedCommandIndex;

1
Assets/Fungus/Sprite/Commands/FadeSprite.cs

@ -4,6 +4,7 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Sprite")]
[CommandName("Fade Sprite")] [CommandName("Fade Sprite")]
[HelpText("Fades a sprite to a target color over a period of time.")] [HelpText("Fades a sprite to a target color over a period of time.")]
public class FadeSprite : FungusCommand public class FadeSprite : FungusCommand

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save