Browse Source

Unified CommandInfo attribute

master
chrisgregan 10 years ago
parent
commit
74db43f463
  1. 7
      Assets/Fungus/Audio/Commands/PlayMusic.cs
  2. 7
      Assets/Fungus/Audio/Commands/PlaySound.cs
  3. 7
      Assets/Fungus/Audio/Commands/SetMusicVolume.cs
  4. 7
      Assets/Fungus/Audio/Commands/StopMusic.cs
  5. 7
      Assets/Fungus/Camera/Commands/FadeToView.cs
  6. 7
      Assets/Fungus/Camera/Commands/MoveToView.cs
  7. 7
      Assets/Fungus/Dialog/Commands/AddOption.cs
  8. 6
      Assets/Fungus/Dialog/Commands/Choose.cs
  9. 6
      Assets/Fungus/Dialog/Commands/Say.cs
  10. 6
      Assets/Fungus/FungusScript/Commands/Call.cs
  11. 6
      Assets/Fungus/FungusScript/Commands/If.cs
  12. 7
      Assets/Fungus/FungusScript/Commands/LoadGlobals.cs
  13. 13
      Assets/Fungus/FungusScript/Commands/LoadScene.cs
  14. 7
      Assets/Fungus/FungusScript/Commands/SaveGlobals.cs
  15. 6
      Assets/Fungus/FungusScript/Commands/Set.cs
  16. 6
      Assets/Fungus/FungusScript/Commands/Wait.cs
  17. 33
      Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs
  18. 8
      Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs
  19. 15
      Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs
  20. 37
      Assets/Fungus/FungusScript/Editor/SequenceEditor.cs
  21. 29
      Assets/Fungus/FungusScript/Scripts/FungusCommand.cs
  22. 7
      Assets/Fungus/Sprite/Commands/FadeSprite.cs

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

