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
{
[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;

7
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;

7
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)]

7
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()

7
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;

7
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;

7
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;

6
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;

6
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;

6
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;

6
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;

7
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 = "";

13
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 = "";

7
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 = "";

6
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

6
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;

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()
{
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();

8
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))
{

15
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;
}
}
}

37
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();

29
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))]

7
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;

Loading…
Cancel
Save