@ -3,9 +3,10 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Audio")] [CommandInfo("Audio",
[CommandName("Play Music")] "Play Music",
[HelpText("Plays game music. If any game music is already playing, it is stopped. Music continues playing across scene loads.")] "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 class PlayMusic : FungusCommand
{ {
public AudioClip musicClip; public AudioClip musicClip;

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

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

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

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

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

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

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

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

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

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

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

@ -5,9 +5,10 @@ using System.Collections.Generic;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandName("Add Option")] [CommandInfo("Dialog",
[CommandCategory("Dialog")] "Add Option",
[HelpText("Adds an option for the player to select, displayed by the next Say command.")] "Adds an option for the player to select, displayed by the next Say command.",
1,1,1)]
public class AddOption : FungusCommand public class AddOption : FungusCommand
{ {
public string optionText; public string optionText;

6
Assets/Fungus/Dialog/Commands/Choose.cs

@ -5,8 +5,10 @@ using System.Collections.Generic;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Dialog")] [CommandInfo("Dialog",
[HelpText("Presents a list of options for the player to choose from, with an optional timeout. Add options using preceding AddOption commands.")] "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 class Choose : FungusCommand
{ {
public ChooseDialog dialog; public ChooseDialog dialog;

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

@ -5,8 +5,10 @@ using System.Collections.Generic;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Dialog")] [CommandInfo("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.")] "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 class Say : FungusCommand
{ {
public SayDialog dialog; public SayDialog dialog;

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

@ -4,8 +4,10 @@ using System.Collections.Generic;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Scripting")] [CommandInfo("Scripting",
[HelpText("Execute another sequence.")] "Call",
"Execute another sequence.",
1,1,1)]
public class Call : FungusCommand public class Call : FungusCommand
{ {
public Sequence targetSequence; public Sequence targetSequence;

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

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

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

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

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

@ -4,12 +4,13 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Scripting")] [CommandInfo("Scripting",
[CommandName("Load Scene")] "Load Scene",
[HelpText("Loads a new scene and displays an optional loading image. This is useful " + "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 " +
"usage. All previously loaded assets (including textures and audio) will be released." + "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.")] "The scene to be loaded must be added to the scene list in Build Settings.",
1,1,1)]
public class LoadScene : FungusCommand public class LoadScene : FungusCommand
{ {
public string sceneName = ""; public string sceneName = "";

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

@ -4,9 +4,10 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Scripting")] [CommandInfo("Scripting",
[CommandName("Save Globals")] "Save Globals",
[HelpText("Saves all current global variables to be loaded again later using the LoadGlobals command. This provides a basic save game system.")] "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 class SaveGlobals : FungusCommand
{ {
public string saveName = ""; public string saveName = "";

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

@ -3,8 +3,10 @@ using System.Collections;
namespace Fungus.Script namespace Fungus.Script
{ {
[CommandCategory("Scripting")] [CommandInfo("Scripting",
[HelpText("Sets a variable to a new value using simple arithmetic operations. The value can be a constant or another variable.")] "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 class Set : FungusCommand
{ {
public enum SetOperator public enum SetOperator

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

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

33
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() public virtual void DrawCommandRowGUI()
{ {
FungusCommand t = target as FungusCommand; FungusCommand t = target as FungusCommand;
@ -57,7 +72,13 @@ namespace Fungus.Script
GUI.backgroundColor = Color.yellow; 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))) if (GUILayout.Button(commandName, EditorStyles.miniButton, GUILayout.MinWidth(80)))
{ {
fungusScript.selectedCommand = t; fungusScript.selectedCommand = t;
@ -110,7 +131,15 @@ namespace Fungus.Script
t.enabled = enabled; 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.Label(commandName + " Command", EditorStyles.boldLabel);
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();

8
Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs

@ -124,7 +124,13 @@ namespace Fungus.Script
summaryRect.x += 85; summaryRect.x += 85;
summaryRect.width -= 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); GUIStyle commandStyle = new GUIStyle(GUI.skin.box);
if (GUI.Button(buttonRect, commandName, commandStyle)) if (GUI.Button(buttonRect, commandName, commandStyle))
{ {

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

@ -117,21 +117,6 @@ namespace Fungus.Script
variable.key = fungusScript.GetUniqueVariableKey(""); variable.key = fungusScript.GetUniqueVariableKey("");
fungusScript.variables.Add(variable); 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;
}
} }
} }

37
Assets/Fungus/FungusScript/Editor/SequenceEditor.cs

@ -66,7 +66,7 @@ namespace Fungus.Script
object[] attributes = type.GetCustomAttributes(false); object[] attributes = type.GetCustomAttributes(false);
foreach (object obj in attributes) foreach (object obj in attributes)
{ {
CommandCategoryAttribute categoryAttr = obj as CommandCategoryAttribute; CommandInfoAttribute categoryAttr = obj as CommandInfoAttribute;
if (categoryAttr != null) if (categoryAttr != null)
{ {
if (!categories.Contains(categoryAttr.Category)) if (!categories.Contains(categoryAttr.Category))
@ -88,18 +88,16 @@ namespace Fungus.Script
string categoryName = categories[selectedCategoryIndex]; string categoryName = categories[selectedCategoryIndex];
foreach (System.Type type in subTypes) foreach (System.Type type in subTypes)
{ {
object[] attributes = type.GetCustomAttributes(false); CommandInfoAttribute commandInfoAttr = FungusCommandEditor.GetCommandInfo(type);
foreach (object obj in attributes) if (commandInfoAttr == null)
{ {
CommandCategoryAttribute categoryAttr = obj as CommandCategoryAttribute; continue;
if (categoryAttr != null) }
{
if (categoryAttr.Category == categoryName) if (categoryName == commandInfoAttr.Category)
{ {
commandNames.Add(FungusScriptEditor.GetCommandName(type)); commandNames.Add(commandInfoAttr.CommandName);
commandTypes.Add(type); commandTypes.Add(type);
}
}
} }
} }
@ -152,17 +150,12 @@ namespace Fungus.Script
EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal();
object[] helpAttributes = selectedType.GetCustomAttributes(typeof(HelpTextAttribute), false); CommandInfoAttribute infoAttr = FungusCommandEditor.GetCommandInfo(selectedType);
foreach (object obj in helpAttributes) if (infoAttr != null)
{ {
HelpTextAttribute helpTextAttr = obj as HelpTextAttribute; GUIStyle labelStyle = new GUIStyle(EditorStyles.miniLabel);
if (helpTextAttr != null) labelStyle.wordWrap = true;
{ EditorGUILayout.HelpBox(infoAttr.HelpText, MessageType.Info);
GUIStyle labelStyle = new GUIStyle(EditorStyles.miniLabel);
labelStyle.wordWrap = true;
EditorGUILayout.HelpBox(helpTextAttr.HelpText, MessageType.Info);
break;
}
} }
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();

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

@ -8,34 +8,21 @@ using System.Collections.Generic;
namespace Fungus.Script namespace Fungus.Script
{ {
public class CommandNameAttribute : Attribute
{
public CommandNameAttribute(string commandName)
{
this.CommandName = commandName;
}
public string CommandName { get; set; } public class CommandInfoAttribute : Attribute
}
public class HelpTextAttribute : 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.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 Category { get; set; }
public string CommandName { get; set; }
public string HelpText { get; set; }
public Color ButtonColor { get; set; }
} }
[RequireComponent(typeof(Sequence))] [RequireComponent(typeof(Sequence))]

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

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

Loading…
Cancel
Save